From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 7380318098191024128 X-Received: by 2002:a05:6512:e8c:b0:52c:cceb:bbcc with SMTP id 2adb3069b0e04-52cccebbd58mr6741654e87.0.1718982509778; Fri, 21 Jun 2024 08:08:29 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a05:6512:2206:b0:52c:a105:90ee with SMTP id 2adb3069b0e04-52ccf08ea71ls164306e87.1.-pod-prod-01-eu; Fri, 21 Jun 2024 08:08:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF6UI33EBbuqcO2rm/JHHAW4BxZGG3hUulDs89GFU80QpTY9nZ/OcIIT7/gYv2IN1ufxby1 X-Received: by 2002:ac2:489b:0:b0:52c:d56f:b2cc with SMTP id 2adb3069b0e04-52cd56fb3bfmr1421759e87.58.1718982507620; Fri, 21 Jun 2024 08:08:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718982507; cv=none; d=google.com; s=arc-20160816; b=YlEFlGHUzXH0cxRe+jEQZ0I21onVVkku/dSSTJTao8Uamxy1U5bERY+F+ujv5BTgR6 fq7VnLwyQ0vOuR6XAO65CE9r1TQIQNxeoEXCpSKMjwG/Uk+cZQ1PdgehGwhy6vrrqPwO eI89orGc4bcAEo7Soyl6cGWN/Skbqpj27WXM4fShrIy1HIt6ZNzylHh4R91m3vEsCkrt BjajtNkJSzRUJk3Ah6MnNJ7AFEA0vorJSciQZ4tjkyeHYLaWCWBNWt7vWzLOyo4+fDuS kj4m2DQdoNzFVAKLqazsR2BvSt0SFaVr/qj5ERwg1V8svy/LUDoF8WCO4ceaasazRJmk PwIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=GQDMB7shaswAgAwX4lgZ4QgmvgefyZhHCIVp2Od8fxk=; fh=/h9QQkzJ8EboVkWg45aWwpaUro6WMavIVd2OhN45RtE=; b=YH1dPrB/GdbJ08MXNr38UvxAsbHHFMlUO7RPsBCeJSpFHHoN8KAD0v/NlyAs83rKRz LbwWtZ04Jkp+fJLZi50KZKlGjv4yyONfeqwH4/X5xq2s83uO93eKnAnIAkSY5SHFEW+g xOSKZqzAVGXV0VIh/kquJU+JFjzuMb71kkzC3JN5OY/QZnmDGPkLAxZ5mhY5ffUhH7Kq aZA3mHGgltKENKzdiqF5mPGs+ooGfuY0tETkvP5AB3RC57E4xYJPJfk8UTKdLz4gaCTR kDdD2hYMKP797gBIPFFkA59bGfHx8A9dLvzViWvs+9emikyYPf1ubh5zUy19bmJA9STm V1CA==; dara=google.com ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of amikan@ilbers.de designates 85.214.156.166 as permitted sender) smtp.mailfrom=amikan@ilbers.de Return-Path: Received: from shymkent.ilbers.de (shymkent.ilbers.de. [85.214.156.166]) by gmr-mx.google.com with ESMTPS id 5b1f17b1804b1-4247194de3bsi6211355e9.0.2024.06.21.08.08.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 21 Jun 2024 08:08:27 -0700 (PDT) Received-SPF: pass (google.com: domain of amikan@ilbers.de designates 85.214.156.166 as permitted sender) client-ip=85.214.156.166; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of amikan@ilbers.de designates 85.214.156.166 as permitted sender) smtp.mailfrom=amikan@ilbers.de Received: from user-B660.promwad.corp ([159.148.83.114]) (authenticated bits=0) by shymkent.ilbers.de (8.15.2/8.15.2/Debian-8+deb9u1) with ESMTPSA id 45LF8ObF006158 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Jun 2024 17:08:26 +0200 From: Anton Mikanovich To: isar-users@googlegroups.com Cc: Anton Mikanovich Subject: [PATCH v3 4/5] CI: Allow external usage for some APIs Date: Fri, 21 Jun 2024 18:08:13 +0300 Message-Id: <20240621150814.189288-5-amikan@ilbers.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240621150814.189288-1-amikan@ilbers.de> References: <20240621150814.189288-1-amikan@ilbers.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=unavailable autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on shymkent.ilbers.de X-TUID: fFgAbOTQAZJJ Provide utilities class for external usage to be imported from outside of Avocado framework. Signed-off-by: Anton Mikanovich --- testsuite/cibase.py | 8 +++-- testsuite/cibuilder.py | 52 ++++----------------------------- testsuite/citest.py | 4 ++- testsuite/repro-build-test.py | 4 ++- testsuite/utils.py | 55 +++++++++++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 51 deletions(-) create mode 100755 testsuite/utils.py diff --git a/testsuite/cibase.py b/testsuite/cibase.py index 0f6997af..fd571c29 100755 --- a/testsuite/cibase.py +++ b/testsuite/cibase.py @@ -8,6 +8,8 @@ import tempfile import time from cibuilder import CIBuilder, isar_root +from utils import CIUtils + from avocado.utils import process class CIBaseTest(CIBuilder): @@ -238,13 +240,13 @@ class CIBaseTest(CIBuilder): for target in targets: sfiles[target] = dict() package = target.rsplit(':', 1)[-1] - isar_apt = self.getVars('REPO_ISAR_DB_DIR', target=target) + isar_apt = CIUtils.getVars('REPO_ISAR_DB_DIR', target=target) fpath = f'{package}/{package}*.tar.gz' targz = set(glob.glob(f'{isar_apt}/../apt/*/pool/*/*/{fpath}')) if len(targz) < 1: self.fail('No source packages found') - for filename in targz: - sfiles[target][filename] = self.get_tar_content(filename) + for fname in targz: + sfiles[target][fname] = CIUtils.get_tar_content(fname) return sfiles self.configure(**kwargs) diff --git a/testsuite/cibuilder.py b/testsuite/cibuilder.py index 87d71387..a20e88f9 100755 --- a/testsuite/cibuilder.py +++ b/testsuite/cibuilder.py @@ -9,11 +9,11 @@ import shutil import signal import subprocess import sys -import tarfile import time import tempfile import start_vm +from utils import CIUtils from avocado import Test from avocado.utils import path @@ -22,7 +22,6 @@ from avocado.utils import process sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)) + '/../bitbake/lib') import bb -import bb.tinfoil DEF_VM_TO_SEC = 600 @@ -253,38 +252,6 @@ class CIBuilder(Test): except FileNotFoundError: self.log.warn(path + backup_prefix + ' not exist') - def getVars(self, *vars, target=None): - self.check_init() - def fixStream(stream): - # fix stream objects to emulate _io.TextIOWrapper - stream.isatty = lambda: False - stream.fileno = lambda: False - stream.encoding = sys.getdefaultencoding() - - sl = target is not None - fixStream(sys.stdout) - fixStream(sys.stderr) - - # wait until previous bitbake will be finished - lockfile = os.path.join(self.build_dir, 'bitbake.lock') - checks = 0 - while os.path.exists(lockfile) and checks < 5: - time.sleep(1) - checks += 1 - - with bb.tinfoil.Tinfoil(setup_logging=sl) as tinfoil: - values = () - if target: - tinfoil.prepare(quiet=2) - d = tinfoil.parse_recipe(target) - for var in vars: - values = values + (d.getVar(var, True) or 'None',) - else: - tinfoil.prepare(config_only=True, quiet=2) - for var in vars: - values = values + (tinfoil.config_data.getVar(var, True) or 'None',) - return values if len(values) > 1 else values[0] - def create_tmp_layer(self): tmp_layer_dir = os.path.join(isar_root, 'meta-tmp') @@ -314,13 +281,6 @@ BBPATH .= ":${LAYERDIR}"\ bb.utils.edit_bblayers_conf(bblayersconf_file, None, tmp_layer_dir) bb.utils.prunedir(tmp_layer_dir) - def get_tar_content(self, filename): - try: - tar = tarfile.open(filename) - return tar.getnames() - except Exception: - return [] - def get_ssh_cmd_prefix(self, user, host, port, priv_key): cmd_prefix = 'ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no '\ '-p %s -o IdentityFile=%s %s@%s ' \ @@ -525,11 +485,11 @@ BBPATH .= ":${LAYERDIR}"\ module_output = b'Just an example' resize_output = None image_fstypes, \ - wks_file, \ - bbdistro = self.getVars('IMAGE_FSTYPES', \ - 'WKS_FILE', \ - 'DISTRO', \ - target=multiconfig) + wks_file, \ + bbdistro = CIUtils.getVars('IMAGE_FSTYPES', + 'WKS_FILE', + 'DISTRO', + target=multiconfig) # only the first type will be tested in start_vm if image_fstypes.split()[0] == 'wic': diff --git a/testsuite/citest.py b/testsuite/citest.py index 42d44f6a..b84ae0e1 100755 --- a/testsuite/citest.py +++ b/testsuite/citest.py @@ -5,6 +5,7 @@ import os from avocado import skipUnless from avocado.utils import path from cibase import CIBaseTest +from utils import CIUtils UMOCI_AVAILABLE = True SKOPEO_AVAILABLE = True @@ -17,6 +18,7 @@ try: except path.CmdNotFoundError: SKOPEO_AVAILABLE = False + class DevTest(CIBaseTest): """ @@ -46,7 +48,7 @@ class DevTest(CIBaseTest): def test_dev_rebuild(self): self.init() - layerdir_core = self.getVars('LAYERDIR_core') + layerdir_core = CIUtils.getVars('LAYERDIR_core') dpkgbase_file = layerdir_core + '/classes/dpkg-base.bbclass' diff --git a/testsuite/repro-build-test.py b/testsuite/repro-build-test.py index 843f3bc6..04e4ddc7 100755 --- a/testsuite/repro-build-test.py +++ b/testsuite/repro-build-test.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 from cibuilder import CIBuilder +from utils import CIUtils from avocado.utils import process @@ -29,7 +30,8 @@ class ReproBuild(CIBuilder): def get_image_path(self, target_name): image_dir = "tmp/deploy/images" - machine, image_name = self.getVars("MACHINE", "IMAGE_FULLNAME", target=target_name) + machine, image_name = CIUtils.getVars('MACHINE', 'IMAGE_FULLNAME', + target=target_name) return f"{image_dir}/{machine}/{image_name}.tar.gz" def build_repro_image( diff --git a/testsuite/utils.py b/testsuite/utils.py new file mode 100755 index 00000000..ffcb5cc7 --- /dev/null +++ b/testsuite/utils.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 + +import os +import sys +import tarfile +import time + +sys.path.append(os.path.join(os.path.dirname(__file__), '../bitbake/lib')) + +import bb +import bb.tinfoil + + +class CIUtils(): + @staticmethod + def getVars(*vars, target=None): + def fixStream(stream): + # fix stream objects to emulate _io.TextIOWrapper + stream.isatty = lambda: False + stream.fileno = lambda: False + stream.encoding = sys.getdefaultencoding() + + sl = target is not None + if not hasattr(sys.stdout, 'isatty'): + fixStream(sys.stdout) + if not hasattr(sys.stderr, 'isatty'): + fixStream(sys.stderr) + + # wait until previous bitbake will be finished + lockfile = os.path.join(os.getcwd(), 'bitbake.lock') + checks = 0 + while os.path.exists(lockfile) and checks < 5: + time.sleep(1) + checks += 1 + + with bb.tinfoil.Tinfoil(setup_logging=sl) as tinfoil: + values = () + if target: + tinfoil.prepare(quiet=2) + d = tinfoil.parse_recipe(target) + for var in vars: + values = values + (d.getVar(var, True) or '',) + else: + tinfoil.prepare(config_only=True, quiet=2) + for var in vars: + values = values + (tinfoil.config_data.getVar(var) or '',) + return values if len(values) > 1 else values[0] + + @staticmethod + def get_tar_content(filename): + try: + tar = tarfile.open(filename) + return tar.getnames() + except Exception: + return [] -- 2.34.1