]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ci: helper: Rework _lcitool_run method logic
authorErik Skultety <eskultet@redhat.com>
Thu, 24 Aug 2023 11:21:12 +0000 (13:21 +0200)
committerErik Skultety <eskultet@redhat.com>
Tue, 12 Sep 2023 09:36:03 +0000 (11:36 +0200)
This method wasn't even utilized before this patch. This patch adds all
the necessary logic to successfully execute a container workload via
lcitool (which will later allow us to ditch ci/Makefile). Because
container executions via lcitool creates the following inside the
container:

    $ ls
    script datadir

where 'datadir' is the workload directory (in this case a local git
repo clone) and 'script' is the code that runs whatever the workload is
over 'datadir'.

In order to satisfy the ^above, our helper generates a trivial
temporary 'script' that will source ci/build.sh and run whatever was
specified as --job essentially to simulate the exact steps a GitLab
pipeline job would go through.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
ci/helper

index 392702ae41d7f61676f606b19c6dd3d6dee15336..fce370f99519280a6c448c74f5c0bac03671e33b 100755 (executable)
--- a/ci/helper
+++ b/ci/helper
@@ -11,6 +11,9 @@ import subprocess
 import sys
 import textwrap
 
+from pathlib import Path
+from tempfile import TemporaryDirectory
+
 import util
 
 
@@ -201,8 +204,56 @@ class Application:
         return repo.clone(dest, local=True)
 
     def _lcitool_run(self, args):
-        output = subprocess.check_output([self._args.lcitool] + args)
-        return output.decode("utf-8")
+        positional_args = ["container"]
+        opts = ["--user", self._args.login]
+        tmpdir = TemporaryDirectory(prefix="scratch",
+                                    dir=Path(self.repo.working_dir, "ci"))
+
+        repo_dest_path = Path(tmpdir.name, "libvirt.git").as_posix()
+        repo_clone = self._prepare_repo_copy(self.repo, repo_dest_path)
+        opts.extend(["--workload-dir", repo_clone.working_dir])
+
+        if self._args.job == "shell":
+            positional_args.append("shell")
+        else:
+            job2func = {
+                "test": "run_test",
+                "build": "run_build",
+                "codestyle": "run_codestyle",
+                "potfile": "run_potfile",
+                "rpmbuild": "run_rpmbuild",
+                "website": "run_website_build",
+            }
+
+            if self._args.engine != "auto":
+                positional_args.extend(["--engine", self._args.engine])
+
+            with open(Path(tmpdir.name, "script"), "w") as f:
+                script_path = f.name
+                contents = textwrap.dedent(f"""\
+                #!/bin/sh
+
+                cd datadir
+                . ci/jobs.sh
+
+                {job2func[self._args.job]}
+                """)
+
+                f.write(contents)
+
+            positional_args.append("run")
+            opts.extend(["--script", script_path])
+
+        opts.append(f"{self._args.image_prefix}{self._args.target}:{self._args.image_tag}")
+        proc = None
+        try:
+            proc = subprocess.run([self._args.lcitool] + positional_args + opts)
+        except KeyboardInterrupt:
+            sys.exit(1)
+        finally:
+            # this will take care of the generated script file above as well
+            tmpdir.cleanup()
+        return proc.returncode
 
     def _check_stale_images(self):
         namespace = self._args.namespace