[libvirt PATCH v3 04/10] ci: Implement 'refresh' helper action

Andrea Bolognani abologna at redhat.com
Fri Mar 12 17:28:16 UTC 2021


This provides the same functionality as the two refresh scripts
that are currently in the repository, with the following
advantages:

  * all files are refreshed with a single command;

  * if lcitool is present in the user's $PATH, it will be
    discovered and used automatically;

  * some output is produced, so the user can follow along with
    the progress of the operation.

Signed-off-by: Andrea Bolognani <abologna at redhat.com>
---
 ci/helper | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 102 insertions(+)

diff --git a/ci/helper b/ci/helper
index 2a59b8e5ab..05ecdcb426 100755
--- a/ci/helper
+++ b/ci/helper
@@ -18,10 +18,22 @@
 
 import argparse
 import pathlib
+import shutil
+import subprocess
+import sys
 
 
 class Parser:
     def __init__(self):
+        # Options that are common to all actions that use lcitool
+        lcitoolparser = argparse.ArgumentParser(add_help=False)
+        lcitoolparser.add_argument(
+            "--lcitool",
+            metavar="PATH",
+            default="lcitool",
+            help="path to lcitool binary",
+        )
+
         # Main parser
         self.parser = argparse.ArgumentParser()
         subparsers = self.parser.add_subparsers(
@@ -30,6 +42,14 @@ class Parser:
         )
         subparsers.required = True
 
+        # refresh action
+        refreshparser = subparsers.add_parser(
+            "refresh",
+            help="refresh data generated with lcitool",
+            parents=[lcitoolparser],
+        )
+        refreshparser.set_defaults(func=Application.action_refresh)
+
     def parse(self):
         return self.parser.parse_args()
 
@@ -39,6 +59,88 @@ class Application:
         self.basedir = pathlib.Path(__file__).resolve().parent
         self.args = Parser().parse()
 
+        if self.args.action == "refresh":
+            if not shutil.which(self.args.lcitool):
+                sys.exit("error: 'lcitool' not installed")
+
+    def lcitool_run(self, args):
+        output = subprocess.check_output([self.args.lcitool] + args)
+        return output.decode("utf-8")
+
+    def lcitool_get_hosts(self):
+        output = self.lcitool_run(["hosts"])
+        return output.splitlines()
+
+    def generate_dockerfile(self, host, cross=None):
+        args = ["dockerfile", host, "libvirt"]
+        outdir = self.basedir.joinpath("containers")
+        outfile = f"ci-{host}.Dockerfile"
+
+        if cross:
+            args.extend(["--cross", cross])
+            outfile = f"ci-{host}-cross-{cross}.Dockerfile"
+
+        output = self.lcitool_run(args)
+        with open(outdir.joinpath(outfile), "w") as f:
+            f.write(output)
+
+    def generate_vars(self, host):
+        args = ["variables", host, "libvirt"]
+        outdir = self.basedir.joinpath("cirrus")
+        outfile = f"{host}.vars"
+
+        output = self.lcitool_run(args)
+        with open(outdir.joinpath(outfile), "w") as f:
+            f.write(output)
+
+    def refresh_containers(self):
+        debian_cross = [
+            "aarch64",
+            "armv6l",
+            "armv7l",
+            "i686",
+            "mips",
+            "mips64el",
+            "mipsel",
+            "ppc64le",
+            "s390x",
+        ]
+        fedora_cross = [
+            "mingw32",
+            "mingw64",
+        ]
+
+        for host in self.lcitool_get_hosts():
+            if host.startswith("freebsd-") or host.startswith("macos-"):
+                continue
+
+            print(f"containers/{host}")
+            self.generate_dockerfile(host)
+
+            if host == "fedora-rawhide":
+                for cross in fedora_cross:
+                    print(f"containers/{host} ({cross})")
+                    self.generate_dockerfile(host, cross)
+
+            if host.startswith("debian-"):
+                for cross in debian_cross:
+                    if host == "debian-sid" and cross == "mips":
+                        continue
+                    print(f"containers/{host} ({cross})")
+                    self.generate_dockerfile(host, cross)
+
+    def refresh_cirrus(self):
+        for host in self.lcitool_get_hosts():
+            if not (host.startswith("freebsd-") or host.startswith("macos-")):
+                continue
+
+            print(f"cirrus/{host}")
+            self.generate_vars(host)
+
+    def action_refresh(self):
+        self.refresh_containers()
+        self.refresh_cirrus()
+
     def run(self):
         self.args.func(self)
 
-- 
2.26.2




More information about the libvir-list mailing list