[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 08/23] avocado_qemu: Fix KNOWN_DISTROS map into the LinuxDistro cl
From: |
Cleber Rosa |
Subject: |
[PULL 08/23] avocado_qemu: Fix KNOWN_DISTROS map into the LinuxDistro class |
Date: |
Tue, 13 Jul 2021 17:19:08 -0400 |
From: Willian Rampazzo <willianr@redhat.com>
As the KNOWN_DISTROS grows, more loosely methods will be created in
the avocado_qemu/__init__.py file.
Let's refactor the code so that KNOWN_DISTROS and related methods are
packaged in a class
Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
Signed-off-by: Eric Auger <eric.auger@redhat.com>
Message-Id: <20210706131729.30749-2-eric.auger@redhat.com>
[CR: moved aarch64 definition from patch 2 to 1]
[CR: protect get() when arch is not defined]
[CR: split long lines]
Acked-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
Signed-off-by: Cleber Rosa <crosa@redhat.com>
---
tests/acceptance/avocado_qemu/__init__.py | 86 +++++++++++++----------
1 file changed, 49 insertions(+), 37 deletions(-)
diff --git a/tests/acceptance/avocado_qemu/__init__.py
b/tests/acceptance/avocado_qemu/__init__.py
index c3163af3b7..256befafc4 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -306,34 +306,50 @@ def ssh_command(self, command):
f'Guest command failed: {command}')
return stdout_lines, stderr_lines
+class LinuxDistro:
+ """Represents a Linux distribution
-#: A collection of known distros and their respective image checksum
-KNOWN_DISTROS = {
- 'fedora': {
- '31': {
- 'x86_64':
- {'checksum': ('e3c1b309d9203604922d6e255c2c5d09'
- '8a309c2d46215d8fc026954f3c5c27a0')},
- 'aarch64':
- {'checksum': ('1e18d9c0cf734940c4b5d5ec592facae'
- 'd2af0ad0329383d5639c997fdf16fe49')},
- 'ppc64':
- {'checksum': ('7c3528b85a3df4b2306e892199a9e1e4'
- '3f991c506f2cc390dc4efa2026ad2f58')},
- 's390x':
- {'checksum': ('4caaab5a434fd4d1079149a072fdc789'
- '1e354f834d355069ca982fdcaf5a122d')},
+ Holds information of known distros.
+ """
+ #: A collection of known distros and their respective image checksum
+ KNOWN_DISTROS = {
+ 'fedora': {
+ '31': {
+ 'x86_64':
+ {'checksum': ('e3c1b309d9203604922d6e255c2c5d09'
+ '8a309c2d46215d8fc026954f3c5c27a0')},
+ 'aarch64':
+ {'checksum': ('1e18d9c0cf734940c4b5d5ec592facae'
+ 'd2af0ad0329383d5639c997fdf16fe49')},
+ 'ppc64':
+ {'checksum': ('7c3528b85a3df4b2306e892199a9e1e4'
+ '3f991c506f2cc390dc4efa2026ad2f58')},
+ 's390x':
+ {'checksum': ('4caaab5a434fd4d1079149a072fdc789'
+ '1e354f834d355069ca982fdcaf5a122d')},
}
}
}
+ def __init__(self, name, version, arch):
+ self.name = name
+ self.version = version
+ self.arch = arch
+ try:
+ info = self.KNOWN_DISTROS.get(name).get(version).get(arch)
+ except AttributeError:
+ # Unknown distro
+ info = None
+ self._info = info or {}
-def get_known_distro_checksum(distro, distro_version, arch):
- try:
- return KNOWN_DISTROS.get(distro).get(distro_version).\
- get(arch).get('checksum')
- except AttributeError:
- return None
+ @property
+ def checksum(self):
+ """Gets the cloud-image file checksum"""
+ return self._info.get('checksum', None)
+
+ @checksum.setter
+ def checksum(self, value):
+ self._info['checksum'] = value
class LinuxTest(Test, LinuxSSHMixIn):
@@ -344,24 +360,24 @@ class LinuxTest(Test, LinuxSSHMixIn):
"""
timeout = 900
- distro_checksum = None
+ distro = None
username = 'root'
password = 'password'
def _set_distro(self):
- distro = self.params.get(
+ distro_name = self.params.get(
'distro',
default=self._get_unique_tag_val('distro'))
- if not distro:
- distro = 'fedora'
- self.distro = distro
+ if not distro_name:
+ distro_name = 'fedora'
distro_version = self.params.get(
'distro_version',
default=self._get_unique_tag_val('distro_version'))
if not distro_version:
distro_version = '31'
- self.distro_version = distro_version
+
+ self.distro = LinuxDistro(distro_name, distro_version, self.arch)
# The distro checksum behaves differently than distro name and
# version. First, it does not respect a tag with the same
@@ -370,13 +386,9 @@ def _set_distro(self):
# order of precedence is: parameter, attribute and then value
# from KNOWN_DISTROS.
distro_checksum = self.params.get('distro_checksum',
- default=self.distro_checksum)
- if not distro_checksum:
- distro_checksum = get_known_distro_checksum(self.distro,
- self.distro_version,
- self.arch)
+ default=None)
if distro_checksum:
- self.distro_checksum = distro_checksum
+ self.distro.checksum = distro_checksum
def setUp(self, ssh_pubkey=None, network_device_type='virtio-net'):
super(LinuxTest, self).setUp()
@@ -418,14 +430,14 @@ def download_boot(self):
self.log.info('Downloading/preparing boot image')
# Fedora 31 only provides ppc64le images
image_arch = self.arch
- if self.distro == 'fedora':
+ if self.distro.name == 'fedora':
if image_arch == 'ppc64':
image_arch = 'ppc64le'
try:
boot = vmimage.get(
- self.distro, arch=image_arch, version=self.distro_version,
- checksum=self.distro_checksum,
+ self.distro.name, arch=image_arch, version=self.distro.version,
+ checksum=self.distro.checksum,
algorithm='sha256',
cache_dir=self.cache_dirs[0],
snapshot_dir=self.workdir)
--
2.31.1
- [PULL 00/23] Python and Acceptance Tests, Cleber Rosa, 2021/07/13
- [PULL 01/23] Acceptance Tests: use the job work directory for created VMs, Cleber Rosa, 2021/07/13
- [PULL 02/23] Acceptance Tests: log information when creating QEMUMachine, Cleber Rosa, 2021/07/13
- [PULL 04/23] Acceptance Tests: rename attribute holding the distro image checksum, Cleber Rosa, 2021/07/13
- [PULL 03/23] Acceptance Tests: distinguish between temp and logs dir, Cleber Rosa, 2021/07/13
- [PULL 05/23] Acceptance Tests: move definition of distro checksums to the framework, Cleber Rosa, 2021/07/13
- [PULL 06/23] Acceptance Tests: support choosing specific distro and version, Cleber Rosa, 2021/07/13
- [PULL 07/23] tests/acceptance: Ignore binary data sent on serial console, Cleber Rosa, 2021/07/13
- [PULL 09/23] Acceptance Tests: Add default kernel params and pxeboot url to the KNOWN_DISTROS collection, Cleber Rosa, 2021/07/13
- [PULL 08/23] avocado_qemu: Fix KNOWN_DISTROS map into the LinuxDistro class,
Cleber Rosa <=
- [PULL 10/23] avocado_qemu: Add SMMUv3 tests, Cleber Rosa, 2021/07/13
- [PULL 11/23] avocado_qemu: Add Intel iommu tests, Cleber Rosa, 2021/07/13
- [PULL 12/23] tests/acceptance: Tag NetBSD tests as 'os:netbsd', Cleber Rosa, 2021/07/13
- [PULL 13/23] tests/acceptance: Automatic set -cpu to the test vm, Cleber Rosa, 2021/07/13
- [PULL 14/23] tests/acceptance: Fix mismatch on cpu tagged tests, Cleber Rosa, 2021/07/13
- [PULL 16/23] tests/acceptance: Tagging tests with "cpu:VALUE", Cleber Rosa, 2021/07/13
- [PULL 15/23] tests/acceptance: Let the framework handle "cpu:VALUE" tagged tests, Cleber Rosa, 2021/07/13
- [PULL 17/23] python/qemu: Add args property to the QEMUMachine class, Cleber Rosa, 2021/07/13
- [PULL 19/23] tests/acceptance: Handle cpu tag on x86_cpu_model_versions tests, Cleber Rosa, 2021/07/13
- [PULL 18/23] tests/acceptance: Add set_vm_arg() to the Test class, Cleber Rosa, 2021/07/13