buildinstall: Log message for boot config change
JIRA: COMPOSE-3945 Signed-off-by: Haibo Lin <hlin@redhat.com>
This commit is contained in:
parent
0c040e0a69
commit
6afbe6d20a
@ -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 = volid.replace(" ", r"\x20").replace("\\", "\\\\")
|
||||||
volid_escaped_2 = volid_escaped.replace("\\", "\\\\")
|
volid_escaped_2 = volid_escaped.replace("\\", "\\\\")
|
||||||
found_configs = []
|
found_configs = []
|
||||||
@ -266,7 +266,7 @@ def tweak_configs(path, volid, ks_file, configs=BOOT_CONFIGS):
|
|||||||
found_configs.append(config)
|
found_configs.append(config)
|
||||||
|
|
||||||
with open(config_path, "r") as f:
|
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
|
os.unlink(config_path) # break hadlink by removing file writing a new one
|
||||||
|
|
||||||
# double-escape volid in yaboot.conf
|
# 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:
|
with open(config_path, "w") as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
|
|
||||||
|
if logger and data != original_data:
|
||||||
|
logger.info('Boot config %s changed' % config_path)
|
||||||
|
|
||||||
return found_configs
|
return found_configs
|
||||||
|
|
||||||
|
|
||||||
@ -311,7 +314,7 @@ def tweak_buildinstall(compose, src, dst, arch, variant, label, volid, kickstart
|
|||||||
)
|
)
|
||||||
run(cmd)
|
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:
|
if kickstart_file and found_configs:
|
||||||
shutil.copy2(kickstart_file, os.path.join(dst, "ks.cfg"))
|
shutil.copy2(kickstart_file, os.path.join(dst, "ks.cfg"))
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ def run(log, opts):
|
|||||||
# if ks.cfg is detected, patch syslinux + grub to use it
|
# if ks.cfg is detected, patch syslinux + grub to use it
|
||||||
if 'ks.cfg' in graft_points:
|
if 'ks.cfg' in graft_points:
|
||||||
log.info('Adding ks.cfg to boot configs')
|
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)
|
arch = opts.force_arch or get_arch(log, work_dir)
|
||||||
|
|
||||||
|
@ -1028,12 +1028,17 @@ class TestSymlinkIso(PungiTestCase):
|
|||||||
class TestTweakConfigs(PungiTestCase):
|
class TestTweakConfigs(PungiTestCase):
|
||||||
|
|
||||||
def test_tweak_configs(self):
|
def test_tweak_configs(self):
|
||||||
|
logger = mock.Mock()
|
||||||
configs = []
|
configs = []
|
||||||
for cfg in BOOT_CONFIGS:
|
for cfg in BOOT_CONFIGS:
|
||||||
if 'yaboot' not in cfg:
|
if 'yaboot' not in cfg:
|
||||||
configs.append(os.path.join(self.topdir, cfg))
|
configs.append(os.path.join(self.topdir, cfg))
|
||||||
touch(configs[-1], ':LABEL=baz')
|
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:
|
for cfg in configs:
|
||||||
self.assertFileContent(
|
self.assertFileContent(
|
||||||
cfg, ":LABEL=new\\x20volid ks=hd:LABEL=new\\x20volid:/ks.cfg\n"
|
cfg, ":LABEL=new\\x20volid ks=hd:LABEL=new\\x20volid:/ks.cfg\n"
|
||||||
|
@ -224,7 +224,7 @@ class TestPatchingIso(unittest.TestCase):
|
|||||||
input_charset='utf-8',
|
input_charset='utf-8',
|
||||||
volid='foobar')])
|
volid='foobar')])
|
||||||
self.assertEqual(tweak_configs.call_args_list,
|
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,
|
self.assertEqual(copy_all.mock_calls,
|
||||||
[mock.call('mounted-iso-dir', ANYTHING)])
|
[mock.call('mounted-iso-dir', ANYTHING)])
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
Loading…
Reference in New Issue
Block a user