From b81e94e808580c2c5d2d5894e748394a2c13d285 Mon Sep 17 00:00:00 2001 From: Qixiang Wan Date: Thu, 31 Aug 2017 16:10:52 +0800 Subject: [PATCH] image-build: add arch name(s) in image config file name Pungi write image config file with name of -.cfg, if there are two or more image configs present for different arches under the same variant and with same format & name, the config file can be overwritten, and result in invalid image conf file. Example: image_build = { '^Server$': [ { 'image-build': { 'format': [('qcow2', 'qcow2'),], 'name': 'fedora-guest-image', 'target': 'guest-fedora-26-image', 'version': '26', 'ksurl': "git://git.example.com/ks.git?fedora#HEAD", 'kickstart': "fedora-26-kvm.ks", 'ksversion': 'f26', 'distro': 'fedora-26', 'disk-size': '10', 'arches': ['x86_64'], 'repo': ["http://example.com/linux/fedora/26/Everything/x86_64/os", ] } }, { 'image-build': { 'format': [('qcow2', 'qcow2'),], 'name': 'fedora-guest-image', 'target': 'guest-fedora-26-image', 'version': '26', 'ksurl': "git://git.example.com/ks.git?fedora#HEAD", 'kickstart': "fedora-26-kvm.ks", 'ksversion': 'f26', 'distro': 'fedora-26', 'disk-size': '10', 'arches': ['ppc64le'], } }, ], } In this case, config file "qcow2_guest-fedora-26-image.cfg" will be created for both x86_64 and ppc64le under the same variant dir, and there is a high chance it will be over-written while Pungi creating the koji task. We can add arch name(s) in config filename to avoid that. Signed-off-by: Qixiang Wan --- pungi/paths.py | 10 ++++++++-- pungi/phases/image_build.py | 3 ++- tests/test_imagebuildphase.py | 18 +++++++++--------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/pungi/paths.py b/pungi/paths.py index f00f22cf..f32debf1 100644 --- a/pungi/paths.py +++ b/pungi/paths.py @@ -302,17 +302,23 @@ class WorkPaths(object): makedirs(path) return path - def image_build_conf(self, variant, image_name, image_type, create_dir=True): + def image_build_conf(self, variant, image_name, image_type, arches=None, create_dir=True): """ @param variant @param image-name @param image-type (e.g docker) + @param arches @param create_dir=True Examples: work/image-build/Server/docker_rhel-server-docker.cfg + work/image-build/Server/docker_rhel-server-docker_x86_64.cfg + work/image-build/Server/docker_rhel-server-docker_x86_64-ppc64le.cfg """ - path = os.path.join(self.image_build_dir(variant), "%s_%s.cfg" % (image_type, image_name)) + path = os.path.join(self.image_build_dir(variant), "%s_%s" % (image_type, image_name)) + if arches is not None: + path = "%s_%s" % (path, '-'.join(list(arches))) + path = "%s.cfg" % path return path diff --git a/pungi/phases/image_build.py b/pungi/phases/image_build.py index 31350ec0..cbaffc9a 100644 --- a/pungi/phases/image_build.py +++ b/pungi/phases/image_build.py @@ -120,7 +120,8 @@ class ImageBuildPhase(base.PhaseLoggerMixin, base.ImageConfigMixin, base.ConfigG "conf_file": self.compose.paths.work.image_build_conf( image_conf["image-build"]['variant'], image_name=image_conf["image-build"]['name'], - image_type=image_conf["image-build"]['format'].replace(",", "-") + image_type=image_conf["image-build"]['format'].replace(",", "-"), + arches=image_conf["image-build"]['arches'], ), "image_dir": self.compose.paths.compose.image_dir(variant), "relative_image_dir": self.compose.paths.compose.image_dir( diff --git a/tests/test_imagebuildphase.py b/tests/test_imagebuildphase.py index 07fa15ad..ef6b130f 100644 --- a/tests/test_imagebuildphase.py +++ b/tests/test_imagebuildphase.py @@ -73,7 +73,7 @@ class TestImageBuildPhase(PungiTestCase): 'can_fail': ['x86_64'], } }, - "conf_file": self.topdir + '/work/image-build/Client/docker_Fedora-Docker-Base.cfg', + "conf_file": self.topdir + '/work/image-build/Client/docker_Fedora-Docker-Base_amd64.cfg', "image_dir": self.topdir + '/compose/Client/%(arch)s/images', "relative_image_dir": 'Client/%(arch)s/images', "link_type": 'hardlink-or-copy', @@ -98,7 +98,7 @@ class TestImageBuildPhase(PungiTestCase): 'can_fail': ['x86_64'], } }, - "conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base.cfg', + "conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base_amd64-x86_64.cfg', "image_dir": self.topdir + '/compose/Server/%(arch)s/images', "relative_image_dir": 'Server/%(arch)s/images', "link_type": 'hardlink-or-copy', @@ -158,7 +158,7 @@ class TestImageBuildPhase(PungiTestCase): 'release': '20151203.t.0', } }, - "conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base.cfg', + "conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base_amd64-x86_64.cfg', "image_dir": self.topdir + '/compose/Server/%(arch)s/images', "relative_image_dir": 'Server/%(arch)s/images', "link_type": 'hardlink-or-copy', @@ -214,7 +214,7 @@ class TestImageBuildPhase(PungiTestCase): 'release': '20151203.t.0', } }, - "conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base.cfg', + "conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base_amd64-x86_64.cfg', "image_dir": self.topdir + '/compose/Server/%(arch)s/images', "relative_image_dir": 'Server/%(arch)s/images', "link_type": 'hardlink-or-copy', @@ -311,7 +311,7 @@ class TestImageBuildPhase(PungiTestCase): 'distro': 'Fedora-20', } }, - "conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base.cfg', + "conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base_x86_64.cfg', "image_dir": self.topdir + '/compose/Server/%(arch)s/images', "relative_image_dir": 'Server/%(arch)s/images', "link_type": 'hardlink-or-copy', @@ -375,7 +375,7 @@ class TestImageBuildPhase(PungiTestCase): 'distro': 'Fedora-20', } }, - "conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base.cfg', + "conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base_x86_64.cfg', "image_dir": self.topdir + '/compose/Server/%(arch)s/images', "relative_image_dir": 'Server/%(arch)s/images', "link_type": 'hardlink-or-copy', @@ -436,7 +436,7 @@ class TestImageBuildPhase(PungiTestCase): 'distro': 'Fedora-20', } }, - "conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base.cfg', + "conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base_x86_64.cfg', "image_dir": self.topdir + '/compose/Server/%(arch)s/images', "relative_image_dir": 'Server/%(arch)s/images', "link_type": 'hardlink-or-copy', @@ -648,7 +648,7 @@ class TestImageBuildPhase(PungiTestCase): 'can_fail': ['x86_64'], } }, - "conf_file": self.topdir + '/work/image-build/Server-optional/docker_Fedora-Docker-Base.cfg', + "conf_file": self.topdir + '/work/image-build/Server-optional/docker_Fedora-Docker-Base_x86_64.cfg', "image_dir": self.topdir + '/compose/Server-optional/%(arch)s/images', "relative_image_dir": 'Server-optional/%(arch)s/images', "link_type": 'hardlink-or-copy', @@ -708,7 +708,7 @@ class TestImageBuildPhase(PungiTestCase): 'can_fail': ['amd64', 'x86_64'], } }, - "conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base.cfg', + "conf_file": self.topdir + '/work/image-build/Server/docker_Fedora-Docker-Base_amd64-x86_64.cfg', "image_dir": self.topdir + '/compose/Server/%(arch)s/images', "relative_image_dir": 'Server/%(arch)s/images', "link_type": 'hardlink-or-copy',