# Load an example system. The sled with serial5 is marked non-provisionable
# so that discretionary zones don't make their way onto it. (We're going to
# expunge it below to test that we don't try and update zone image sources
# on expunged sleds.)
load-example --nsleds 7 --ndisks-per-sled 1 --sled-policy 5:non-provisionable

sled-list

# 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.)
generate-fake-repo 1.0.0
# Create a second TUF repository from a different fake manifest.
generate-fake-repo 2.0.0

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

# On one sled, update the install dataset.
sled-update-install-dataset serial0 --to-target-release

# On another sled, simulate an error reading the zone manifest.
sled-update-install-dataset serial1 --with-manifest-error

# On a third sled, update the install dataset and simulate a mupdate override.
# Also set it in the blueprint -- this simulates the situation where the mupdate
# override is in progress and will be cleared in the future.
sled-update-install-dataset serial2 --to-target-release
sled-set serial2 mupdate-override ffffffff-ffff-ffff-ffff-ffffffffffff
blueprint-edit latest set-remove-mupdate-override serial2 ffffffff-ffff-ffff-ffff-ffffffffffff
# Apply the latest blueprint to serial2's inventory so that the noop check
# exercises the mupdate-override-set-in-blueprint path rather than firing
# inventory-stale on the bumped sled-agent generation.
sled-set serial2 omicron-config latest

# On a fourth sled, simulate an error validating the install dataset image on one zone.
# We pick ntp because internal-ntp is non-discretionary.
sled-update-install-dataset serial3 --to-target-release --with-zone-error ntp

# On a fifth sled, set the install dataset to the repo-2.0.0.zip generated by the
# second TUF repository.
sled-update-install-dataset serial4 --from-repo repo-2.0.0.zip

# On the sixth sled, update to the target release (so it shows up in inventory).
# Then, mark the sled expunged (in the planning input).
sled-update-install-dataset serial5 --to-target-release
sled-set serial5 policy expunged

# On the seventh sled, update to the target release but hide the sled
# from inventory. This should prevent changes to the blueprint for
# this sled.
sled-update-install-dataset serial6 --to-target-release
sled-set serial6 inventory-hidden

# Generate an inventory and run a blueprint planning step.
inventory-generate
blueprint-plan latest latest

# This diff should show expected changes to the blueprint.
blueprint-diff latest

# Bring the hidden sled back.
sled-set serial6 inventory-visible

# The first plan bumped the sled-agent generation on the sleds where it did
# noop conversions (serial0, serial3) and where it set remove_mupdate_override
# (serial2). Apply that blueprint to those sleds' inventories so the next
# plan's noop check doesn't fire the inventory-stale path for them.
sled-set serial0 omicron-config latest
sled-set serial2 omicron-config latest
sled-set serial3 omicron-config latest

# Run another inventory and blueprint planning step.
inventory-generate
blueprint-plan latest latest

# This diff should show changes to the sled that's back in inventory.
blueprint-diff latest
