Skip to content

Commit 7720200

Browse files
committed
phd: better method for referencing a disk from a VmSpec
1 parent f2d57bf commit 7720200

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

phd-tests/framework/src/test_vm/spec.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ pub struct VmSpec {
3434
}
3535

3636
impl VmSpec {
37-
/// Yields an array of handles to this VM's Crucible disks.
38-
pub fn get_crucible_disks(&self) -> Vec<Arc<dyn disk::DiskConfig>> {
37+
pub fn get_disk_by_device_name(
38+
&self,
39+
name: &str,
40+
) -> Option<&Arc<dyn disk::DiskConfig>> {
3941
self.disk_handles
4042
.iter()
41-
.filter(|d| d.as_crucible().is_some())
42-
.cloned()
43-
.collect()
43+
.find(|disk| disk.device_name().as_str() == name)
4444
}
4545

4646
/// Update the Crucible backend specs in the instance spec to match the

phd-tests/tests/src/crucible/smoke.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ async fn vcr_replace_test(ctx: &Framework) {
9595
// necessary because Crucible doesn't permit VCR replacements for volumes
9696
// whose read-only parents are local files (which is true for artifact-based
9797
// Crucible disks).
98+
const DATA_DISK_NAME: &str = "vcr-replacement-target";
9899
config.data_disk(
99-
"vcr-replacement-target",
100+
DATA_DISK_NAME,
100101
DiskSource::Blank(1024 * 1024 * 1024),
101102
DiskInterface::Nvme,
102103
DiskBackend::Crucible {
@@ -107,8 +108,9 @@ async fn vcr_replace_test(ctx: &Framework) {
107108
);
108109

109110
let spec = config.vm_spec(ctx).await?;
110-
let disks = spec.get_crucible_disks();
111-
let disk = disks[0].as_crucible().unwrap();
111+
let disk_hdl =
112+
spec.get_disk_by_device_name(DATA_DISK_NAME).cloned().unwrap();
113+
let disk = disk_hdl.as_crucible().unwrap();
112114

113115
let mut vm = ctx.spawn_vm_with_spec(spec, None).await?;
114116
vm.launch().await?;

0 commit comments

Comments
 (0)