Skip to content

Commit 93c7b0b

Browse files
authored
[2/n] [reconfigurator-planning] avoid wiping out boot partition state (#8937)
The boot partition state is going to become important in tests soon, since we want to set up the simulated system such that no MGS-driven updates are happening. Simply calling `debug_assume_success` wipes out MGS-related state, so add an alternative that doesn't.
1 parent 884f2c2 commit 93c7b0b

File tree

2 files changed

+73
-42
lines changed

2 files changed

+73
-42
lines changed

nexus-sled-agent-shared/src/inventory.rs

Lines changed: 62 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,31 @@ impl ConfigReconcilerInventory {
190190
/// look at the actual `last_reconciliation` value from the parent
191191
/// [`Inventory`].
192192
pub fn debug_assume_success(config: OmicronSledConfig) -> Self {
193+
let mut ret = Self {
194+
// These fields will be filled in by `debug_update_assume_success`.
195+
last_reconciled_config: OmicronSledConfig::default(),
196+
external_disks: BTreeMap::new(),
197+
datasets: BTreeMap::new(),
198+
orphaned_datasets: IdOrdMap::new(),
199+
zones: BTreeMap::new(),
200+
remove_mupdate_override: None,
201+
202+
// These fields will not.
203+
boot_partitions: BootPartitionContents::debug_assume_success(),
204+
};
205+
206+
ret.debug_update_assume_success(config);
207+
208+
ret
209+
}
210+
211+
/// Given a sled config, update an existing reconciler result to simulate an
212+
/// output that sled-agent could have emitted if reconciliation succeeded.
213+
///
214+
/// This method should only be used by tests and dev tools; real code should
215+
/// look at the actual `last_reconciliation` value from the parent
216+
/// [`Inventory`].
217+
pub fn debug_update_assume_success(&mut self, config: OmicronSledConfig) {
193218
let external_disks = config
194219
.disks
195220
.iter()
@@ -212,50 +237,17 @@ impl ConfigReconcilerInventory {
212237
RemoveMupdateOverrideBootSuccessInventory::Removed,
213238
),
214239
non_boot_message: "mupdate override successfully removed \
215-
on non-boot disks"
240+
on non-boot disks"
216241
.to_owned(),
217242
}
218243
});
219244

220-
Self {
221-
last_reconciled_config: config,
222-
external_disks,
223-
datasets,
224-
orphaned_datasets: IdOrdMap::new(),
225-
zones,
226-
boot_partitions: {
227-
BootPartitionContents {
228-
boot_disk: Ok(M2Slot::A),
229-
slot_a: Ok(BootPartitionDetails {
230-
header: BootImageHeader {
231-
flags: 0,
232-
data_size: 1000,
233-
image_size: 1000,
234-
target_size: 1000,
235-
sha256: [0; 32],
236-
image_name: "fake from debug_assume_success()"
237-
.to_string(),
238-
},
239-
artifact_hash: ArtifactHash([0x0a; 32]),
240-
artifact_size: 1000,
241-
}),
242-
slot_b: Ok(BootPartitionDetails {
243-
header: BootImageHeader {
244-
flags: 0,
245-
data_size: 1000,
246-
image_size: 1000,
247-
target_size: 1000,
248-
sha256: [1; 32],
249-
image_name: "fake from debug_assume_success()"
250-
.to_string(),
251-
},
252-
artifact_hash: ArtifactHash([0x0b; 32]),
253-
artifact_size: 1000,
254-
}),
255-
}
256-
},
257-
remove_mupdate_override,
258-
}
245+
self.last_reconciled_config = config;
246+
self.external_disks = external_disks;
247+
self.datasets = datasets;
248+
self.orphaned_datasets = IdOrdMap::new();
249+
self.zones = zones;
250+
self.remove_mupdate_override = remove_mupdate_override;
259251
}
260252
}
261253

@@ -286,6 +278,36 @@ impl BootPartitionContents {
286278
M2Slot::B => &self.slot_b,
287279
}
288280
}
281+
282+
pub fn debug_assume_success() -> Self {
283+
Self {
284+
boot_disk: Ok(M2Slot::A),
285+
slot_a: Ok(BootPartitionDetails {
286+
header: BootImageHeader {
287+
flags: 0,
288+
data_size: 1000,
289+
image_size: 1000,
290+
target_size: 1000,
291+
sha256: [0; 32],
292+
image_name: "fake from debug_assume_success()".to_string(),
293+
},
294+
artifact_hash: ArtifactHash([0x0a; 32]),
295+
artifact_size: 1000,
296+
}),
297+
slot_b: Ok(BootPartitionDetails {
298+
header: BootImageHeader {
299+
flags: 0,
300+
data_size: 1000,
301+
image_size: 1000,
302+
target_size: 1000,
303+
sha256: [1; 32],
304+
image_name: "fake from debug_assume_success()".to_string(),
305+
},
306+
artifact_hash: ArtifactHash([0x0b; 32]),
307+
artifact_size: 1000,
308+
}),
309+
}
310+
}
289311
}
290312

291313
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, JsonSchema, Serialize)]

nexus/reconfigurator/planning/src/system.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,17 @@ impl SystemDescription {
461461
completed_at: Utc::now(),
462462
ran_for: Duration::from_secs(5),
463463
};
464-
sled.inventory_sled_agent.last_reconciliation =
465-
Some(ConfigReconcilerInventory::debug_assume_success(sled_config));
464+
match sled.inventory_sled_agent.last_reconciliation.as_mut() {
465+
Some(last_reconciliation) => {
466+
last_reconciliation.debug_update_assume_success(sled_config);
467+
}
468+
None => {
469+
sled.inventory_sled_agent.last_reconciliation =
470+
Some(ConfigReconcilerInventory::debug_assume_success(
471+
sled_config,
472+
));
473+
}
474+
};
466475

467476
Ok(self)
468477
}

0 commit comments

Comments
 (0)