From nobody Mon Feb 9 02:28:30 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625577710359133.17800330656337; Tue, 6 Jul 2021 06:21:50 -0700 (PDT) Received: from localhost ([::1]:51138 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m0l1J-0000mS-6u for importer@patchew.org; Tue, 06 Jul 2021 09:21:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35438) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0kxi-00026j-Jg for qemu-devel@nongnu.org; Tue, 06 Jul 2021 09:18:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:24853) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m0kxW-0007ny-Na for qemu-devel@nongnu.org; Tue, 06 Jul 2021 09:18:04 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-49-e9mWifFhO4C-Se1hTML3_g-1; Tue, 06 Jul 2021 09:17:51 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9421719251A0; Tue, 6 Jul 2021 13:17:50 +0000 (UTC) Received: from laptop.redhat.com (ovpn-113-159.ams2.redhat.com [10.36.113.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6BB269CB8; Tue, 6 Jul 2021 13:17:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625577473; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L9zucO0YT73veOSaGVS1qVMDfBuyR92BI+w+N+d4NXg=; b=iVM4oUly0KOUN56dueN4MZ2WSStKmtYd1IBp1U66zgCj+E6cLrGiC/IqseBpK8MvsocIbM teDqwkoacAHMNQAdjDQLX88RhOgoLUlxl2nGSsA3tU3GrU5yUUUyOWZCd9NFlhsO/5t/Iv QwXNPubTqSM0RNG1wqiGplbDWtbxzxs= X-MC-Unique: e9mWifFhO4C-Se1hTML3_g-1 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, philmd@redhat.com, crosa@redhat.com, wainersm@redhat.com Subject: [PATCH v5 1/4] avocado_qemu: Fix KNOWN_DISTROS map into the LinuxDistro class Date: Tue, 6 Jul 2021 15:17:26 +0200 Message-Id: <20210706131729.30749-2-eric.auger@redhat.com> In-Reply-To: <20210706131729.30749-1-eric.auger@redhat.com> References: <20210706131729.30749-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eric.auger@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.442, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: wrampazz@redhat.com, peterx@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625577713897100001 Content-Type: text/plain; charset="utf-8" From: Willian Rampazzo 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 Signed-off-by: Eric Auger Acked-by: Wainer dos Santos Moschetta --- tests/acceptance/avocado_qemu/__init__.py | 74 +++++++++++++---------- 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/a= vocado_qemu/__init__.py index 81ac90bebb..af93cd63ea 100644 --- a/tests/acceptance/avocado_qemu/__init__.py +++ b/tests/acceptance/avocado_qemu/__init__.py @@ -299,29 +299,43 @@ def ssh_command(self, command): f'Guest command failed: {command}') return stdout_lines, stderr_lines =20 +class LinuxDistro: + """Represents a Linux distribution =20 -#: A collection of known distros and their respective image checksum -KNOWN_DISTROS =3D { - 'fedora': { - '31': { - 'x86_64': - {'checksum': 'e3c1b309d9203604922d6e255c2c5d098a309c2d46215d8f= c026954f3c5c27a0'}, - 'aarch64': - {'checksum': '1e18d9c0cf734940c4b5d5ec592facaed2af0ad0329383d5= 639c997fdf16fe49'}, - 'ppc64': - {'checksum': '7c3528b85a3df4b2306e892199a9e1e43f991c506f2cc390= dc4efa2026ad2f58'}, - 's390x': - {'checksum': '4caaab5a434fd4d1079149a072fdc7891e354f834d355069= ca982fdcaf5a122d'}, + Holds information of known distros. + """ + #: A collection of known distros and their respective image checksum + KNOWN_DISTROS =3D { + 'fedora': { + '31': { + 'x86_64': + {'checksum': 'e3c1b309d9203604922d6e255c2c5d098a309c2d4621= 5d8fc026954f3c5c27a0'}, + 'ppc64': + {'checksum': '7c3528b85a3df4b2306e892199a9e1e43f991c506f2c= c390dc4efa2026ad2f58'}, + 's390x': + {'checksum': '4caaab5a434fd4d1079149a072fdc7891e354f834d35= 5069ca982fdcaf5a122d'}, } } } =20 + def __init__(self, name, version, arch): + self.name =3D name + self.version =3D version + self.arch =3D arch + try: + self._info =3D self.KNOWN_DISTROS.get(name).get(version).get(a= rch) + except AttributeError: + # Unknown distro + self._info =3D {} =20 -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'] =3D value =20 =20 class LinuxTest(Test, LinuxSSHMixIn): @@ -332,24 +346,24 @@ class LinuxTest(Test, LinuxSSHMixIn): """ =20 timeout =3D 900 - distro_checksum =3D None + distro =3D None username =3D 'root' password =3D 'password' =20 def _set_distro(self): - distro =3D self.params.get( + distro_name =3D self.params.get( 'distro', default=3Dself._get_unique_tag_val('distro')) - if not distro: - distro =3D 'fedora' - self.distro =3D distro + if not distro_name: + distro_name =3D 'fedora' =20 distro_version =3D self.params.get( 'distro_version', default=3Dself._get_unique_tag_val('distro_version')) if not distro_version: distro_version =3D '31' - self.distro_version =3D distro_version + + self.distro =3D LinuxDistro(distro_name, distro_version, self.arch) =20 # The distro checksum behaves differently than distro name and # version. First, it does not respect a tag with the same @@ -358,13 +372,9 @@ def _set_distro(self): # order of precedence is: parameter, attribute and then value # from KNOWN_DISTROS. distro_checksum =3D self.params.get('distro_checksum', - default=3Dself.distro_checksum) - if not distro_checksum: - distro_checksum =3D get_known_distro_checksum(self.distro, - self.distro_versio= n, - self.arch) + default=3DNone) if distro_checksum: - self.distro_checksum =3D distro_checksum + self.distro.checksum =3D distro_checksum =20 def setUp(self, ssh_pubkey=3DNone, network_device_type=3D'virtio-net'): super(LinuxTest, self).setUp() @@ -406,14 +416,14 @@ def download_boot(self): self.log.info('Downloading/preparing boot image') # Fedora 31 only provides ppc64le images image_arch =3D self.arch - if self.distro =3D=3D 'fedora': + if self.distro.name =3D=3D 'fedora': if image_arch =3D=3D 'ppc64': image_arch =3D 'ppc64le' =20 try: boot =3D vmimage.get( - self.distro, arch=3Dimage_arch, version=3Dself.distro_vers= ion, - checksum=3Dself.distro_checksum, + self.distro.name, arch=3Dimage_arch, version=3Dself.distro= .version, + checksum=3Dself.distro.checksum, algorithm=3D'sha256', cache_dir=3Dself.cache_dirs[0], snapshot_dir=3Dself.workdir) --=20 2.26.3