Disable cloud-init network auto configuration

The previos implementation doesn't fix the problem. Cloud-init
creates /etc/network/interfaces.d/50-cloud-init.cfg which prevents
to set static IP.

Change-Id: I49d09dd37403a843adfe34be156e5e265b0f3e08
Signed-off-by: Sergii Golovatiuk <sgolovatiuk@mirantis.com>
This commit is contained in:
Sergii Golovatiuk 2016-11-16 17:32:37 +01:00
parent fee38d0cd9
commit fa49edcdae
2 changed files with 20 additions and 2 deletions

View File

@ -187,7 +187,7 @@ class BuildUtilsTestCase(unittest2.TestCase):
mock_yaml_dump.assert_called_once_with({
'cloud_init_modules': ['ssh'],
'cloud_config_modules': ['runcmd', 'write-files']
}, mock.ANY, default_flow_style=False)
}, mock.ANY, encoding='utf-8', default_flow_style=False)
@mock.patch('fuel_agent.utils.build.os.symlink')
@mock.patch('fuel_agent.utils.build.os.mkdir')
@ -214,8 +214,10 @@ class BuildUtilsTestCase(unittest2.TestCase):
allow_unsigned_file='fake_unsigned',
force_ipv4_file='fake_force_ipv4',
pipeline_depth_file='fake_pipeline_depth')
file_handle_mock = mock_open.return_value.__enter__.return_value
file_handle_mock.write.assert_called_once_with('manual\n')
mock_exec_expected_calls = [
mock.call('sed',
'-i',
@ -241,11 +243,18 @@ 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.d/'),
mock.call('chroot',
'etc/cloud/cloud.cfg.d/99-disable-network-config.cfg'),
mock.call('chroot', 'etc/cloud/cloud.cfg'),
mock.call('/', bu.GRUB2_DMRAID_SETTINGS)]
self.assertEqual(mock_path_join_expected_calls,
mock_path.join.call_args_list)
mock_symlink.assert_called_once_with('/dev/null', 'fake_path')
mock_yaml_dump.assert_called_with(mock.ANY,
mock.ANY,
encoding='utf-8',
default_flow_style=False)
@mock.patch('fuel_agent.utils.build.open',
create=True, new_callable=mock.mock_open)

View File

@ -186,7 +186,8 @@ def fix_cloud_init_config(config_path):
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)
yaml.safe_dump(config,
cloud_conf, encoding='utf-8', default_flow_style=False)
def do_post_inst(chroot, hashed_root_password,
@ -213,6 +214,14 @@ 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_cfg = os.path.join(chroot, 'etc/cloud/cloud.cfg.d/')
utils.makedirs_if_not_exists(os.path.dirname(cloud_cfg))
with open(os.path.join(
chroot,
'etc/cloud/cloud.cfg.d/99-disable-network-config.cfg'), 'w') as cf:
yaml.safe_dump({'network': {'config': 'disabled'}}, cf,
encoding='utf-8',
default_flow_style=False)
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)