Skip to content

Commit

Permalink
illumos fixes
Browse files Browse the repository at this point in the history
Created using spr 1.3.6-beta.1
  • Loading branch information
sunshowers committed Aug 10, 2024
1 parent 017ec26 commit 667ff17
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 29 deletions.
25 changes: 13 additions & 12 deletions sled-agent/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::instance_manager::{
Error as ManagerError, InstanceManagerServices, InstanceTicket,
};
use crate::metrics::MetricsRequestQueue;
use crate::nexus::NexusClient;
use crate::params::ZoneBundleMetadata;
use crate::params::{InstanceExternalIpBody, ZoneBundleCause};
use crate::params::{
Expand Down Expand Up @@ -348,7 +349,7 @@ struct InstanceRunner {
running_state: Option<RunningState>,

// Connection to Nexus
nexus_client: nexus_client::Client,
nexus_client: NexusClient,

// Storage resources
storage: StorageHandle,
Expand Down Expand Up @@ -1566,6 +1567,7 @@ mod tests {
use super::*;
use crate::fakes::nexus::{FakeNexusServer, ServerContext};
use crate::metrics;
use crate::nexus::make_nexus_client_with_port;
use crate::vmm_reservoir::VmmReservoirManagerHandle;
use crate::zone_bundle::CleanupContext;
use camino_tempfile::Utf8TempDir;
Expand Down Expand Up @@ -1632,7 +1634,7 @@ mod tests {
}

struct FakeNexusParts {
nexus_client: NexusClientWithResolver,
nexus_client: NexusClient,
_nexus_server: HttpServer<ServerContext>,
state_rx: Receiver<ReceivedInstanceState>,
_dns_server: TransientServer,
Expand Down Expand Up @@ -1660,12 +1662,11 @@ mod tests {
.unwrap(),
);

let nexus_client =
NexusClientWithResolver::new_from_resolver_with_port(
&log,
resolver,
_nexus_server.local_addr().port(),
);
let nexus_client = make_nexus_client_with_port(
&log,
resolver,
_nexus_server.local_addr().port(),
);

Self { nexus_client, _nexus_server, state_rx, _dns_server }
}
Expand Down Expand Up @@ -1758,7 +1759,7 @@ mod tests {
async fn instance_struct(
log: &Logger,
propolis_addr: SocketAddr,
nexus_client_with_resolver: NexusClientWithResolver,
nexus_client: NexusClient,
storage_handle: StorageHandle,
temp_dir: &String,
) -> (Instance, MetricsRx) {
Expand All @@ -1772,7 +1773,7 @@ mod tests {
let (services, rx) = fake_instance_manager_services(
log,
storage_handle,
nexus_client_with_resolver,
nexus_client,
temp_dir,
);

Expand Down Expand Up @@ -1848,7 +1849,7 @@ mod tests {
fn fake_instance_manager_services(
log: &Logger,
storage_handle: StorageHandle,
nexus_client_with_resolver: NexusClientWithResolver,
nexus_client: NexusClient,
temp_dir: &String,
) -> (InstanceManagerServices, MetricsRx) {
let vnic_allocator =
Expand All @@ -1867,7 +1868,7 @@ mod tests {

let (metrics_queue, rx) = MetricsRequestQueue::for_test();
let services = InstanceManagerServices {
nexus_client: nexus_client_with_resolver,
nexus_client,
vnic_allocator,
port_manager,
storage: storage_handle,
Expand Down
7 changes: 4 additions & 3 deletions sled-agent/src/instance_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use crate::instance::propolis_zone_name;
use crate::instance::Instance;
use crate::metrics::MetricsRequestQueue;
use crate::nexus::NexusClient;
use crate::params::InstanceExternalIpBody;
use crate::params::InstanceMetadata;
use crate::params::ZoneBundleMetadata;
Expand Down Expand Up @@ -73,7 +74,7 @@ pub enum Error {
}

pub(crate) struct InstanceManagerServices {
pub nexus_client: nexus_client::Client,
pub nexus_client: NexusClient,
pub vnic_allocator: VnicAllocator<Etherstub>,
pub port_manager: PortManager,
pub storage: StorageHandle,
Expand Down Expand Up @@ -102,7 +103,7 @@ impl InstanceManager {
#[allow(clippy::too_many_arguments)]
pub fn new(
log: Logger,
nexus_client: nexus_client::Client,
nexus_client: NexusClient,
etherstub: Etherstub,
port_manager: PortManager,
storage: StorageHandle,
Expand Down Expand Up @@ -421,7 +422,7 @@ struct InstanceManagerRunner {
terminate_tx: mpsc::UnboundedSender<InstanceDeregisterRequest>,
terminate_rx: mpsc::UnboundedReceiver<InstanceDeregisterRequest>,

nexus_client: nexus_client::Client,
nexus_client: NexusClient,

// TODO: If we held an object representing an enum of "Created OR Running"
// instance, we could avoid the methods within "instance.rs" that panic
Expand Down
15 changes: 9 additions & 6 deletions sled-agent/src/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

pub use nexus_client::Client as NexusClient;
use omicron_common::api::external::Generation;
use omicron_common::disk::DiskVariant;

use crate::vmm_reservoir::VmmReservoirManagerHandle;
use internal_dns::resolver::{ResolveError, Resolver};
use internal_dns::resolver::Resolver;
use internal_dns::ServiceName;
use nexus_client::types::SledAgentInfo;
use omicron_common::address::NEXUS_INTERNAL_PORT;
Expand All @@ -19,29 +18,33 @@ use tokio::sync::{broadcast, mpsc, oneshot, Notify};
use tokio::time::{interval, Duration, MissedTickBehavior};
use uuid::Uuid;

// Re-export the nexus_client::Client crate. (Use a type alias to be more
// rust-analyzer friendly.)
pub(crate) type NexusClient = nexus_client::Client;

pub(crate) fn make_nexus_client(
log: &Logger,
resolver: Arc<Resolver>,
) -> Result<NexusClient, ResolveError> {
) -> NexusClient {
make_nexus_client_with_port(log, resolver, NEXUS_INTERNAL_PORT)
}

pub(crate) fn make_nexus_client_with_port(
log: &Logger,
resolver: Arc<Resolver>,
port: u16,
) -> Result<NexusClient, ResolveError> {
) -> NexusClient {
let client = reqwest::ClientBuilder::new()
.dns_resolver(resolver)
.build()
.expect("Failed to build client");

let dns_name = ServiceName::Nexus.srv_name();
Ok(NexusClient::new_with_client(
NexusClient::new_with_client(
&format!("http://{dns_name}:{port}"),
client,
log.new(o!("component" => "NexusClient")),
))
)
}

pub fn d2n_params(
Expand Down
5 changes: 3 additions & 2 deletions sled-agent/src/probe_manager.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::metrics::MetricsRequestQueue;
use crate::nexus::NexusClient;
use anyhow::{anyhow, Result};
use illumos_utils::dladm::Etherstub;
use illumos_utils::link::VnicAllocator;
Expand Down Expand Up @@ -53,7 +54,7 @@ struct RunningProbes {

pub(crate) struct ProbeManagerInner {
join_handle: Mutex<Option<JoinHandle<()>>>,
nexus_client: nexus_client::Client,
nexus_client: NexusClient,
log: Logger,
sled_id: Uuid,
vnic_allocator: VnicAllocator<Etherstub>,
Expand All @@ -66,7 +67,7 @@ pub(crate) struct ProbeManagerInner {
impl ProbeManager {
pub(crate) fn new(
sled_id: Uuid,
nexus_client: nexus_client::Client,
nexus_client: NexusClient,
etherstub: Etherstub,
storage: StorageHandle,
port_manager: PortManager,
Expand Down
3 changes: 1 addition & 2 deletions sled-agent/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ impl Server {
.map_err(|e| e.to_string())?,
);

let nexus_client =
make_nexus_client(&log, resolver).map_err(|e| e.to_string())?;
let nexus_client = make_nexus_client(&log, resolver);

let sled_agent = SledAgent::new(
&config,
Expand Down
6 changes: 3 additions & 3 deletions sled-agent/src/sled_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::instance_manager::InstanceManager;
use crate::long_running_tasks::LongRunningTaskHandles;
use crate::metrics::MetricsManager;
use crate::nexus::{
NexusNotifierHandle, NexusNotifierInput, NexusNotifierTask,
NexusClient, NexusNotifierHandle, NexusNotifierInput, NexusNotifierTask,
};
use crate::params::{
DiskStateRequested, InstanceExternalIpBody, InstanceHardware,
Expand Down Expand Up @@ -319,7 +319,7 @@ struct SledAgentInner {
services: ServiceManager,

// Connection to Nexus.
nexus_client: nexus_client::Client,
nexus_client: NexusClient,

// A mechanism for notifiying nexus about sled-agent updates
nexus_notifier: NexusNotifierHandle,
Expand Down Expand Up @@ -364,7 +364,7 @@ impl SledAgent {
pub async fn new(
config: &Config,
log: Logger,
nexus_client: nexus_client::Client,
nexus_client: NexusClient,
request: StartSledAgentRequest,
services: ServiceManager,
long_running_task_handles: LongRunningTaskHandles,
Expand Down
2 changes: 1 addition & 1 deletion sled-agent/src/updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ impl UpdateManager {
mod test {
use super::*;
use crate::fakes::nexus::FakeNexusServer;
use crate::nexus::NexusClient;
use flate2::write::GzEncoder;
use nexus_client::Client as NexusClient;
use omicron_common::api::external::{Error, SemverVersion};
use omicron_common::api::internal::nexus::UpdateArtifactId;
use omicron_test_utils::dev::test_setup_log;
Expand Down

0 comments on commit 667ff17

Please sign in to comment.