diff options
| author | Bruce Ashfield <bruce.ashfield@gmail.com> | 2026-01-06 02:45:48 +0000 |
|---|---|---|
| committer | Bruce Ashfield <bruce.ashfield@gmail.com> | 2026-02-09 03:32:52 +0000 |
| commit | 3a24b69b4edf4b04b2b2a13ee9575412b014068a (patch) | |
| tree | d8fd3b800f0f8d5ace651d0656c6bcd19e289212 | |
| parent | 2af9d5d88b48bc4e90b62af3c66ae674f33d1646 (diff) | |
| download | meta-virtualization-3a24b69b4edf4b04b2b2a13ee9575412b014068a.tar.gz | |
tests: fix has_image false positive from substring match
Change has_image() to use 'image inspect' instead of substring search
in 'images' output. The substring approach caused false positives when
images like 'nginx:alpine' were present - searching for 'alpine' would
match and skip pulling 'alpine:latest'.
This fixes TestSaveLoad::test_save_and_load which failed after the
port forwarding test introduced nginx:alpine.
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
| -rw-r--r-- | tests/conftest.py | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/tests/conftest.py b/tests/conftest.py index a9452410..b35f190c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py | |||
| @@ -381,10 +381,17 @@ class VdkrRunner: | |||
| 381 | return self.run("load", "-i", str(input_file), timeout=timeout) | 381 | return self.run("load", "-i", str(input_file), timeout=timeout) |
| 382 | 382 | ||
| 383 | def has_image(self, image_name): | 383 | def has_image(self, image_name): |
| 384 | """Check if an image exists.""" | 384 | """Check if an image exists. |
| 385 | |||
| 386 | Uses 'image inspect' for precise matching instead of substring | ||
| 387 | search in 'images' output, which can give false positives | ||
| 388 | (e.g., 'nginx:alpine' matching search for 'alpine'). | ||
| 389 | """ | ||
| 385 | self.ensure_memres() | 390 | self.ensure_memres() |
| 386 | result = self.images() | 391 | # Use image inspect for precise matching - returns 0 if image exists |
| 387 | return image_name.split(":")[0] in result.stdout | 392 | ref = image_name if ":" in image_name else f"{image_name}:latest" |
| 393 | result = self.run("image", "inspect", ref, check=False, capture_output=True) | ||
| 394 | return result.returncode == 0 | ||
| 388 | 395 | ||
| 389 | def ensure_alpine(self, timeout=300): | 396 | def ensure_alpine(self, timeout=300): |
| 390 | """Ensure alpine:latest is available, pulling if necessary.""" | 397 | """Ensure alpine:latest is available, pulling if necessary.""" |
| @@ -585,10 +592,17 @@ class VpdmnRunner: | |||
| 585 | return self.run("load", "-i", str(input_file), timeout=timeout) | 592 | return self.run("load", "-i", str(input_file), timeout=timeout) |
| 586 | 593 | ||
| 587 | def has_image(self, image_name): | 594 | def has_image(self, image_name): |
| 588 | """Check if an image exists.""" | 595 | """Check if an image exists. |
| 596 | |||
| 597 | Uses 'image inspect' for precise matching instead of substring | ||
| 598 | search in 'images' output, which can give false positives | ||
| 599 | (e.g., 'nginx:alpine' matching search for 'alpine'). | ||
| 600 | """ | ||
| 589 | self.ensure_memres() | 601 | self.ensure_memres() |
| 590 | result = self.images() | 602 | # Use image inspect for precise matching - returns 0 if image exists |
| 591 | return image_name.split(":")[0] in result.stdout | 603 | ref = image_name if ":" in image_name else f"{image_name}:latest" |
| 604 | result = self.run("image", "inspect", ref, check=False, capture_output=True) | ||
| 605 | return result.returncode == 0 | ||
| 592 | 606 | ||
| 593 | def ensure_alpine(self, timeout=300): | 607 | def ensure_alpine(self, timeout=300): |
| 594 | """Ensure alpine:latest is available, pulling if necessary.""" | 608 | """Ensure alpine:latest is available, pulling if necessary.""" |
