Skip to content

Commit 35a3c3e

Browse files
dianpopaacatangiu
authored andcommitted
vmm: unit test the PARTUUID functionality...
inside device_config/drive.rs. Signed-off-by: Diana Popa <[email protected]>
1 parent 57046df commit 35a3c3e

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

vmm/src/device_config/drive.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ mod tests {
281281
}
282282

283283
#[test]
284-
/// Test BlockDevicesConfigs::add when you first add the root device and then the other devices
284+
// Test BlockDevicesConfigs::add when you first add the root device and then the other devices.
285285
fn test_add_root_block_device_first() {
286286
let dummy_file_1 = NamedTempFile::new().unwrap();
287287
let dummy_path_1 = dummy_file_1.path().to_path_buf();
@@ -317,7 +317,6 @@ mod tests {
317317
};
318318

319319
let mut block_devices_configs = BlockDeviceConfigs::new();
320-
321320
assert!(block_devices_configs.add(root_block_device.clone()).is_ok());
322321
assert!(
323322
block_devices_configs
@@ -331,6 +330,7 @@ mod tests {
331330
);
332331

333332
assert_eq!(block_devices_configs.has_root_block_device(), true);
333+
assert_eq!(block_devices_configs.has_partuuid_root(), false);
334334
assert_eq!(block_devices_configs.config_list.len(), 3);
335335

336336
let mut block_dev_iter = block_devices_configs.config_list.iter();
@@ -340,12 +340,12 @@ mod tests {
340340
}
341341

342342
#[test]
343-
/// Test BlockDevicesConfigs::add when you add other devices first and then the root device
343+
// Test BlockDevicesConfigs::add when you add other devices first and then the root device.
344344
fn test_root_block_device_add_last() {
345345
let dummy_file_1 = NamedTempFile::new().unwrap();
346346
let dummy_path_1 = dummy_file_1.path().to_path_buf();
347347
let root_block_device = BlockDeviceConfig {
348-
path_on_host: dummy_path_1,
348+
path_on_host: dummy_path_1.clone(),
349349
is_root_device: true,
350350
partuuid: None,
351351
is_read_only: false,
@@ -389,6 +389,7 @@ mod tests {
389389
assert!(block_devices_configs.add(root_block_device.clone()).is_ok());
390390

391391
assert_eq!(block_devices_configs.has_root_block_device(), true);
392+
assert_eq!(block_devices_configs.has_partuuid_root(), false);
392393
assert_eq!(block_devices_configs.config_list.len(), 3);
393394

394395
let mut block_dev_iter = block_devices_configs.config_list.iter();
@@ -423,7 +424,7 @@ mod tests {
423424
let dummy_file_1 = NamedTempFile::new().unwrap();
424425
let dummy_path_1 = dummy_file_1.path().to_path_buf();
425426
let root_block_device = BlockDeviceConfig {
426-
path_on_host: dummy_path_1,
427+
path_on_host: dummy_path_1.clone(),
427428
is_root_device: true,
428429
partuuid: None,
429430
is_read_only: false,
@@ -463,8 +464,29 @@ mod tests {
463464
assert!(block_devices_configs.update(&dummy_block_device_2).is_err());
464465

465466
// Update with 2 root block devices
466-
dummy_block_device_2.path_on_host = dummy_path_2;
467+
dummy_block_device_2.path_on_host = dummy_path_2.clone();
467468
dummy_block_device_2.is_root_device = true;
468469
assert!(block_devices_configs.update(&dummy_block_device_2).is_err());
470+
471+
// Switch roots and add a PARTUUID for the new one .
472+
let root_block_device_old = BlockDeviceConfig {
473+
path_on_host: dummy_path_1,
474+
is_root_device: false,
475+
partuuid: None,
476+
is_read_only: false,
477+
drive_id: String::from("1"),
478+
rate_limiter: None,
479+
};
480+
let root_block_device_new = BlockDeviceConfig {
481+
path_on_host: dummy_path_2,
482+
is_root_device: true,
483+
partuuid: Some("0eaa91a0-01".to_string()),
484+
is_read_only: false,
485+
drive_id: String::from("2"),
486+
rate_limiter: None,
487+
};
488+
assert!(&block_devices_configs.update(&root_block_device_old).is_ok());
489+
assert!(&block_devices_configs.update(&root_block_device_new).is_ok());
490+
assert!(block_devices_configs.has_partuuid_root);
469491
}
470492
}

0 commit comments

Comments
 (0)