diff options
| author | Bruce Ashfield <bruce.ashfield@gmail.com> | 2026-06-04 22:10:36 +0000 |
|---|---|---|
| committer | Bruce Ashfield <bruce.ashfield@gmail.com> | 2026-06-12 02:58:55 +0000 |
| commit | 5e958db73270a60c6ac04b19aec8f66b6ba474e2 (patch) | |
| tree | 77269c4f65ed478efaefddb1bc6dcb7c3d770e7f | |
| parent | dfb2c9a331e841faf3cae040439519ecf85a84a1 (diff) | |
| download | meta-virtualization-5e958db73270a60c6ac04b19aec8f66b6ba474e2.tar.gz | |
tests: fix image ID parsing and 9p assertion patterns
test_vdkr_registry.py: Docker's images output changed from separate
REPOSITORY TAG IMAGE_ID columns to combined IMAGE ID DISK_USAGE
columns. The parser grabbed the disk usage (8.45MB) as the image ID.
Handle both old and new formats.
test_container_registry_script.py: The secure registry tests checked
for literal 'virtfs' and 'cashare' strings in vrunner.sh, but the
9p share setup was refactored to use hv_build_9p_opts(). Update
assertions to match the current abstraction.
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
| -rw-r--r-- | tests/test_container_registry_script.py | 28 | ||||
| -rw-r--r-- | tests/test_vdkr_registry.py | 19 |
2 files changed, 25 insertions, 22 deletions
diff --git a/tests/test_container_registry_script.py b/tests/test_container_registry_script.py index 3089e870..18efb851 100644 --- a/tests/test_container_registry_script.py +++ b/tests/test_container_registry_script.py | |||
| @@ -1497,7 +1497,7 @@ class TestVcontainerSecureRegistry: | |||
| 1497 | "Should not base64 encode CA cert for kernel cmdline" | 1497 | "Should not base64 encode CA cert for kernel cmdline" |
| 1498 | 1498 | ||
| 1499 | def test_vrunner_daemon_sets_9p(self): | 1499 | def test_vrunner_daemon_sets_9p(self): |
| 1500 | """Test that daemon mode sets _9p=1 in kernel cmdline.""" | 1500 | """Test that daemon mode sets up virtio-9p share and _9p=1.""" |
| 1501 | script = Path("/opt/bruce/poky/meta-virtualization/recipes-containers/" | 1501 | script = Path("/opt/bruce/poky/meta-virtualization/recipes-containers/" |
| 1502 | "vcontainer/files/vrunner.sh") | 1502 | "vcontainer/files/vrunner.sh") |
| 1503 | if not script.exists(): | 1503 | if not script.exists(): |
| @@ -1505,26 +1505,24 @@ class TestVcontainerSecureRegistry: | |||
| 1505 | 1505 | ||
| 1506 | content = script.read_text() | 1506 | content = script.read_text() |
| 1507 | 1507 | ||
| 1508 | # Find the daemon mode block and check for _9p=1 | 1508 | # Find the daemon mode block and check for 9p setup |
| 1509 | # The daemon block should contain both virtfs and _9p=1 | ||
| 1510 | lines = content.split('\n') | 1509 | lines = content.split('\n') |
| 1511 | in_daemon_block = False | 1510 | in_daemon_block = False |
| 1512 | daemon_has_virtfs = False | 1511 | daemon_has_9p_opts = False |
| 1513 | daemon_has_9p = False | 1512 | daemon_has_9p_flag = False |
| 1514 | for line in lines: | 1513 | for line in lines: |
| 1515 | if 'DAEMON_MODE" = "start"' in line or "DAEMON_MODE\" = \"start\"" in line: | 1514 | if 'DAEMON_MODE" = "start"' in line or 'DAEMON_MODE = "start"' in line: |
| 1516 | in_daemon_block = True | 1515 | in_daemon_block = True |
| 1517 | if in_daemon_block: | 1516 | if in_daemon_block: |
| 1518 | if "virtfs" in line and "DAEMON_SHARE_DIR" in line: | 1517 | if "hv_build_9p_opts" in line and "DAEMON_SHARE_DIR" in line: |
| 1519 | daemon_has_virtfs = True | 1518 | daemon_has_9p_opts = True |
| 1520 | if "_9p=1" in line: | 1519 | if "_9p=1" in line: |
| 1521 | daemon_has_9p = True | 1520 | daemon_has_9p_flag = True |
| 1522 | # Detect end of the if block (next top-level statement) | 1521 | if line.startswith("fi") and in_daemon_block and daemon_has_9p_opts: |
| 1523 | if line.startswith("fi") and in_daemon_block and daemon_has_virtfs: | ||
| 1524 | break | 1522 | break |
| 1525 | 1523 | ||
| 1526 | assert daemon_has_virtfs, "Daemon mode should set up virtio-9p share" | 1524 | assert daemon_has_9p_opts, "Daemon mode should set up virtio-9p share via hv_build_9p_opts" |
| 1527 | assert daemon_has_9p, "Daemon mode should set _9p=1 in kernel cmdline" | 1525 | assert daemon_has_9p_flag, "Daemon mode should set _9p=1 in kernel cmdline" |
| 1528 | 1526 | ||
| 1529 | def test_vrunner_nondaemon_ca_cert_virtio9p(self): | 1527 | def test_vrunner_nondaemon_ca_cert_virtio9p(self): |
| 1530 | """Test that non-daemon mode creates virtio-9p share for CA cert.""" | 1528 | """Test that non-daemon mode creates virtio-9p share for CA cert.""" |
| @@ -1536,8 +1534,8 @@ class TestVcontainerSecureRegistry: | |||
| 1536 | content = script.read_text() | 1534 | content = script.read_text() |
| 1537 | assert "CA_SHARE_DIR" in content, \ | 1535 | assert "CA_SHARE_DIR" in content, \ |
| 1538 | "Non-daemon mode should create CA_SHARE_DIR for virtio-9p" | 1536 | "Non-daemon mode should create CA_SHARE_DIR for virtio-9p" |
| 1539 | assert "cashare" in content, \ | 1537 | assert "hv_build_9p_opts" in content and "CA_SHARE_DIR" in content, \ |
| 1540 | "Should add virtio-9p device for CA cert sharing" | 1538 | "Should set up virtio-9p device for CA cert sharing via hv_build_9p_opts" |
| 1541 | 1539 | ||
| 1542 | def test_vdkr_init_reads_ca_from_share(self): | 1540 | def test_vdkr_init_reads_ca_from_share(self): |
| 1543 | """Test that vdkr-init.sh reads CA cert from /mnt/share/ca.crt.""" | 1541 | """Test that vdkr-init.sh reads CA cert from /mnt/share/ca.crt.""" |
diff --git a/tests/test_vdkr_registry.py b/tests/test_vdkr_registry.py index 72a27169..e429f6ab 100644 --- a/tests/test_vdkr_registry.py +++ b/tests/test_vdkr_registry.py | |||
| @@ -112,15 +112,20 @@ class TestImageCompoundCommands: | |||
| 112 | return None, None | 112 | return None, None |
| 113 | 113 | ||
| 114 | # Parse the images output to find alpine | 114 | # Parse the images output to find alpine |
| 115 | # Docker output format varies by version: | ||
| 116 | # Old: REPOSITORY TAG IMAGE ID CREATED SIZE | ||
| 117 | # New: IMAGE ID DISK USAGE CONTENT SIZE EXTRA | ||
| 115 | for line in images_result.stdout.splitlines(): | 118 | for line in images_result.stdout.splitlines(): |
| 116 | if "alpine" in line.lower() and "REPOSITORY" not in line: | 119 | if "alpine" in line.lower() and "REPOSITORY" not in line and "IMAGE" not in line: |
| 117 | # Parse: REPOSITORY TAG IMAGE_ID CREATED SIZE | ||
| 118 | parts = line.split() | 120 | parts = line.split() |
| 119 | if len(parts) >= 3: | 121 | if len(parts) >= 2: |
| 120 | repo = parts[0] | 122 | image_ref = parts[0] |
| 121 | tag = parts[1] | 123 | image_id = parts[1] |
| 122 | image_id = parts[2] | 124 | # Old format: repo and tag are separate columns |
| 123 | return f"{repo}:{tag}", image_id | 125 | if ':' not in image_ref and len(parts) >= 3: |
| 126 | image_ref = f"{parts[0]}:{parts[1]}" | ||
| 127 | image_id = parts[2] | ||
| 128 | return image_ref, image_id | ||
| 124 | return None, None | 129 | return None, None |
| 125 | 130 | ||
| 126 | def test_image_ls(self): | 131 | def test_image_ls(self): |
