|
9 | 9 |
|
10 | 10 | use std::process::Command;
|
11 | 11 |
|
12 |
| -use crate::{get_bck_command, get_test_image}; |
| 12 | +use crate::{get_bck_command, get_test_image, LIBVIRT_INTEGRATION_TEST_LABEL}; |
13 | 13 |
|
14 | 14 | /// Test libvirt list functionality (lists domains)
|
15 | 15 | pub fn test_libvirt_list_functionality() {
|
@@ -224,6 +224,8 @@ pub fn test_libvirt_run_ssh_full_workflow() {
|
224 | 224 | "run",
|
225 | 225 | "--name",
|
226 | 226 | &domain_name,
|
| 227 | + "--label", |
| 228 | + LIBVIRT_INTEGRATION_TEST_LABEL, |
227 | 229 | "--filesystem",
|
228 | 230 | "ext4",
|
229 | 231 | &test_image,
|
@@ -416,6 +418,8 @@ pub fn test_libvirt_vm_lifecycle() {
|
416 | 418 | "ext4",
|
417 | 419 | "--name",
|
418 | 420 | &domain_name,
|
| 421 | + "--label", |
| 422 | + INTEGRATION_TEST_LABEL, |
419 | 423 | test_image,
|
420 | 424 | ])
|
421 | 425 | .output()
|
@@ -526,6 +530,8 @@ pub fn test_libvirt_bind_storage_ro() {
|
526 | 530 | "run",
|
527 | 531 | "--name",
|
528 | 532 | &domain_name,
|
| 533 | + "--label", |
| 534 | + INTEGRATION_TEST_LABEL, |
529 | 535 | "--bind-storage-ro",
|
530 | 536 | "--filesystem",
|
531 | 537 | "ext4",
|
@@ -699,6 +705,144 @@ pub fn test_libvirt_bind_storage_ro() {
|
699 | 705 | println!("✓ --bind-storage-ro end-to-end test passed");
|
700 | 706 | }
|
701 | 707 |
|
| 708 | +/// Test libvirt label functionality |
| 709 | +pub fn test_libvirt_label_functionality() { |
| 710 | + let bck = get_bck_command().unwrap(); |
| 711 | + let test_image = get_test_image(); |
| 712 | + |
| 713 | + // Generate unique domain name for this test |
| 714 | + let domain_name = format!( |
| 715 | + "test-label-{}", |
| 716 | + std::time::SystemTime::now() |
| 717 | + .duration_since(std::time::UNIX_EPOCH) |
| 718 | + .unwrap() |
| 719 | + .as_secs() |
| 720 | + ); |
| 721 | + |
| 722 | + println!( |
| 723 | + "Testing libvirt label functionality with domain: {}", |
| 724 | + domain_name |
| 725 | + ); |
| 726 | + |
| 727 | + // Cleanup any existing domain with this name |
| 728 | + let _ = Command::new("virsh") |
| 729 | + .args(&["destroy", &domain_name]) |
| 730 | + .output(); |
| 731 | + let _ = Command::new(&bck) |
| 732 | + .args(&["libvirt", "rm", &domain_name, "--force", "--stop"]) |
| 733 | + .output(); |
| 734 | + |
| 735 | + // Create domain with multiple labels |
| 736 | + println!("Creating libvirt domain with multiple labels..."); |
| 737 | + let create_output = Command::new("timeout") |
| 738 | + .args([ |
| 739 | + "300s", |
| 740 | + &bck, |
| 741 | + "libvirt", |
| 742 | + "run", |
| 743 | + "--name", |
| 744 | + &domain_name, |
| 745 | + "--label", |
| 746 | + INTEGRATION_TEST_LABEL, |
| 747 | + "--label", |
| 748 | + "test-env", |
| 749 | + "--label", |
| 750 | + "temporary", |
| 751 | + "--filesystem", |
| 752 | + "ext4", |
| 753 | + &test_image, |
| 754 | + ]) |
| 755 | + .output() |
| 756 | + .expect("Failed to run libvirt run with labels"); |
| 757 | + |
| 758 | + let create_stdout = String::from_utf8_lossy(&create_output.stdout); |
| 759 | + let create_stderr = String::from_utf8_lossy(&create_output.stderr); |
| 760 | + |
| 761 | + println!("Create stdout: {}", create_stdout); |
| 762 | + println!("Create stderr: {}", create_stderr); |
| 763 | + |
| 764 | + if !create_output.status.success() { |
| 765 | + cleanup_domain(&domain_name); |
| 766 | + panic!("Failed to create domain with labels: {}", create_stderr); |
| 767 | + } |
| 768 | + |
| 769 | + println!("Successfully created domain with labels: {}", domain_name); |
| 770 | + |
| 771 | + // Verify labels are stored in domain XML |
| 772 | + println!("Checking domain XML for labels..."); |
| 773 | + let dumpxml_output = Command::new("virsh") |
| 774 | + .args(&["dumpxml", &domain_name]) |
| 775 | + .output() |
| 776 | + .expect("Failed to dump domain XML"); |
| 777 | + |
| 778 | + let domain_xml = String::from_utf8_lossy(&dumpxml_output.stdout); |
| 779 | + |
| 780 | + // Check that labels are in the XML |
| 781 | + assert!( |
| 782 | + domain_xml.contains("bootc:label") || domain_xml.contains("<label>"), |
| 783 | + "Domain XML should contain label metadata" |
| 784 | + ); |
| 785 | + assert!( |
| 786 | + domain_xml.contains(LIBVIRT_INTEGRATION_TEST_LABEL), |
| 787 | + "Domain XML should contain bcvk-integration label" |
| 788 | + ); |
| 789 | + |
| 790 | + // Test filtering by label |
| 791 | + println!("Testing label filtering with libvirt list..."); |
| 792 | + let list_output = Command::new(&bck) |
| 793 | + .args([ |
| 794 | + "libvirt", |
| 795 | + "list", |
| 796 | + "--label", |
| 797 | + LIBVIRT_INTEGRATION_TEST_LABEL, |
| 798 | + "-a", |
| 799 | + ]) |
| 800 | + .output() |
| 801 | + .expect("Failed to run libvirt list with label filter"); |
| 802 | + |
| 803 | + let list_stdout = String::from_utf8_lossy(&list_output.stdout); |
| 804 | + println!("List output: {}", list_stdout); |
| 805 | + |
| 806 | + assert!( |
| 807 | + list_output.status.success(), |
| 808 | + "libvirt list with label filter should succeed" |
| 809 | + ); |
| 810 | + assert!( |
| 811 | + list_stdout.contains(&domain_name), |
| 812 | + "Domain should appear in filtered list. Output: {}", |
| 813 | + list_stdout |
| 814 | + ); |
| 815 | + |
| 816 | + // Test filtering by a label that should match |
| 817 | + let list_test_env = Command::new(&bck) |
| 818 | + .args(["libvirt", "list", "--label", "test-env", "-a"]) |
| 819 | + .output() |
| 820 | + .expect("Failed to run libvirt list with test-env label"); |
| 821 | + |
| 822 | + let list_test_env_stdout = String::from_utf8_lossy(&list_test_env.stdout); |
| 823 | + assert!( |
| 824 | + list_test_env_stdout.contains(&domain_name), |
| 825 | + "Domain should appear when filtering by test-env label" |
| 826 | + ); |
| 827 | + |
| 828 | + // Test filtering by a label that should NOT match |
| 829 | + let list_nomatch = Command::new(&bck) |
| 830 | + .args(["libvirt", "list", "--label", "nonexistent-label", "-a"]) |
| 831 | + .output() |
| 832 | + .expect("Failed to run libvirt list with nonexistent label"); |
| 833 | + |
| 834 | + let list_nomatch_stdout = String::from_utf8_lossy(&list_nomatch.stdout); |
| 835 | + assert!( |
| 836 | + !list_nomatch_stdout.contains(&domain_name), |
| 837 | + "Domain should NOT appear when filtering by nonexistent label" |
| 838 | + ); |
| 839 | + |
| 840 | + // Cleanup domain |
| 841 | + cleanup_domain(&domain_name); |
| 842 | + |
| 843 | + println!("✓ Label functionality test passed"); |
| 844 | +} |
| 845 | + |
702 | 846 | /// Test error handling for invalid configurations
|
703 | 847 | pub fn test_libvirt_error_handling() {
|
704 | 848 | let bck = get_bck_command().unwrap();
|
|
0 commit comments