Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
104 changes: 100 additions & 4 deletions dev-tools/reconfigurator-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,21 @@ 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 nexus_types::inventory::SpType;
use omicron_common::address::REPO_DEPOT_PORT;
use omicron_common::api::external::Generation;
use omicron_common::api::external::Name;
Expand All @@ -53,9 +56,11 @@ use std::fmt::Write;
use std::io::IsTerminal;
use swrite::{SWrite, swriteln};
use tabled::Tabled;
use tufaceous_artifact::ArtifactHash;
use tufaceous_artifact::ArtifactVersion;
use tufaceous_artifact::ArtifactVersionError;
use tufaceous_artifact::{
ArtifactHash, ArtifactHashId, ArtifactKind, KnownArtifactKind,
};

mod log_capture;

Expand Down Expand Up @@ -372,6 +377,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 +905,71 @@ 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 (known_artifact_kind, details) = match component {
SpUpdateComponent::Sp {
expected_active_version,
expected_inactive_version,
} => {
let known_artifact_kind = match sp.sp_type {
SpType::Sled => KnownArtifactKind::GimletSp,
SpType::Power => KnownArtifactKind::PscSp,
SpType::Switch => KnownArtifactKind::SwitchSp,
};
let details = PendingMgsUpdateDetails::Sp {
expected_active_version,
expected_inactive_version,
};
(known_artifact_kind, details)
}
};

let artifact_kind = ArtifactKind::from_known(known_artifact_kind);
let artifact_hash_id =
ArtifactHashId { kind: artifact_kind, hash: artifact_hash };
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_id,
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