Skip to content

Commit

Permalink
Merge pull request #5669 from clebergnu/functional_distro_test
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Richter <[email protected]>
  • Loading branch information
richtja authored Apr 28, 2023
2 parents 729b2fe + c2ec624 commit d2d9a61
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions selftests/functional/utils/distro.py
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",
)

0 comments on commit d2d9a61

Please sign in to comment.