Skip to content

Commit b6f7e55

Browse files
authored
[38/n] [sled-agent-zone-images] use real Omicron zone names (#8687)
We're going to switch this API to accept an Omicron `ZoneKind` soon. Prepare for that change by using real zone names internally.
1 parent 21fb969 commit b6f7e55

File tree

7 files changed

+71
-46
lines changed

7 files changed

+71
-46
lines changed

.git-blame-ignore-revs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# Whitespace-only changes
22
d01ba56c2127789d85723793380a7378394583f1
3+
852c59e89088455d251376786776fd556784995c

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sled-agent/zone-images-examples/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ workspace = true
1111
camino.workspace = true
1212
camino-tempfile-ext.workspace = true
1313
iddqd.workspace = true
14+
nexus-sled-agent-shared.workspace = true
1415
omicron-common.workspace = true
1516
omicron-uuid-kinds.workspace = true
1617
omicron-workspace-hack.workspace = true

sled-agent/zone-images-examples/src/lib.rs

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use camino_tempfile_ext::{
1515
prelude::*,
1616
};
1717
use iddqd::{IdOrdItem, IdOrdMap, id_upcast};
18+
use nexus_sled_agent_shared::inventory::ZoneKind;
1819
use omicron_common::update::{
1920
MupdateOverrideInfo, OmicronZoneFileMetadata, OmicronZoneManifest,
2021
OmicronZoneManifestSource,
@@ -82,12 +83,13 @@ impl WriteInstallDatasetContext {
8283
/// errors.
8384
pub fn new_basic() -> Self {
8485
Self {
86+
// The zones are picked arbitrarily for our unit tests.
8587
zones: [
86-
ZoneContents::new("zone1.tar.gz", b"zone1"),
87-
ZoneContents::new("zone2.tar.gz", b"zone2"),
88-
ZoneContents::new("zone3.tar.gz", b"zone3"),
89-
ZoneContents::new("zone4.tar.gz", b"zone4"),
90-
ZoneContents::new("zone5.tar.gz", b"zone5"),
88+
ZoneContents::new(ZoneKind::CockroachDb, b"fake cockroachdb"),
89+
ZoneContents::new(ZoneKind::Clickhouse, b"fake clickhouse"),
90+
ZoneContents::new(ZoneKind::Crucible, b"fake crucible"),
91+
ZoneContents::new(ZoneKind::InternalDns, b"fake internal_dns"),
92+
ZoneContents::new(ZoneKind::Nexus, b"fake nexus"),
9193
]
9294
.into_iter()
9395
.collect(),
@@ -99,16 +101,17 @@ impl WriteInstallDatasetContext {
99101

100102
/// Makes a number of error cases for testing.
101103
pub fn make_error_cases(&mut self) {
102-
// zone1.tar.gz is valid.
103-
// For zone2.tar.gz, change the size.
104-
self.zones.get_mut("zone2.tar.gz").unwrap().json_size = 1024;
105-
// For zone3.tar.gz, change the hash.
106-
self.zones.get_mut("zone3.tar.gz").unwrap().json_hash =
104+
// cockroachdb.tar.gz is valid.
105+
// For clickhouse, change the size.
106+
self.zones.get_mut(&ZoneKind::Clickhouse).unwrap().json_size = 1024;
107+
// For crucible, change the hash.
108+
self.zones.get_mut(&ZoneKind::Crucible).unwrap().json_hash =
107109
ArtifactHash([0; 32]);
108-
// Don't write out zone4 but include it in the JSON.
109-
self.zones.get_mut("zone4.tar.gz").unwrap().write_to_disk = false;
110-
// Write out zone5 but don't include it in the JSON.
111-
self.zones.get_mut("zone5.tar.gz").unwrap().include_in_json = false;
110+
// Don't write out internal DNS but include it in the JSON.
111+
self.zones.get_mut(&ZoneKind::InternalDns).unwrap().write_to_disk =
112+
false;
113+
// Write out nexus but don't include it in the JSON.
114+
self.zones.get_mut(&ZoneKind::Nexus).unwrap().include_in_json = false;
112115
}
113116

114117
/// Set to false to not write out the zone manifest to disk.
@@ -141,7 +144,10 @@ impl WriteInstallDatasetContext {
141144
.iter()
142145
.filter_map(|zone| {
143146
zone.include_in_json.then(|| OmicronZoneFileMetadata {
144-
file_name: zone.file_name.clone(),
147+
file_name: zone
148+
.zone_kind
149+
.artifact_in_install_dataset()
150+
.to_owned(),
145151
file_size: zone.json_size,
146152
hash: zone.json_hash,
147153
})
@@ -176,7 +182,8 @@ impl WriteInstallDatasetContext {
176182
pub fn write_to(&self, dir: &ChildPath) -> Result<(), FixtureError> {
177183
for zone in &self.zones {
178184
if zone.write_to_disk {
179-
dir.child(&zone.file_name).write_binary(&zone.contents)?;
185+
dir.child(zone.zone_kind.artifact_in_install_dataset())
186+
.write_binary(&zone.contents)?;
180187
}
181188
}
182189

@@ -202,7 +209,7 @@ impl WriteInstallDatasetContext {
202209

203210
#[derive(Clone, Debug)]
204211
pub struct ZoneContents {
205-
file_name: String,
212+
zone_kind: ZoneKind,
206213
contents: Vec<u8>,
207214
// json_size and json_hash are stored separately, so tests can tweak
208215
// them before writing out the override info.
@@ -213,11 +220,11 @@ pub struct ZoneContents {
213220
}
214221

215222
impl ZoneContents {
216-
fn new(file_name: &str, contents: &[u8]) -> Self {
223+
fn new(zone_kind: ZoneKind, contents: &[u8]) -> Self {
217224
let size = contents.len() as u64;
218225
let hash = compute_hash(contents);
219226
Self {
220-
file_name: file_name.to_string(),
227+
zone_kind,
221228
contents: contents.to_vec(),
222229
json_size: size,
223230
json_hash: hash,
@@ -243,9 +250,12 @@ impl ZoneContents {
243250
}
244251
};
245252

253+
let file_name = self.zone_kind.artifact_in_install_dataset().to_owned();
254+
let path = dir.join(&file_name);
255+
246256
ZoneManifestArtifactResult {
247-
file_name: self.file_name.clone(),
248-
path: dir.join(&self.file_name),
257+
file_name,
258+
path,
249259
expected_size: self.json_size,
250260
expected_hash: self.json_hash,
251261
status,
@@ -254,10 +264,10 @@ impl ZoneContents {
254264
}
255265

256266
impl IdOrdItem for ZoneContents {
257-
type Key<'a> = &'a str;
267+
type Key<'a> = ZoneKind;
258268

259269
fn key(&self) -> Self::Key<'_> {
260-
&self.file_name
270+
self.zone_kind
261271
}
262272

263273
id_upcast!();

sled-agent/zone-images/src/source_resolver.rs

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ mod tests {
228228

229229
use camino_tempfile_ext::prelude::*;
230230
use dropshot::{ConfigLogging, ConfigLoggingLevel, test_util::LogContext};
231+
use nexus_sled_agent_shared::inventory::ZoneKind;
231232
use sled_agent_zone_images_examples::{
232233
BOOT_PATHS, BOOT_UUID, WriteInstallDatasetContext,
233234
};
@@ -252,16 +253,16 @@ mod tests {
252253
// RAM disk image sources should work as expected.
253254
let ramdisk_source = resolver
254255
.file_source_for(
255-
"zone1",
256+
"switch",
256257
&ZoneImageSource::Ramdisk,
257258
internal_disks_rx.current(),
258259
)
259260
.unwrap();
260-
assert_eq!(ramdisk_source, ramdisk_file_source("zone1"));
261+
assert_eq!(ramdisk_source, ramdisk_file_source("switch"));
261262

262263
let file_source = resolver
263264
.file_source_for(
264-
"zone1",
265+
ZoneKind::CockroachDb.zone_prefix(),
265266
&ZoneImageSource::Omicron(
266267
OmicronZoneImageSource::InstallDataset,
267268
),
@@ -274,7 +275,9 @@ mod tests {
274275
assert_eq!(
275276
file_source,
276277
ZoneImageFileSource {
277-
file_name: install_dataset_file_name("zone1"),
278+
file_name: ZoneKind::CockroachDb
279+
.artifact_in_install_dataset()
280+
.to_owned(),
278281
search_paths: vec![Utf8PathBuf::from(RAMDISK_IMAGE_PATH)]
279282
}
280283
);
@@ -305,17 +308,17 @@ mod tests {
305308
// The resolver should not fail for ramdisk images.
306309
let file_source = resolver
307310
.file_source_for(
308-
"fake-zone",
311+
"switch",
309312
&ZoneImageSource::Ramdisk,
310313
internal_disks_rx.current(),
311314
)
312315
.unwrap();
313-
assert_eq!(file_source, ramdisk_file_source("fake-zone"));
316+
assert_eq!(file_source, ramdisk_file_source("switch"));
314317

315-
// zone1.tar.gz is valid.
318+
// The cockroach zone is valid.
316319
let file_source = resolver
317320
.file_source_for(
318-
"zone1",
321+
ZoneKind::CockroachDb.zone_prefix(),
319322
&ZoneImageSource::Omicron(
320323
OmicronZoneImageSource::InstallDataset,
321324
),
@@ -325,20 +328,27 @@ mod tests {
325328
assert_eq!(
326329
file_source,
327330
ZoneImageFileSource {
328-
file_name: "zone1.tar.gz".to_string(),
331+
file_name: ZoneKind::CockroachDb
332+
.artifact_in_install_dataset()
333+
.to_string(),
329334
search_paths: vec![
330335
Utf8PathBuf::from(RAMDISK_IMAGE_PATH),
331336
dir.path().join(&BOOT_PATHS.install_dataset)
332337
]
333338
},
334339
);
335340

336-
// zone2, zone3, zone4 and zone5 aren't valid, and none of them will
337-
// return the install dataset path.
338-
for zone_name in ["zone2", "zone3", "zone4", "zone5"] {
341+
// Clickhouse, Crucible, InternalDns and Nexus aren't valid, and none of
342+
// them will return the install dataset path.
343+
for zone_kind in [
344+
ZoneKind::Clickhouse,
345+
ZoneKind::Crucible,
346+
ZoneKind::InternalDns,
347+
ZoneKind::Nexus,
348+
] {
339349
let file_source = resolver
340350
.file_source_for(
341-
zone_name,
351+
zone_kind.zone_prefix(),
342352
&ZoneImageSource::Omicron(
343353
OmicronZoneImageSource::InstallDataset,
344354
),
@@ -348,7 +358,9 @@ mod tests {
348358
assert_eq!(
349359
file_source,
350360
ZoneImageFileSource {
351-
file_name: install_dataset_file_name(zone_name),
361+
file_name: zone_kind
362+
.artifact_in_install_dataset()
363+
.to_owned(),
352364
search_paths: vec![Utf8PathBuf::from(RAMDISK_IMAGE_PATH)]
353365
}
354366
);
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
5 artifacts in manifest generated by installinator (mupdate ID: 00000000-0000-0000-0000-000000000000): 5 valid, 0 mismatched, 0 errors:
2-
- zone1.tar.gz: valid (5 bytes, a34f924efa72cd0139ea5dc268f5d2736a9ebc858552b8f3c8cb2bed1992c31d)
3-
- zone2.tar.gz: valid (5 bytes, 930c5a9adbeb8410817a1dff05d7cbffe4ada2ddbeaacecadd7cbcb35a233231)
4-
- zone3.tar.gz: valid (5 bytes, 0f40fdb255100d0239a7e0944c8b9fdb9ba4795ad72988eaeeb00e9346236e08)
5-
- zone4.tar.gz: valid (5 bytes, 64d6e4a84209b4b02f4da36d24eae12b0d1ec9e414d1c3bd12a261a245148324)
6-
- zone5.tar.gz: valid (5 bytes, 112b21db93f16057fa957a58b711bff40ec395c9147d4084a88c9085c6507bf7)
2+
- clickhouse.tar.gz: valid (15 bytes, 360cfb774fc2f2e492efcb21995620ea4dcb0abc4bd390bb391785c7f7429386)
3+
- cockroachdb.tar.gz: valid (16 bytes, 7a91673e17475dfd18ca5267ecf4c771000eefa715e324db915448034e913bc1)
4+
- crucible.tar.gz: valid (13 bytes, a18058cdfecf9eb3251f5b1c87986e565713080a7f7b00adf81fd0e201ba4d62)
5+
- internal_dns.tar.gz: valid (17 bytes, f4ef1d710d82c1daa35e0c0a8100913139e2bfb349e435cf9ce5b72625d7bdef)
6+
- nexus.tar.gz: valid (10 bytes, 96eddf0a4af3e1991879de233883cd9e2a15ed68cabd69977034d12842579b80)
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
4 artifacts in manifest generated by installinator (mupdate ID: 00000000-0000-0000-0000-000000000000): 1 valid, 2 mismatched, 1 errors:
2-
- zone1.tar.gz: valid (5 bytes, a34f924efa72cd0139ea5dc268f5d2736a9ebc858552b8f3c8cb2bed1992c31d)
3-
- zone2.tar.gz: mismatch (expected 1024 bytes, 930c5a9adbeb8410817a1dff05d7cbffe4ada2ddbeaacecadd7cbcb35a233231; found 5 bytes, 930c5a9adbeb8410817a1dff05d7cbffe4ada2ddbeaacecadd7cbcb35a233231)
4-
- zone3.tar.gz: mismatch (expected 5 bytes, 0000000000000000000000000000000000000000000000000000000000000000; found 5 bytes, 0f40fdb255100d0239a7e0944c8b9fdb9ba4795ad72988eaeeb00e9346236e08)
5-
- zone4.tar.gz: error (file not found)
2+
- clickhouse.tar.gz: mismatch (expected 1024 bytes, 360cfb774fc2f2e492efcb21995620ea4dcb0abc4bd390bb391785c7f7429386; found 15 bytes, 360cfb774fc2f2e492efcb21995620ea4dcb0abc4bd390bb391785c7f7429386)
3+
- cockroachdb.tar.gz: valid (16 bytes, 7a91673e17475dfd18ca5267ecf4c771000eefa715e324db915448034e913bc1)
4+
- crucible.tar.gz: mismatch (expected 13 bytes, 0000000000000000000000000000000000000000000000000000000000000000; found 13 bytes, a18058cdfecf9eb3251f5b1c87986e565713080a7f7b00adf81fd0e201ba4d62)
5+
- internal_dns.tar.gz: error (file not found)

0 commit comments

Comments
 (0)