buildinstall: Log message for boot config change

JIRA: COMPOSE-3945
Signed-off-by: Haibo Lin <hlin@redhat.com>
This commit is contained in:
Haibo Lin 2019-11-21 11:39:02 +08:00
parent 0c040e0a69
commit 6afbe6d20a
4 changed files with 14 additions and 6 deletions

View File

@ -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"))

View File

@ -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)

View File

@ -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"

View File

@ -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(