diff --git a/fuel_agent/tests/test_build_utils.py b/fuel_agent/tests/test_build_utils.py index 3a9ec677..7aa92984 100644 --- a/fuel_agent/tests/test_build_utils.py +++ b/fuel_agent/tests/test_build_utils.py @@ -173,6 +173,22 @@ class BuildUtilsTestCase(unittest2.TestCase): self.assertEqual('chroot', mock_files.call_args[0][0]) self.assertEqual(files, set(mock_files.call_args[0][1])) + @mock.patch('fuel_agent.utils.build.open', + create=True, new_callable=mock.mock_open) + @mock.patch('fuel_agent.utils.build.yaml.safe_dump') + @mock.patch('fuel_agent.utils.build.yaml.safe_load', + return_value={'cloud_init_modules': ['write-files', 'ssh'], + 'cloud_config_modules': ['runcmd'] + } + ) + def test_fix_cloud_init_config(self, mock_yaml_load, mock_yaml_dump, + mock_open): + bu.fix_cloud_init_config('fake_path') + mock_yaml_dump.assert_called_once_with({ + 'cloud_init_modules': ['ssh'], + 'cloud_config_modules': ['runcmd', 'write-files'] + }, mock.ANY, default_flow_style=False) + @mock.patch('fuel_agent.utils.build.os.symlink') @mock.patch('fuel_agent.utils.build.os.mkdir') @mock.patch('fuel_agent.utils.build.open', @@ -181,7 +197,10 @@ class BuildUtilsTestCase(unittest2.TestCase): @mock.patch.object(bu, 'clean_apt_settings') @mock.patch.object(bu, 'remove_files') @mock.patch.object(utils, 'execute') - def test_do_post_inst(self, mock_exec, mock_files, mock_clean, mock_path, + @mock.patch('fuel_agent.utils.build.yaml.safe_dump') + @mock.patch('fuel_agent.utils.build.yaml.safe_load') + def test_do_post_inst(self, mock_yaml_load, mock_yaml_dump, mock_exec, + mock_files, mock_clean, mock_path, mock_open, mock_mkdir, mock_symlink): mock_path.join.return_value = 'fake_path' mock_path.exists.return_value = True @@ -223,6 +242,7 @@ class BuildUtilsTestCase(unittest2.TestCase): mock.call('chroot', 'etc/init/mcollective.override'), mock.call('chroot', 'etc/systemd/system'), mock.call('chroot', 'etc/systemd/system/mcollective.service'), + mock.call('chroot', 'etc/cloud/cloud.cfg'), mock.call('chroot', 'var/lib/cloud'), mock.call('fake_path', 'data'), mock.call('fake_path', 'data', 'upgraded-network'), diff --git a/fuel_agent/utils/build.py b/fuel_agent/utils/build.py index a9dca3d3..36c9f213 100644 --- a/fuel_agent/utils/build.py +++ b/fuel_agent/utils/build.py @@ -177,6 +177,18 @@ def clean_apt_settings(chroot, allow_unsigned_file='allow_unsigned_packages', clean_dirs(chroot, dirs) +def fix_cloud_init_config(config_path): + # NOTE(mzhnichkov): change an order of executing cloud-init modules + # this change is suitable for cloud-init packages from trust/xenial + with open(config_path, 'r') as cloud_conf: + config = yaml.safe_load(cloud_conf) + if 'write-files' in config['cloud_init_modules']: + config['cloud_init_modules'].remove('write-files') + config['cloud_config_modules'].append('write-files') + with open(config_path, 'w') as cloud_conf: + yaml.safe_dump(config, cloud_conf, default_flow_style=False) + + def do_post_inst(chroot, hashed_root_password, allow_unsigned_file='allow_unsigned_packages', force_ipv4_file='force_ipv4', @@ -201,6 +213,9 @@ def do_post_inst(chroot, hashed_root_password, if os.path.exists(os.path.join(chroot, 'etc/systemd/system')): os.symlink('/dev/null', os.path.join(chroot, 'etc/systemd/system/mcollective.service')) + cloud_init_conf = os.path.join(chroot, 'etc/cloud/cloud.cfg') + if os.path.exists(cloud_init_conf): + fix_cloud_init_config(cloud_init_conf) # NOTE(mzhnichkov): skip auto networking configuration at cloud-init stage cloud_path = os.path.join(chroot, 'var/lib/cloud') if os.path.exists(cloud_path):