public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Anton Mikanovich <amikan@ilbers.de>
To: isar-users@googlegroups.com
Cc: Anton Mikanovich <amikan@ilbers.de>
Subject: [PATCH 4/5] CI: Allow external usage for some APIs
Date: Fri, 14 Jun 2024 14:23:19 +0300	[thread overview]
Message-ID: <20240614112320.122428-5-amikan@ilbers.de> (raw)
In-Reply-To: <20240614112320.122428-1-amikan@ilbers.de>

Provide utilities class for external usage to be imported from outside
of Avocado framework.

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
 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


  parent reply	other threads:[~2024-06-14 11:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-14 11:23 [PATCH 0/5] Remove code duplications for start_vm Anton Mikanovich
2024-06-14 11:23 ` [PATCH 1/5] start_vm: Switch to python version Anton Mikanovich
2024-06-14 11:23 ` [PATCH 2/5] start_vm: Add secureboot support Anton Mikanovich
2024-06-14 11:23 ` [PATCH 3/5] scripts: Remove vm_smoke_test Anton Mikanovich
2024-06-14 11:23 ` Anton Mikanovich [this message]
2024-06-14 11:23 ` [PATCH 5/5] start_vm: Reuse getVars API Anton Mikanovich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240614112320.122428-5-amikan@ilbers.de \
    --to=amikan@ilbers.de \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox