Skip to content

Commit eda99fc

Browse files
committed
fix E0063 errors
1 parent dd04881 commit eda99fc

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

src/api/routes.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ use crate::core::vm::{VMStatus, VMConfig};
7979
use crate::gpu::device::{GPUManager, GPUDevice, GPUConfig};
8080
use crate::monitoring::metrics::{MetricsCollector, ResourceMetrics};
8181
use crate::api::middleware::rate_limit::{rate_limit_layer, GlobalRateLimit, RateLimitExceeded};
82-
use crate::utils::os::{current_platform};
82+
use crate::utils::os::current_platform;
8383

8484
fn handle_error(err: impl std::fmt::Display) -> StatusCode {
8585
error!("Operation failed: {}", err);
@@ -102,6 +102,8 @@ pub struct CreateVMRequest {
102102
pub memory_mb: u64,
103103
pub gpu_required: bool,
104104
pub disk_size_gb: Option<u64>,
105+
#[serde(skip_serializing_if = "Option::is_none")]
106+
pub gpu_passthrough: Option<String>,
105107
// pub username: String,
106108
// pub password: String,
107109
}
@@ -199,6 +201,7 @@ async fn create_vm(
199201
vcpus: params.cpu_cores,
200202
disk_path: PathBuf::from(format!("/var/lib/gpu-share/images/{}.qcow2", params.name)),
201203
disk_size_gb: params.disk_size_gb.unwrap_or(20),
204+
gpu_passthrough: params.gpu_passthrough.clone(),
202205
};
203206

204207
#[cfg(target_os = "linux")]

tests/live_tests.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ async fn test_real_vm_creation() -> anyhow::Result<()> {
3636
vcpus: 2, // Dual-core power! ⚡
3737
disk_path: PathBuf::from("/var/lib/gpu-share/images/test-vm-1.qcow2"),
3838
disk_size_gb: 20, // Room for activities!
39+
gpu_passthrough: None,
3940
};
4041

4142
// Create and verify our new digital pet 🐕
@@ -78,6 +79,10 @@ async fn test_real_gpu_passthrough() -> anyhow::Result<()> {
7879
vcpus: 4, // Quad-core power for our GPU overlord!
7980
disk_path: PathBuf::from("/var/lib/gpu-share/images/test-gpu-vm.qcow2"),
8081
disk_size_gb: 40, // Extra space for those GPU drivers! 📦
82+
gpu_passthrough: Some(GPUConfig {
83+
gpu_id: test_gpu.id.clone(),
84+
iommu_group: "0".to_string(), // Default group for testing
85+
}),
8186
};
8287

8388
let vm = libvirt.create_vm(&config).await?;
@@ -119,6 +124,7 @@ async fn test_real_metrics_collection() -> anyhow::Result<()> {
119124
vcpus: 2,
120125
disk_path: PathBuf::from("/var/lib/gpu-share/images/test-metrics.qcow2"),
121126
disk_size_gb: 20,
127+
gpu_passthrough: None,
122128
};
123129

124130
let vm = libvirt.create_vm(&config).await?;
@@ -255,6 +261,7 @@ async fn test_cross_platform_vm_operations() -> anyhow::Result<()> {
255261
vcpus: 2,
256262
disk_path: PathBuf::from("/var/lib/gpu-share/images/cross-platform-test.qcow2"),
257263
disk_size_gb: 20,
264+
gpu_passthrough: None,
258265
};
259266

260267
// Basic VM operations
@@ -276,4 +283,52 @@ async fn test_cross_platform_vm_operations() -> anyhow::Result<()> {
276283
vm.destroy()?;
277284
vm.undefine()?;
278285
Ok(())
286+
}
287+
288+
// Test 1: Basic VM Creation
289+
async fn create_basic_vm() -> VMConfig {
290+
VMConfig {
291+
name: "test-vm-basic".into(),
292+
memory_kb: 2048 * 1024,
293+
vcpus: 2,
294+
disk_path: PathBuf::from("/var/lib/libvirt/images/test-vm-basic.qcow2"),
295+
disk_size_gb: 20,
296+
gpu_passthrough: None,
297+
}
298+
}
299+
300+
// Test 2: GPU Passthrough Test
301+
async fn create_gpu_vm() -> VMConfig {
302+
VMConfig {
303+
name: "test-vm-gpu".into(),
304+
memory_kb: 4096 * 1024,
305+
vcpus: 4,
306+
disk_path: PathBuf::from("/var/lib/libvirt/images/test-vm-gpu.qcow2"),
307+
disk_size_gb: 40,
308+
gpu_passthrough: Some("0000:01:00.0".into()),
309+
}
310+
}
311+
312+
// Test 3: Big Scale VM
313+
async fn create_large_vm() -> VMConfig {
314+
VMConfig {
315+
name: "test-vm-large".into(),
316+
memory_kb: 16384 * 1024,
317+
vcpus: 8,
318+
disk_path: PathBuf::from("/var/lib/libvirt/images/test-vm-large.qcow2"),
319+
disk_size_gb: 100,
320+
gpu_passthrough: None,
321+
}
322+
}
323+
324+
// Test 4: Edge Case - Minimum Resources
325+
async fn create_minimal_vm() -> VMConfig {
326+
VMConfig {
327+
name: "test-vm-minimal".into(),
328+
memory_kb: 512 * 1024,
329+
vcpus: 1,
330+
disk_path: PathBuf::from("/var/lib/libvirt/images/test-vm-minimal.qcow2"),
331+
disk_size_gb: 10,
332+
gpu_passthrough: None,
333+
}
279334
}

0 commit comments

Comments
 (0)