ci: helper: Rework _lcitool_run method logic

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>
This commit is contained in:
Erik Skultety 2023-08-24 13:21:12 +02:00
parent 4ad2f89244
commit 04b9118fe5

View File

@ -11,6 +11,9 @@ import subprocess
import sys import sys
import textwrap import textwrap
from pathlib import Path
from tempfile import TemporaryDirectory
import util import util
@ -201,8 +204,56 @@ class Application:
return repo.clone(dest, local=True) return repo.clone(dest, local=True)
def _lcitool_run(self, args): def _lcitool_run(self, args):
output = subprocess.check_output([self._args.lcitool] + args) positional_args = ["container"]
return output.decode("utf-8") 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): def _check_stale_images(self):
namespace = self._args.namespace namespace = self._args.namespace