diff --git a/pungi/phases/buildinstall.py b/pungi/phases/buildinstall.py index e2f4ff07..6485a82b 100644 --- a/pungi/phases/buildinstall.py +++ b/pungi/phases/buildinstall.py @@ -255,7 +255,7 @@ BOOT_CONFIGS = [ ] -def tweak_configs(path, volid, ks_file, configs=BOOT_CONFIGS): +def tweak_configs(path, volid, ks_file, configs=BOOT_CONFIGS, logger=None): volid_escaped = volid.replace(" ", r"\x20").replace("\\", "\\\\") volid_escaped_2 = volid_escaped.replace("\\", "\\\\") found_configs = [] @@ -266,7 +266,7 @@ def tweak_configs(path, volid, ks_file, configs=BOOT_CONFIGS): found_configs.append(config) with open(config_path, "r") as f: - data = f.read() + data = original_data = f.read() os.unlink(config_path) # break hadlink by removing file writing a new one # double-escape volid in yaboot.conf @@ -283,6 +283,9 @@ def tweak_configs(path, volid, ks_file, configs=BOOT_CONFIGS): with open(config_path, "w") as f: f.write(data) + if logger and data != original_data: + logger.info('Boot config %s changed' % config_path) + return found_configs @@ -311,7 +314,7 @@ def tweak_buildinstall(compose, src, dst, arch, variant, label, volid, kickstart ) run(cmd) - found_configs = tweak_configs(tmp_dir, volid, kickstart_file) + found_configs = tweak_configs(tmp_dir, volid, kickstart_file, logger=compose._logger) if kickstart_file and found_configs: shutil.copy2(kickstart_file, os.path.join(dst, "ks.cfg")) diff --git a/pungi_utils/patch_iso.py b/pungi_utils/patch_iso.py index 789bf8d9..3e55affd 100644 --- a/pungi_utils/patch_iso.py +++ b/pungi_utils/patch_iso.py @@ -96,7 +96,7 @@ def run(log, opts): # if ks.cfg is detected, patch syslinux + grub to use it if 'ks.cfg' in graft_points: log.info('Adding ks.cfg to boot configs') - tweak_configs(work_dir, volume_id, graft_points['ks.cfg']) + tweak_configs(work_dir, volume_id, graft_points['ks.cfg'], logger=log) arch = opts.force_arch or get_arch(log, work_dir) diff --git a/tests/test_buildinstall.py b/tests/test_buildinstall.py index 28634bf5..cf73c760 100644 --- a/tests/test_buildinstall.py +++ b/tests/test_buildinstall.py @@ -1028,12 +1028,17 @@ class TestSymlinkIso(PungiTestCase): class TestTweakConfigs(PungiTestCase): def test_tweak_configs(self): + logger = mock.Mock() configs = [] for cfg in BOOT_CONFIGS: if 'yaboot' not in cfg: configs.append(os.path.join(self.topdir, cfg)) touch(configs[-1], ':LABEL=baz') - tweak_configs(self.topdir, 'new volid', os.path.join(self.topdir, 'ks.cfg')) + found_configs = tweak_configs(self.topdir, 'new volid', os.path.join(self.topdir, 'ks.cfg'), logger=logger) + self.assertEqual( + logger.info.call_args_list, + [mock.call('Boot config %s changed' % os.path.join(self.topdir, cfg)) for cfg in found_configs] + ) for cfg in configs: self.assertFileContent( cfg, ":LABEL=new\\x20volid ks=hd:LABEL=new\\x20volid:/ks.cfg\n" diff --git a/tests/test_patch_iso.py b/tests/test_patch_iso.py index dcd2a31b..480b94f3 100644 --- a/tests/test_patch_iso.py +++ b/tests/test_patch_iso.py @@ -224,7 +224,7 @@ class TestPatchingIso(unittest.TestCase): input_charset='utf-8', volid='foobar')]) self.assertEqual(tweak_configs.call_args_list, - [mock.call(ANYTHING, 'foobar', 'path/to/ks.cfg')]) + [mock.call(ANYTHING, 'foobar', 'path/to/ks.cfg', logger=log)]) self.assertEqual(copy_all.mock_calls, [mock.call('mounted-iso-dir', ANYTHING)]) self.assertEqual(