Skip to content
Merged
88 changes: 85 additions & 3 deletions dev-tools/reconfigurator-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ use nexus_reconfigurator_planning::system::{SledBuilder, SystemDescription};
use nexus_reconfigurator_simulation::SimState;
use nexus_reconfigurator_simulation::SimStateBuilder;
use nexus_reconfigurator_simulation::Simulator;
use nexus_types::deployment::BlueprintZoneDisposition;
use nexus_types::deployment::BlueprintZoneImageSource;
use nexus_types::deployment::BlueprintZoneImageVersion;
use nexus_types::deployment::OmicronZoneNic;
use nexus_types::deployment::PlanningInput;
use nexus_types::deployment::SledFilter;
use nexus_types::deployment::execution;
use nexus_types::deployment::execution::blueprint_external_dns_config;
use nexus_types::deployment::execution::blueprint_internal_dns_config;
use nexus_types::deployment::{Blueprint, UnstableReconfiguratorState};
use nexus_types::deployment::{BlueprintZoneDisposition, ExpectedVersion};
use nexus_types::deployment::{
BlueprintZoneImageSource, PendingMgsUpdateDetails,
};
use nexus_types::deployment::{BlueprintZoneImageVersion, PendingMgsUpdate};
use nexus_types::external_api::views::SledPolicy;
use nexus_types::external_api::views::SledProvisionPolicy;
use omicron_common::address::REPO_DEPOT_PORT;
Expand Down Expand Up @@ -372,6 +374,32 @@ enum BlueprintEditCommands {
},
/// expunge a zone
ExpungeZone { zone_id: OmicronZoneUuid },
/// configure an SP update
SetSpUpdate {
/// serial number to update
serial: String,
/// artifact hash id
artifact_hash: ArtifactHash,
/// version
version: String,
/// component to update
#[command(subcommand)]
component: SpUpdateComponent,
},
/// delete a configured SP update
DeleteSpUpdate {
/// baseboard serial number whose update to delete
serial: String,
},
}

#[derive(Clone, Debug, Subcommand)]
enum SpUpdateComponent {
/// update the SP itself
Sp {
expected_active_version: ArtifactVersion,
expected_inactive_version: ExpectedVersion,
},
}

#[derive(Debug, Subcommand)]
Expand Down Expand Up @@ -874,6 +902,60 @@ fn cmd_blueprint_edit(
.context("failed to expunge zone")?;
format!("expunged zone {zone_id} from sled {sled_id}")
}
BlueprintEditCommands::SetSpUpdate {
serial,
artifact_hash,
version,
component,
} => {
let (baseboard_id, sp) = latest_collection
.sps
.iter()
.find(|(b, _)| b.serial_number == serial)
.ok_or_else(|| {
anyhow!("unknown baseboard serial: {serial:?}")
})?;

let details = match component {
SpUpdateComponent::Sp {
expected_active_version,
expected_inactive_version,
} => PendingMgsUpdateDetails::Sp {
expected_active_version,
expected_inactive_version,
},
};

let artifact_version = ArtifactVersion::new(version)
.context("parsing artifact version")?;

let update = PendingMgsUpdate {
baseboard_id: baseboard_id.clone(),
sp_type: sp.sp_type,
slot_id: u32::from(sp.sp_slot),
details,
artifact_hash,
artifact_version,
};

builder.pending_mgs_update_insert(update);
format!(
"configured update for serial {serial}\n\
warn: no validation is done on the requested artifact \
hash or version"
)
}
BlueprintEditCommands::DeleteSpUpdate { serial } => {
let baseboard_id = latest_collection
.baseboards
.iter()
.find(|b| b.serial_number == serial)
.ok_or_else(|| {
anyhow!("unknown baseboard serial: {serial:?}")
})?;
builder.pending_mgs_update_delete(baseboard_id);
format!("deleted configured update for serial {serial}")
}
};

let mut new_blueprint = builder.build();
Expand Down
42 changes: 42 additions & 0 deletions dev-tools/reconfigurator-cli/tests/input/cmds-set-mgs-updates.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Load example system
load-example --nsleds 3 --ndisks-per-sled 3
blueprint-show ad97e762-7bf1-45a6-a98f-60afb7e491c0

# Configure an MGS-managed update to one of the SPs.
blueprint-edit ad97e762-7bf1-45a6-a98f-60afb7e491c0 set-sp-update serial2 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 1.1.0 sp 1.0.0 1.0.1
blueprint-show cca24b71-09b5-4042-9185-b33e9f2ebba0
blueprint-diff ad97e762-7bf1-45a6-a98f-60afb7e491c0 cca24b71-09b5-4042-9185-b33e9f2ebba0
# diff in the reverse direction. Should show one removal.
blueprint-diff cca24b71-09b5-4042-9185-b33e9f2ebba0 ad97e762-7bf1-45a6-a98f-60afb7e491c0

# Change that configuration. It should replace the previous one.
# This also exercises versions that are not semver.
blueprint-edit cca24b71-09b5-4042-9185-b33e9f2ebba0 set-sp-update serial2 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 newest sp newer older
blueprint-show 5bf974f3-81f9-455b-b24e-3099f765664c
blueprint-diff cca24b71-09b5-4042-9185-b33e9f2ebba0 5bf974f3-81f9-455b-b24e-3099f765664c
# diff in the reverse direction. Should still show one modification.
blueprint-diff 5bf974f3-81f9-455b-b24e-3099f765664c cca24b71-09b5-4042-9185-b33e9f2ebba0

# Configure an MGS-managed update to a different SP.
# This should *not* replace the existing one.
# This also exercises the special "invalid" string for a version number.
blueprint-edit 5bf974f3-81f9-455b-b24e-3099f765664c set-sp-update serial0 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 three sp two invalid
blueprint-show 1b837a27-3be1-4fcb-8499-a921c839e1d0
blueprint-diff 5bf974f3-81f9-455b-b24e-3099f765664c 1b837a27-3be1-4fcb-8499-a921c839e1d0

# Delete one of these updates.
blueprint-edit 1b837a27-3be1-4fcb-8499-a921c839e1d0 delete-sp-update serial2
blueprint-show 3682a71b-c6ca-4b7e-8f84-16df80c85960
blueprint-diff 1b837a27-3be1-4fcb-8499-a921c839e1d0 3682a71b-c6ca-4b7e-8f84-16df80c85960

# test help output
blueprint-edit ad97e762-7bf1-45a6-a98f-60afb7e491c0 help
blueprint-edit ad97e762-7bf1-45a6-a98f-60afb7e491c0 set-sp-update help
blueprint-edit ad97e762-7bf1-45a6-a98f-60afb7e491c0 set-sp-update serial0 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 three --help
blueprint-edit ad97e762-7bf1-45a6-a98f-60afb7e491c0 set-sp-update serial0 e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 three sp --help
blueprint-edit ad97e762-7bf1-45a6-a98f-60afb7e491c0 delete-sp-update help

# test error case: no such serial
blueprint-edit ad97e762-7bf1-45a6-a98f-60afb7e491c0 set-sp-update not-a-serial e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 1.1.0 sp 1.0.0 1.0.1
# test error case: bad hash
blueprint-edit ad97e762-7bf1-45a6-a98f-60afb7e491c0 set-sp-update serial0 bogus-hash 1.1.0 sp 1.0.0 1.0.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
error: invalid value 'bogus-hash' for '<ARTIFACT_HASH>': Invalid string length

For more information, try '--help'.
Loading
Loading