Skip to content

Commit a8fe10f

Browse files
committed
Add test cases for AttachNic and RemoveNic
Signed-off-by: Guvenc Gulce <[email protected]>
1 parent 9418454 commit a8fe10f

File tree

1 file changed

+66
-5
lines changed

1 file changed

+66
-5
lines changed

feos/tests/integration_tests.rs

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ use feos_proto::{
1212
ListImagesRequest, PullImageRequest, WatchImageStatusRequest,
1313
},
1414
vm_service::{
15-
stream_vm_console_request as console_input, vm_service_client::VmServiceClient,
16-
AttachConsoleMessage, CpuConfig, CreateVmRequest, DeleteVmRequest, GetVmRequest,
17-
MemoryConfig, PauseVmRequest, PingVmRequest, ResumeVmRequest, ShutdownVmRequest,
18-
StartVmRequest, StreamVmConsoleRequest, StreamVmEventsRequest, VmConfig, VmEvent, VmState,
19-
VmStateChangedEvent,
15+
net_config, stream_vm_console_request as console_input, vm_service_client::VmServiceClient,
16+
AttachConsoleMessage, AttachNicRequest, CpuConfig, CreateVmRequest, DeleteVmRequest,
17+
GetVmRequest, MemoryConfig, NetConfig, PauseVmRequest, PingVmRequest, RemoveNicRequest,
18+
ResumeVmRequest, ShutdownVmRequest, StartVmRequest, StreamVmConsoleRequest,
19+
StreamVmEventsRequest, TapConfig, VmConfig, VmEvent, VmState, VmStateChangedEvent,
2020
},
2121
};
2222
use hyper_util::rt::TokioIo;
@@ -405,6 +405,67 @@ async fn test_create_and_start_vm() -> Result<()> {
405405
info!("VMM Ping successful, PID: {}", ping_res.pid);
406406
guard.pid = Some(Pid::from_raw(ping_res.pid as i32));
407407

408+
info!("Attaching NIC 'test-nic' to vm_id: {}", &vm_id);
409+
let attach_nic_req = AttachNicRequest {
410+
vm_id: vm_id.clone(),
411+
nic: Some(NetConfig {
412+
device_id: "test".to_string(),
413+
backend: Some(net_config::Backend::Tap(TapConfig {
414+
tap_name: "test".to_string(),
415+
})),
416+
..Default::default()
417+
}),
418+
};
419+
let attach_res = vm_client.attach_nic(attach_nic_req).await?.into_inner();
420+
assert_eq!(attach_res.device_id, "test");
421+
info!(
422+
"AttachNic call successful, device_id: {}",
423+
attach_res.device_id
424+
);
425+
426+
tokio::time::sleep(Duration::from_millis(100)).await;
427+
428+
info!("Verifying NIC was attached with GetVm");
429+
let get_req_after_attach = GetVmRequest {
430+
vm_id: vm_id.clone(),
431+
};
432+
let info_res_after_attach = vm_client.get_vm(get_req_after_attach).await?.into_inner();
433+
let nic_found = info_res_after_attach
434+
.config
435+
.expect("VM should have a config")
436+
.net
437+
.iter()
438+
.any(|nic| nic.device_id == "test");
439+
assert!(nic_found, "Attached NIC 'test' was not found in VM config");
440+
info!("Successfully verified NIC attachment.");
441+
442+
info!("Removing NIC 'test' from vm_id: {}", &vm_id);
443+
let remove_nic_req = RemoveNicRequest {
444+
vm_id: vm_id.clone(),
445+
device_id: "test".to_string(),
446+
};
447+
vm_client.remove_nic(remove_nic_req).await?;
448+
info!("RemoveNic call successful");
449+
450+
tokio::time::sleep(Duration::from_millis(100)).await;
451+
452+
info!("Verifying NIC was removed with GetVm");
453+
let get_req_after_remove = GetVmRequest {
454+
vm_id: vm_id.clone(),
455+
};
456+
let info_res_after_remove = vm_client.get_vm(get_req_after_remove).await?.into_inner();
457+
let nic_still_present = info_res_after_remove
458+
.config
459+
.expect("VM should have a config")
460+
.net
461+
.iter()
462+
.any(|nic| nic.device_id == "test");
463+
assert!(
464+
!nic_still_present,
465+
"Removed NIC 'test' was still found in VM config"
466+
);
467+
info!("Successfully verified NIC removal.");
468+
408469
info!("Deleting VM: {}", &vm_id);
409470
let delete_req = DeleteVmRequest {
410471
vm_id: vm_id.clone(),

0 commit comments

Comments
 (0)