Skip to content

Commit 6450196

Browse files
dianpopaalxiord
authored andcommitted
adjust tests to boot_source changes
Signed-off-by: Diana Popa <dpopa@amazon.com>
1 parent b710875 commit 6450196

File tree

4 files changed

+32
-26
lines changed

4 files changed

+32
-26
lines changed

src/vmm/src/resources.rs

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,9 @@ mod tests {
505505

506506
use super::*;
507507
use crate::resources::VmResources;
508-
use crate::vmm_config::boot_source::{BootConfig, BootSourceConfig, DEFAULT_KERNEL_CMDLINE};
508+
use crate::vmm_config::boot_source::{
509+
BootConfig, BootSource, BootSourceConfig, DEFAULT_KERNEL_CMDLINE,
510+
};
509511
use crate::vmm_config::drive::{BlockBuilder, BlockDeviceConfig, FileEngineType};
510512
use crate::vmm_config::machine_config::{CpuFeaturesTemplate, VmConfig, VmConfigError};
511513
use crate::vmm_config::net::{NetBuilder, NetworkInterfaceConfig};
@@ -562,22 +564,24 @@ mod tests {
562564
blocks
563565
}
564566

565-
fn default_boot_cfg() -> BootConfig {
567+
fn default_boot_cfg() -> BootSource {
566568
let mut kernel_cmdline = linux_loader::cmdline::Cmdline::new(4096);
567569
kernel_cmdline.insert_str(DEFAULT_KERNEL_CMDLINE).unwrap();
568570
let tmp_file = TempFile::new().unwrap();
569-
BootConfig {
570-
cmdline: kernel_cmdline,
571-
kernel_file: File::open(tmp_file.as_path()).unwrap(),
572-
initrd_file: Some(File::open(tmp_file.as_path()).unwrap()),
573-
description: Default::default(),
571+
BootSource {
572+
config: BootSourceConfig::default(),
573+
builder: Some(BootConfig {
574+
cmdline: kernel_cmdline,
575+
kernel_file: File::open(tmp_file.as_path()).unwrap(),
576+
initrd_file: Some(File::open(tmp_file.as_path()).unwrap()),
577+
}),
574578
}
575579
}
576580

577581
fn default_vm_resources() -> VmResources {
578582
VmResources {
579583
vm_config: VmConfig::default(),
580-
boot_config: Some(default_boot_cfg()),
584+
boot_source: default_boot_cfg(),
581585
block: default_blocks(),
582586
vsock: Default::default(),
583587
balloon: Default::default(),
@@ -1373,8 +1377,8 @@ mod tests {
13731377
#[test]
13741378
fn test_boot_config() {
13751379
let vm_resources = default_vm_resources();
1376-
let expected_boot_cfg = vm_resources.boot_config.as_ref().unwrap();
1377-
let actual_boot_cfg = vm_resources.boot_source().unwrap();
1380+
let expected_boot_cfg = vm_resources.boot_source.builder.as_ref().unwrap();
1381+
let actual_boot_cfg = vm_resources.boot_source_builder().unwrap();
13781382

13791383
assert!(actual_boot_cfg == expected_boot_cfg);
13801384
}
@@ -1390,13 +1394,16 @@ mod tests {
13901394
};
13911395

13921396
let mut vm_resources = default_vm_resources();
1393-
let boot_cfg = vm_resources.boot_source().unwrap();
1397+
let boot_builder = vm_resources.boot_source_builder().unwrap();
13941398
let tmp_ino = tmp_file.as_file().metadata().unwrap().st_ino();
13951399

1396-
assert_ne!(boot_cfg.cmdline.as_str(), cmdline);
1397-
assert_ne!(boot_cfg.kernel_file.metadata().unwrap().st_ino(), tmp_ino);
1400+
assert_ne!(boot_builder.cmdline.as_str(), cmdline);
13981401
assert_ne!(
1399-
boot_cfg
1402+
boot_builder.kernel_file.metadata().unwrap().st_ino(),
1403+
tmp_ino
1404+
);
1405+
assert_ne!(
1406+
boot_builder
14001407
.initrd_file
14011408
.as_ref()
14021409
.unwrap()
@@ -1406,12 +1413,15 @@ mod tests {
14061413
tmp_ino
14071414
);
14081415

1409-
vm_resources.set_boot_source(expected_boot_cfg).unwrap();
1410-
let boot_cfg = vm_resources.boot_source().unwrap();
1411-
assert_eq!(boot_cfg.cmdline.as_str(), cmdline);
1412-
assert_eq!(boot_cfg.kernel_file.metadata().unwrap().st_ino(), tmp_ino);
1416+
vm_resources.build_boot_source(expected_boot_cfg).unwrap();
1417+
let boot_source_builder = vm_resources.boot_source_builder().unwrap();
1418+
assert_eq!(boot_source_builder.cmdline.as_str(), cmdline);
1419+
assert_eq!(
1420+
boot_source_builder.kernel_file.metadata().unwrap().st_ino(),
1421+
tmp_ino
1422+
);
14131423
assert_eq!(
1414-
boot_cfg
1424+
boot_source_builder
14151425
.initrd_file
14161426
.as_ref()
14171427
.unwrap()

src/vmm/src/rpc_interface.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ mod tests {
925925
Ok(())
926926
}
927927

928-
pub fn set_boot_source(
928+
pub fn build_boot_source(
929929
&mut self,
930930
_: BootSourceConfig,
931931
) -> Result<(), BootSourceConfigError> {

src/vmm/src/utilities/mock_resources/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl MockVmResources {
7373
}
7474

7575
pub fn with_boot_source(mut self, boot_source_cfg: BootSourceConfig) -> Self {
76-
self.0.set_boot_source(boot_source_cfg).unwrap();
76+
self.0.build_boot_source(boot_source_cfg).unwrap();
7777
self
7878
}
7979

src/vmm/src/vmm_config/boot_source.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,8 @@ pub(crate) mod tests {
130130
kernel_image_path: kernel_path,
131131
};
132132

133-
let boot_cfg = BootConfig::new(boot_src_cfg.clone()).unwrap();
133+
let boot_cfg = BootConfig::new(&boot_src_cfg).unwrap();
134134
assert!(boot_cfg.initrd_file.is_none());
135135
assert_eq!(boot_cfg.cmdline.as_str(), DEFAULT_KERNEL_CMDLINE);
136-
assert_eq!(boot_cfg.description, boot_src_cfg);
137-
138-
let generated_cfg = BootSourceConfig::from(&boot_cfg);
139-
assert_eq!(generated_cfg, boot_src_cfg);
140136
}
141137
}

0 commit comments

Comments
 (0)