-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5669 from clebergnu/functional_distro_test
Signed-off-by: Jan Richter <[email protected]>
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import os | ||
|
||
from avocado import Test | ||
from avocado.core.exit_codes import AVOCADO_ALL_OK | ||
from avocado.core.job import Job | ||
from avocado.core.nrunner.runnable import Runnable | ||
from avocado.core.suite import TestSuite | ||
|
||
|
||
class Distro(Test): | ||
"""Tests distro detection in containers | ||
:avocado: dependency={"type": "package", "name": "podman", "action": "check"} | ||
""" | ||
|
||
def run_job(self, podman_image, output): | ||
"""Runs an Avocado job on a container, returning the stdout of the one | ||
and only runnable executed (equivalent to an "avocado distro" command). | ||
""" | ||
config = { | ||
"run.spawner": "podman", | ||
"spawner.podman.image": podman_image, | ||
"run.results_dir": self.workdir, | ||
} | ||
runnable = Runnable("exec-test", "python3", "-m", "avocado", "distro") | ||
suite = TestSuite("1", config, tests=[runnable]) | ||
with Job(config, test_suites=[suite]) as job: | ||
result = job.run() | ||
self.assertEqual(result, AVOCADO_ALL_OK, "Job execution failed") | ||
|
||
stdout_path = os.path.join(job.test_results_path, "1-1-python3", "stdout") | ||
with open(stdout_path, "rb") as stdout: | ||
self.assertEqual(stdout.read(), output) | ||
|
||
def test_fedora_36(self): | ||
""" | ||
:avocado: dependency={"type": "podman-image", "uri": "registry.fedoraproject.org/fedora:36"} | ||
""" | ||
self.run_job( | ||
"registry.fedoraproject.org/fedora:36", | ||
b"Detected distribution: fedora (" | ||
+ os.uname().machine.encode() | ||
+ b") version 36 release 0\n", | ||
) | ||
|
||
def test_rhel_9_1(self): | ||
""" | ||
:avocado: dependency={"type": "podman-image", "uri": "registry.access.redhat.com/ubi9:9.1"} | ||
""" | ||
self.run_job( | ||
"registry.access.redhat.com/ubi9:9.1", | ||
b"Detected distribution: rhel (" | ||
+ os.uname().machine.encode() | ||
+ b") version 9 release 1\n", | ||
) |