From fcf1442f71d3a5929150a9d04ef689ddfa9b70cd Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Jan 06 2020 12:30:13 +0000 Subject: Support generating ISOs when using link_type="symlink". When `link_type = "symlink"` is used, the packages are in fact symlinks to /mnt/koji. When graft points file is generated, the paths in this graft points file point to symlinks and therefore symlinks are copied into the generated ISO file instead of real files. In this commit, the code to generate the graft points file is changed so it resolves the symlink to real file stored on /mnt/koji. To make this code safer, it does such resolving only in case the symlink points outside of `compose.paths.compose.topdir()`. Therefore you can still generate ISO file with symlink pointing to file stored within the ISO file itself, although this is not done currently afaik. The main reason for this is to be able to generate ISO files even without hardlinks (which would need read-write access on /mnt/koji) and without copying all the packages from /mnt/koji to local storage. Signed-off-by: Jan Kaluza --- diff --git a/pungi/phases/createiso.py b/pungi/phases/createiso.py index 135de4f..a96e4ac 100644 --- a/pungi/phases/createiso.py +++ b/pungi/phases/createiso.py @@ -439,9 +439,9 @@ def prepare_iso(compose, arch, variant, disc_num=1, disc_count=None, split_iso_d write_discinfo(new_di_path, **data) if not disc_count or disc_count == 1: - data = iso.get_graft_points([tree_dir, iso_dir]) + data = iso.get_graft_points(compose, [tree_dir, iso_dir]) else: - data = iso.get_graft_points([iso._paths_from_list(tree_dir, split_iso_data["files"]), iso_dir]) + data = iso.get_graft_points(compose, [iso._paths_from_list(tree_dir, split_iso_data["files"]), iso_dir]) if compose.conf["createiso_break_hardlinks"]: compose.log_debug( diff --git a/pungi/phases/extra_isos.py b/pungi/phases/extra_isos.py index 0a13801..7f0cb19 100644 --- a/pungi/phases/extra_isos.py +++ b/pungi/phases/extra_isos.py @@ -182,7 +182,7 @@ def get_iso_contents( buildinstall_dir = os.path.join(buildinstall_dir, variant.uid) copy_boot_images(buildinstall_dir, iso_dir) - files = iso.get_graft_points([buildinstall_dir, iso_dir]) + files = iso.get_graft_points(compose, [buildinstall_dir, iso_dir]) # We need to point efiboot.img to compose/ tree, because it was # modified in buildinstall phase and the file in work/ has different @@ -198,19 +198,19 @@ def get_iso_contents( # Get packages... package_dir = compose.paths.compose.packages(arch, var) - for k, v in iso.get_graft_points([package_dir]).items(): + for k, v in iso.get_graft_points(compose, [package_dir]).items(): files[os.path.join(var.uid, 'Packages', k)] = v # Get repodata... tree_dir = compose.paths.compose.repository(arch, var) repo_dir = os.path.join(tree_dir, 'repodata') - for k, v in iso.get_graft_points([repo_dir]).items(): + for k, v in iso.get_graft_points(compose, [repo_dir]).items(): files[os.path.join(var.uid, 'repodata', k)] = v if inherit_extra_files: # Get extra files... extra_files_dir = compose.paths.work.extra_files_dir(arch, var) - for k, v in iso.get_graft_points([extra_files_dir]).items(): + for k, v in iso.get_graft_points(compose, [extra_files_dir]).items(): files[os.path.join(var.uid, k)] = v extra_files_dir = compose.paths.work.extra_iso_extra_files_dir(arch, variant) @@ -226,7 +226,7 @@ def get_iso_contents( ) # Add extra files specific for the ISO - files.update(iso.get_graft_points([extra_files_dir])) + files.update(iso.get_graft_points(compose, [extra_files_dir])) gp = "%s-graft-points" % iso_dir iso.write_graft_points(gp, files, exclude=["*/lost+found", "*/boot.iso"]) diff --git a/pungi/wrappers/iso.py b/pungi/wrappers/iso.py index d33e8cc..7f527a0 100644 --- a/pungi/wrappers/iso.py +++ b/pungi/wrappers/iso.py @@ -246,7 +246,7 @@ def get_volume_id(path): raise RuntimeError("Could not read Volume ID") -def get_graft_points(paths, exclusive_paths=None, exclude=None): +def get_graft_points(compose, paths, exclusive_paths=None, exclude=None): # path priority in ascending order (1st = lowest prio) # paths merge according to priority # exclusive paths override whole dirs @@ -266,6 +266,20 @@ def get_graft_points(paths, exclusive_paths=None, exclude=None): tree = _scan_tree(i) result = _merge_trees(result, tree, exclusive=True) + # Resolve possible symlinks pointing outside of the compose.topdir. + # This fixes an issue if link_type is set to "symlink" and therefore + # the RPM packages are symbolic links to /mnt/koji filesystem. + # Without this, the symbolic links would be simply copied into the ISO + # without the real RPMs. + topdir = compose.paths.compose.topdir() + for key in result.keys(): + path = result[key] + if os.path.islink(path): + real_path = os.readlink(path) + abspath = os.path.normpath(os.path.join(os.path.dirname(path), real_path)) + if not abspath.startswith(topdir): + result[key] = abspath + # TODO: exclude return result diff --git a/tests/test_extra_isos_phase.py b/tests/test_extra_isos_phase.py index 1506115..5fce3b2 100644 --- a/tests/test_extra_isos_phase.py +++ b/tests/test_extra_isos_phase.py @@ -562,7 +562,7 @@ class GetIsoContentsTest(helpers.PungiTestCase): 'work/x86_64/Server/extra-iso-extra-files': {'EULA': '/mnt/EULA'}, } - ggp.side_effect = lambda x: gp[x[0][len(self.topdir) + 1:]] + ggp.side_effect = lambda compose, x: gp[x[0][len(self.topdir) + 1:]] gp_file = os.path.join(self.topdir, 'work/x86_64/iso/my.iso-graft-points') self.assertEqual( @@ -589,7 +589,7 @@ class GetIsoContentsTest(helpers.PungiTestCase): six.assertCountEqual( self, ggp.call_args_list, - [mock.call([os.path.join(self.topdir, x)]) for x in gp] + [mock.call(self.compose, [os.path.join(self.topdir, x)]) for x in gp] ) self.assertEqual(len(wgp.call_args_list), 1) self.assertEqual(wgp.call_args_list[0][0][0], gp_file) @@ -623,7 +623,7 @@ class GetIsoContentsTest(helpers.PungiTestCase): "work/x86_64/Server/extra-iso-extra-files": {"EULA": "/mnt/EULA"}, } - ggp.side_effect = lambda x: gp[x[0][len(self.topdir) + 1:]] + ggp.side_effect = lambda compose, x: gp[x[0][len(self.topdir) + 1:]] gp_file = os.path.join(self.topdir, "work/x86_64/iso/my.iso-graft-points") self.assertEqual( @@ -652,7 +652,7 @@ class GetIsoContentsTest(helpers.PungiTestCase): six.assertCountEqual( self, ggp.call_args_list, - [mock.call([os.path.join(self.topdir, x)]) for x in gp] + [mock.call(self.compose, [os.path.join(self.topdir, x)]) for x in gp] ) self.assertEqual(len(wgp.call_args_list), 1) self.assertEqual(wgp.call_args_list[0][0][0], gp_file) @@ -684,7 +684,7 @@ class GetIsoContentsTest(helpers.PungiTestCase): 'work/src/Server/extra-iso-extra-files': {'EULA': '/mnt/EULA'}, } - ggp.side_effect = lambda x: gp[x[0][len(self.topdir) + 1:]] + ggp.side_effect = lambda compose, x: gp[x[0][len(self.topdir) + 1:]] gp_file = os.path.join(self.topdir, 'work/src/iso/my.iso-graft-points') self.assertEqual( @@ -711,7 +711,7 @@ class GetIsoContentsTest(helpers.PungiTestCase): six.assertCountEqual( self, ggp.call_args_list, - [mock.call([os.path.join(self.topdir, x)]) for x in gp] + [mock.call(self.compose, [os.path.join(self.topdir, x)]) for x in gp] ) self.assertEqual(len(wgp.call_args_list), 1) self.assertEqual(wgp.call_args_list[0][0][0], gp_file) @@ -756,7 +756,7 @@ class GetIsoContentsTest(helpers.PungiTestCase): 'images/efiboot.img': os.path.join(iso_dir, 'images/efiboot.img'), } - ggp.side_effect = lambda x: gp[x[0][len(self.topdir) + 1:]] if len(x) == 1 else bi_gp + ggp.side_effect = lambda compose, x: gp[x[0][len(self.topdir) + 1:]] if len(x) == 1 else bi_gp gp_file = os.path.join(self.topdir, 'work/x86_64/iso/my.iso-graft-points') self.assertEqual( @@ -790,7 +790,8 @@ class GetIsoContentsTest(helpers.PungiTestCase): six.assertCountEqual( self, ggp.call_args_list, - [mock.call([os.path.join(self.topdir, x)]) for x in gp] + [mock.call([bi_dir, iso_dir])] + [mock.call(self.compose, [os.path.join(self.topdir, x)]) for x in gp] + [ + mock.call(self.compose, [bi_dir, iso_dir])] ) self.assertEqual(len(wgp.call_args_list), 1) self.assertEqual(wgp.call_args_list[0][0][0], gp_file)