qcow2 SAL + rhai script to test functionality
This commit is contained in:
82
packages/system/virt/tests/rhai/04_qcow2_basic.rhai
Normal file
82
packages/system/virt/tests/rhai/04_qcow2_basic.rhai
Normal file
@@ -0,0 +1,82 @@
|
||||
// Basic tests for QCOW2 SAL (offline, will skip if qemu-img is not present)
|
||||
|
||||
print("=== QCOW2 Basic Tests ===");
|
||||
|
||||
// Dependency check
|
||||
let qemu = which("qemu-img");
|
||||
if qemu == () {
|
||||
print("⚠️ qemu-img not available - skipping QCOW2 tests");
|
||||
print("Install qemu-utils (Debian/Ubuntu) or QEMU tools for your distro.");
|
||||
print("=== QCOW2 Tests Skipped ===");
|
||||
exit();
|
||||
}
|
||||
|
||||
// Helper: unique temp path
|
||||
let now = 0;
|
||||
try {
|
||||
// if process module exists you could pull a timestamp; fallback to random-ish suffix
|
||||
now = 100000 + (rand() % 100000);
|
||||
} catch (err) {
|
||||
now = 100000 + (rand() % 100000);
|
||||
}
|
||||
let img_path = `/tmp/qcow2_test_${now}.img`;
|
||||
|
||||
print("\n--- Test 1: Create image ---");
|
||||
let create_res = qcow2_create(img_path, 1);
|
||||
if create_res.is_err() {
|
||||
print(`❌ Create failed: ${create_res.unwrap_err()}`);
|
||||
exit();
|
||||
}
|
||||
print(`✓ Created qcow2: ${img_path}`);
|
||||
|
||||
print("\n--- Test 2: Info ---");
|
||||
let info_res = qcow2_info(img_path);
|
||||
if info_res.is_err() {
|
||||
print(`❌ Info failed: ${info_res.unwrap_err()}`);
|
||||
exit();
|
||||
}
|
||||
let info = info_res.unwrap();
|
||||
print("✓ Info fetched");
|
||||
if info.format != () { print(` format: ${info.format}`); }
|
||||
if info["virtual-size"] != () { print(` virtual-size: ${info["virtual-size"]}`); }
|
||||
|
||||
print("\n--- Test 3: Snapshot create/list/delete (offline) ---");
|
||||
let snap_name = "s1";
|
||||
let screate = qcow2_snapshot_create(img_path, snap_name);
|
||||
if screate.is_err() {
|
||||
print(`❌ snapshot_create failed: ${screate.unwrap_err()}`);
|
||||
exit();
|
||||
}
|
||||
print("✓ snapshot created: s1");
|
||||
|
||||
let slist = qcow2_snapshot_list(img_path);
|
||||
if slist.is_err() {
|
||||
print(`❌ snapshot_list failed: ${slist.unwrap_err()}`);
|
||||
exit();
|
||||
}
|
||||
let snaps = slist.unwrap();
|
||||
print(`✓ snapshot_list ok, count=${snaps.len()}`);
|
||||
|
||||
let sdel = qcow2_snapshot_delete(img_path, snap_name);
|
||||
if sdel.is_err() {
|
||||
print(`❌ snapshot_delete failed: ${sdel.unwrap_err()}`);
|
||||
exit();
|
||||
}
|
||||
print("✓ snapshot deleted: s1");
|
||||
|
||||
// Optional: Base image builder (commented to avoid big downloads by default)
|
||||
// Uncomment to test manually on a dev machine with bandwidth.
|
||||
// print("\n--- Optional: Build Ubuntu 24.04 Base ---");
|
||||
// let base_dir = "/tmp/virt_images";
|
||||
// let base = qcow2_build_ubuntu_24_04_base(base_dir, 10);
|
||||
// if base.is_err() {
|
||||
// print(`⚠️ base build failed or skipped: ${base.unwrap_err()}`);
|
||||
// } else {
|
||||
// let m = base.unwrap();
|
||||
// print(`✓ Base image path: ${m.base_image_path}`);
|
||||
// print(`✓ Base snapshot: ${m.snapshot}`);
|
||||
// print(`✓ Source URL: ${m.url}`);
|
||||
// if m.resized_to_gb != () { print(`✓ Resized to: ${m.resized_to_gb}G`); }
|
||||
// }
|
||||
|
||||
print("\n=== QCOW2 Basic Tests Completed ===");
|
Reference in New Issue
Block a user