# Load example system
load-example --nsleds 2 --ndisks-per-sled 3

# Create a TUF repository from a fake manifest. (The output TUF repo is
# written to a temporary directory that this invocation of `reconfigurator-cli`
# is running out of as its working directory.)
#
# This is used to simulate the initial version of the system.
generate-fake-repo 0.0.1

# Load the target release from the assembled TUF repository.
set target-release repo-0.0.1.zip

# Update the install dataset on all sleds to the target release.
# This will cause zones to be noop converted over to Artifact,
# unblocking upgrades.
sled-update-install-dataset serial0 --to-target-release
sled-update-install-dataset serial1 --to-target-release

# Measurements will block further planning progress, run a planning step
inventory-generate
blueprint-plan latest latest
blueprint-diff latest

# Make sure the measurements are up to date for inventory
sled-set serial0 omicron-config latest
sled-set serial1 omicron-config latest

# Generate inventory, then do a planning run to ensure that all zones
# are set to Artifact.
inventory-generate
blueprint-plan latest latest
blueprint-diff latest
# The above blueprint includes a pending MGS update, which we should delete
# (we want to start from a fresh state).
blueprint-edit latest delete-sp-update serial0
# Also set the Omicron config for all sleds to reflect the
# corresponding image sources.
sled-set serial0 omicron-config latest
sled-set serial1 omicron-config latest
# Generate inventory once more to reflect the omicron config changes.
inventory-generate

# Setup is now done -- create another TUF repository which will act as the
# target release being updated to.
generate-fake-repo 1.0.0

# Load the target release from the assembled TUF repository.
set target-release repo-1.0.0.zip

# Measurements will block further planning progress, run a planning step
blueprint-plan latest latest
blueprint-diff latest

# Make sure the measurements are up to date for inventory
sled-set serial0 omicron-config latest
sled-set serial1 omicron-config latest
inventory-generate

# First step: upgrade one RoT bootloader.
blueprint-plan latest latest
blueprint-diff latest

# One by one, update the RoT bootloader, RoT, SP, and host OS of the first sled.
sled-update-rot-bootloader serial0 --stage0 1.0.0
inventory-generate
blueprint-plan latest latest
blueprint-diff latest

sled-update-rot serial0 --slot-b 1.0.0 --active-slot b --persistent-boot-preference b
inventory-generate
blueprint-plan latest latest
blueprint-diff latest

sled-update-sp serial0 --active 1.0.0
inventory-generate
blueprint-plan latest latest
blueprint-diff latest

sled-update-host-phase2 serial0 --slot-b c2a8af75d6907ef138d033dc3be1fcbf7d7a78a87aee04796caf283a6bb0952d
sled-update-host-phase1 serial0 --active B --slot-b 2902cb5932fa703ed62fc6a0a330898fe6fd4bde68c74f6398a6aa916cb7e79c
sled-update-host-phase2 serial0 --boot-disk B

# Before generating the inventory that completes all updates on sled serial0,
# mark sled serial1 as hidden in inventory. We should see a note in the planner
# report that we are missing sled agent inventory for measurements on sled 1.
# This will block any MGS updates that could be pending because we must
# observe the expected measurements on all sleds before we proceed.
#
# Apply the latest blueprint to serial0's inventory so that its reported
# sled-agent generation isn't stale relative to the parent blueprint. (Earlier
# plans bumped the blueprint's generation for this sled.) That keeps the noop
# check on serial0 from firing the inventory-stale path.
sled-set serial0 omicron-config latest
sled-set serial1 inventory-hidden
inventory-generate
blueprint-plan latest latest
blueprint-diff latest
