Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions nexus/mgs-updates/src/test_util/host_phase_2_test_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ mod api_impl {
use sled_agent_types_versions::v1;
use sled_agent_types_versions::v20;
use sled_agent_types_versions::v24;
use sled_agent_types_versions::v25;
use sled_diagnostics::SledDiagnosticsQueryOutput;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
Expand Down Expand Up @@ -770,6 +771,13 @@ mod api_impl {
}

async fn write_network_bootstore_config(
_rqctx: RequestContext<Self::Context>,
_body: TypedBody<v25::early_networking::WriteNetworkConfigRequest>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
unimplemented!()
}

async fn write_network_bootstore_config_v24(
_rqctx: RequestContext<Self::Context>,
_body: TypedBody<v24::early_networking::WriteNetworkConfigRequest>,
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
Expand Down
1 change: 0 additions & 1 deletion nexus/src/app/background/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,6 @@ impl BackgroundTasksInitializer {
task_impl: Box::new(SwitchPortSettingsManager::new(
datastore.clone(),
resolver.clone(),
rx_blueprint.clone(),
)),
opctx: opctx.child(BTreeMap::new()),
watchers: vec![],
Expand Down
89 changes: 16 additions & 73 deletions nexus/src/app/background/tasks/sync_switch_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
//! to relevant management daemons (dendrite, mgd, sled-agent, etc.)

use crate::app::{
background::{
LoadedTargetBlueprint,
tasks::networking::{api_to_dpd_port_settings, build_mgd_clients},
background::tasks::networking::{
api_to_dpd_port_settings, build_mgd_clients,
},
dpd_clients, switch_zone_address_mappings,
};
Expand All @@ -21,7 +20,6 @@ use nexus_db_model::{
AddressLotBlock, BgpConfig, BootstoreConfig, INFRA_LOT, LoopbackAddress,
NETWORK_KEY, SwitchLinkSpeed,
};
use tokio::sync::watch;
use uuid::Uuid;

use crate::app::background::BackgroundTask;
Expand Down Expand Up @@ -131,16 +129,11 @@ impl Default for AddStaticRouteRequest {
pub struct SwitchPortSettingsManager {
datastore: Arc<DataStore>,
resolver: Resolver,
rx_blueprint: watch::Receiver<Option<LoadedTargetBlueprint>>,
}

impl SwitchPortSettingsManager {
pub fn new(
datastore: Arc<DataStore>,
resolver: Resolver,
rx_blueprint: watch::Receiver<Option<LoadedTargetBlueprint>>,
) -> Self {
Self { datastore, resolver, rx_blueprint }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing that you have managed to get rid of reading from the bootstore and blueprint!

pub fn new(datastore: Arc<DataStore>, resolver: Resolver) -> Self {
Self { datastore, resolver }
}

async fn switch_ports(
Expand Down Expand Up @@ -1031,40 +1024,6 @@ impl BackgroundTask for SwitchPortSettingsManager {
// calculate and apply bootstore changes
//

// TODO: #5232 Make ntp servers w/ generation tracking
// first-class citizens in the db
//
// In the meantime, we can read the NTP servers from the current
// target blueprint.
let ntp_servers = {
// Clone the target blueprint to avoid holding the watch
// channel any longer than necessary.
let Some(LoadedTargetBlueprint { blueprint, .. }) = self
.rx_blueprint
.borrow_and_update()
.clone()
else {
warn!(
log,
"no blueprint loaded yet; skipping bootstore sync",
);
continue;
};

match blueprint.upstream_ntp_config() {
Some(config) => config.ntp_servers.to_vec(),
None => {
warn!(
log,
"target blueprint has no upstream NTP config; \
assuming this is a dev/test system and \
skipping bootstore sync",
);
continue;
}
}
};

// build the desired bootstore config from the records we've fetched
let subnet = match rack.rack_subnet {
Some(IpNetwork::V6(subnet)) => subnet.into(),
Expand Down Expand Up @@ -1348,15 +1307,14 @@ impl BackgroundTask for SwitchPortSettingsManager {
};

let desired_config = EarlyNetworkConfigBody {
ntp_servers,
rack_network_config: Some(RackNetworkConfig {
rack_network_config: RackNetworkConfig {
rack_subnet: subnet,
infra_ip_first,
infra_ip_last,
ports,
bgp,
bfd,
}),
},
};

// bootstore_needs_update is a boolean value that determines
Expand Down Expand Up @@ -1386,33 +1344,18 @@ impl BackgroundTask for SwitchPortSettingsManager {
.and_then(|envelope| envelope.deserialize_body())
{
Ok(config) => {
let current_ntp_servers: HashSet<String> = config.ntp_servers.clone().into_iter().collect();
let desired_ntp_servers: HashSet<String> = desired_config.ntp_servers.clone().into_iter().collect();

let rnc_differs = match (config.rack_network_config.clone(), desired_config.rack_network_config.clone()) {
(Some(current_rnc), Some(desired_rnc)) => {
!hashset_eq(current_rnc.bgp.clone(), desired_rnc.bgp.clone()) ||
!hashset_eq(current_rnc.bfd.clone(), desired_rnc.bfd.clone()) ||
!hashset_eq(current_rnc.ports.clone(), desired_rnc.ports.clone()) ||
current_rnc.rack_subnet != desired_rnc.rack_subnet ||
current_rnc.infra_ip_first != desired_rnc.infra_ip_first ||
current_rnc.infra_ip_last != desired_rnc.infra_ip_last
},
(None, Some(_)) => true,
_ => {
todo!("error")
}
let current_rnc = &config.rack_network_config;
let desired_rnc = &desired_config.rack_network_config;
let rnc_differs = {
!hashset_eq(current_rnc.bgp.clone(), desired_rnc.bgp.clone()) ||
!hashset_eq(current_rnc.bfd.clone(), desired_rnc.bfd.clone()) ||
!hashset_eq(current_rnc.ports.clone(), desired_rnc.ports.clone()) ||
current_rnc.rack_subnet != desired_rnc.rack_subnet ||
current_rnc.infra_ip_first != desired_rnc.infra_ip_first ||
current_rnc.infra_ip_last != desired_rnc.infra_ip_last
};

if current_ntp_servers != desired_ntp_servers {
info!(
log,
"ntp servers have changed";
"old" => ?current_ntp_servers,
"new" => ?desired_ntp_servers,
);
true
} else if rnc_differs {
if rnc_differs {
info!(
log,
"rack network config has changed";
Expand Down
5 changes: 2 additions & 3 deletions nexus/test-utils/src/starter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,15 +918,14 @@ impl<'a, N: NexusServer> ControlPlaneStarter<'a, N> {
pub async fn configure_sled_agents(&mut self) {
let early_network_config = WriteNetworkConfigRequest {
body: EarlyNetworkConfigBody {
ntp_servers: Vec::new(),
rack_network_config: Some(RackNetworkConfig {
rack_network_config: RackNetworkConfig {
bfd: Vec::new(),
bgp: Vec::new(),
infra_ip_first: "192.0.2.10".parse().unwrap(),
infra_ip_last: "192.0.2.100".parse().unwrap(),
ports: Vec::new(),
rack_subnet: "fd00:1122:3344:0100::/56".parse().unwrap(),
}),
},
},
generation: 1,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@
},
"/network-bootstore-config": {
"put": {
"operationId": "write_network_bootstore_config",
"operationId": "write_network_bootstore_config_v24",
"requestBody": {
"content": {
"application/json": {
Expand Down
Loading
Loading