From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 7380318098191024128 X-Received: by 2002:a2e:9e84:0:b0:2eb:e47c:6d2a with SMTP id 38308e7fff4ca-2ec0e5d1383mr15202591fa.28.1718364215504; Fri, 14 Jun 2024 04:23:35 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a05:600c:3b0c:b0:421:7e41:1878 with SMTP id 5b1f17b1804b1-422b6cce65fls9571285e9.0.-pod-prod-07-eu; Fri, 14 Jun 2024 04:23:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEq0UY9OxmbnJryDNVVw453tFXpHOwlhnl4zOiwMbLeps4xBMdNDf50tQDsr2XUE9AyLMYi X-Received: by 2002:a05:600c:91e:b0:421:f04d:ebd2 with SMTP id 5b1f17b1804b1-4230482fbafmr24494045e9.22.1718364213390; Fri, 14 Jun 2024 04:23:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1718364213; cv=none; d=google.com; s=arc-20160816; b=TtPasHq6kEm7AQh5zsykKDO3NmtiFEddbEVTSvGRXatBTcteNtL/peoEZr+dw9kOsW mFeUr6kMAyd94IOWRqjVT1VRT173MFd0jiVnaa2NQkfs8DRgGgCATgds6WvqXUooYeJv JZDDYAuw9BPyn+0266UDcJRLtAdGD3W/k8kozL/kycw/tqw5ECHO1qjlIXFobN3HAKRC PjbCViQnFt3EvfCiVOqDiqLGF0yL0HU3NZZavpkGvYWZSo5CiGNzblG7ALU+mBpVnp9e SFnJWGhF1F1d/mki+cuRSXGF+KZOTmRdgxnvjJrNGeZYKn55sh5jX7WPZTPvUBZxZOEa 5Ydw== 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=a07wbHghMLOtZnFmjWXm5kOQzgrErgkvQ+d+lwJ6VVU=; fh=/h9QQkzJ8EboVkWg45aWwpaUro6WMavIVd2OhN45RtE=; b=0SU5zPPv3JcFIhQgu0JLLqaIWm8S1xC+iI3FmL3z8oEugAp7CMKkPgg5JsKY7/l0XA o1HnjNvO6KFIxQnWWFmtHMVwRnOTe4kw7zBZqg2YiV+x1EJzAkL/WgsDQTzSqaEZ+ruB MAUsQ70mqM8N682cNOfI34ZRkEtTxNwh/N2d207mjCBmrSqyhzejx2ah4Bn4iN7xCmyi njE+dSKBIb4FyUnQN5ZXJpf2sDCFBD0+sjbi9w3nyACLQCVDOrpJs5cO3El6g+Hgt6nI TlLw6iR6YVmslNUXgCn8RS/WwaNhw32fno2AXe8JgqCCKW4OS0o/VzBoRZQJm0/Ad8PB fd2w==; 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-42285317d3bsi4210915e9.1.2024.06.14.04.23.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Jun 2024 04:23:33 -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 localhost.localdomain (r154-240-38-77-broadband.btv.lv [77.38.240.154] (may be forged)) (authenticated bits=0) by shymkent.ilbers.de (8.15.2/8.15.2/Debian-8+deb9u1) with ESMTPSA id 45EBNRq5031631 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 14 Jun 2024 13:23:32 +0200 From: Anton Mikanovich To: isar-users@googlegroups.com Cc: Anton Mikanovich Subject: [PATCH 4/5] CI: Allow external usage for some APIs Date: Fri, 14 Jun 2024 14:23:19 +0300 Message-Id: <20240614112320.122428-5-amikan@ilbers.de> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240614112320.122428-1-amikan@ilbers.de> References: <20240614112320.122428-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: ypKnNtWjHKdC Provide utilities class for external usage to be imported from outside of Avocado framework. Signed-off-by: Anton Mikanovich --- testsuite/cibase.py | 6 +++-- testsuite/cibuilder.py | 50 ++++---------------------------------- testsuite/citest.py | 4 +++- testsuite/utils.py | 54 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 48 deletions(-) create mode 100755 testsuite/utils.py diff --git a/testsuite/cibase.py b/testsuite/cibase.py index 0f6997af..c257a465 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) + sfiles[target][filename] = CIUtils.get_tar_content(filename) return sfiles self.configure(**kwargs) diff --git a/testsuite/cibuilder.py b/testsuite/cibuilder.py index a51d6f7e..4aa06ffb 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 ' \ @@ -526,10 +486,10 @@ BBPATH .= ":${LAYERDIR}"\ resize_output = None image_fstypes, \ wks_file, \ - bbdistro = self.getVars('IMAGE_FSTYPES', \ - 'WKS_FILE', \ - 'DISTRO', \ - target=multiconfig) + 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/utils.py b/testsuite/utils.py new file mode 100755 index 00000000..a3f643fa --- /dev/null +++ b/testsuite/utils.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 + +import os +import sys +import tarfile +import time + +sys.path.insert(0, os.path.dirname(os.path.realpath(__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, True) 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