Skip to content

Commit 0a76d62

Browse files
committed
Better comments & error message
1 parent e019fda commit 0a76d62

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

nexus/src/external_api/http_entrypoints.rs

+20-5
Original file line numberDiff line numberDiff line change
@@ -6443,23 +6443,37 @@ impl NexusExternalApi for NexusExternalApiImpl {
64436443
let params = body.into_inner();
64446444
let system_version = params.system_version;
64456445

6446+
// We don't need a transaction for the following queries because
6447+
// (1) the generation numbers provide optimistic concurrency control:
6448+
// if another request were to successfully update the target release
6449+
// between when we fetch it here and when we try to update it below,
6450+
// our update would fail because the next generation number would
6451+
// would already be taken; and
6452+
// (2) we assume that TUF repo depot records are immutable, i.e.,
6453+
// system version X.Y.Z won't designate different repos over time.
64466454
let current_target_release =
64476455
nexus.datastore().target_release_get_current(&opctx).await?;
6448-
let view = nexus
6456+
6457+
// Disallow downgrades.
6458+
if let views::TargetReleaseSource::SystemVersion { version } = nexus
64496459
.datastore()
64506460
.target_release_view(&opctx, &current_target_release)
6451-
.await?;
6452-
if let views::TargetReleaseSource::SystemVersion { version } =
6453-
view.release_source
6461+
.await?
6462+
.release_source
64546463
{
64556464
if version > system_version {
64566465
return Err(HttpError::for_bad_request(
64576466
None,
6458-
"can't downgrade system".into(),
6467+
format!(
6468+
"The requested target system release ({system_version}) \
6469+
is older than the current target system release ({version}). \
6470+
This is not supported."
6471+
),
64596472
));
64606473
}
64616474
}
64626475

6476+
// Fetch the TUF repo metadata and update the target release.
64636477
let tuf_repo_id = nexus
64646478
.datastore()
64656479
.update_tuf_repo_get(&opctx, system_version.into())
@@ -6475,6 +6489,7 @@ impl NexusExternalApi for NexusExternalApiImpl {
64756489
.datastore()
64766490
.target_release_insert(&opctx, next_target_release)
64776491
.await?;
6492+
64786493
Ok(HttpResponseCreated(
64796494
nexus
64806495
.datastore()

openapi/nexus-internal.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2347,7 +2347,7 @@
23472347
]
23482348
},
23492349
"BlueprintZoneImageSource": {
2350-
"description": "Where a blueprint's image source is located.\n\nThis is the blueprint version of [`OmicronZoneImageSource`].",
2350+
"description": "Where the zone image source is located.\n\nThis is the blueprint version of [`OmicronZoneImageSource`].",
23512351
"oneOf": [
23522352
{
23532353
"description": "This zone's image source is whatever happens to be on the sled's \"install\" dataset.\n\nThis is whatever was put in place at the factory or by the latest MUPdate. The image used here can vary by sled and even over time (if the sled gets MUPdated again).\n\nHistorically, this was the only source for zone images. In an system with automated control-plane-driven update we expect to only use this variant in emergencies where the system had to be recovered via MUPdate.",

0 commit comments

Comments
 (0)