From 89e278381f160b1f3154f78a4d76663699e966d3 Mon Sep 17 00:00:00 2001 From: Eduardo Olivares Date: Mon, 28 Oct 2024 16:42:28 +0100 Subject: [PATCH] Remove passt when virt-customize does not work When tobiko runs virt-customize on a podified environment, the command fails because passt cannot be used. This patch adds a temporary workaround until the issue is fixed. TOBIKO-122 Change-Id: I7b52387d1ad889da2f4b77cb05cd5af457d83e89 --- tobiko/openstack/glance/_image.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tobiko/openstack/glance/_image.py b/tobiko/openstack/glance/_image.py index 6d6f0b700..ec49311ae 100644 --- a/tobiko/openstack/glance/_image.py +++ b/tobiko/openstack/glance/_image.py @@ -444,6 +444,21 @@ class CustomizedGlanceImageFixture(FileGlanceImageFixture): return 'customized' def customize_image_file(self, base_file: str) -> str: + + def workaround_passt(full_command, exc): + which_passt = sh.execute( + 'which passt', expect_exit_status=None).stdout.rstrip() + if which_passt == '': + raise exc + + cmd = f'mv {which_passt} {which_passt}.bak' + cmd_cleanup = f'mv {which_passt}.bak {which_passt}' + tobiko.add_cleanup(sh.execute, cmd_cleanup, + expect_exit_status=None, sudo=True) + LOG.exception("Executing virt-customize without passt") + sh.execute(cmd, sudo=True) + sh.execute(full_command) + customized_file = f'{base_file}-{self._get_customized_suffix()}' if os.path.isfile(customized_file): if (os.stat(base_file).st_mtime_ns < @@ -464,7 +479,10 @@ class CustomizedGlanceImageFixture(FileGlanceImageFixture): 'virt-customize', '-a', work_file]) - sh.execute(command + options) + try: + sh.execute(command + options) + except sh.ShellCommandFailed as exc: + workaround_passt(command + options, exc) sh.get_file(work_file, customized_file) return customized_file