Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions coriolis/osmorphing/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,9 @@ def _create_cloudinit_user(self):
if not self._check_user_exists(cloud_user):
self._exec_cmd_chroot("useradd %s" % cloud_user)

def _has_systemd_chroot(self):
return self._test_path("/lib/systemd/system")

def _configure_cloud_init(self):
cloud_cfg_mods = {}
if "cloud-init" not in self.get_packages()[0]:
Expand All @@ -468,6 +471,9 @@ def _configure_cloud_init(self):

self._write_cloud_init_mods_config(cloud_cfg_mods)

if self._has_systemd_chroot():
self._enable_systemd_service("cloud-init")

def _test_path_chroot(self, path):
# This method uses _exec_cmd_chroot() instead of SFTP stat()
# because in some situations, the SSH user used may not have
Expand Down
8 changes: 0 additions & 8 deletions coriolis/osmorphing/debian.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ def _compose_netplan_cfg(self, nics_info):
}
return yaml.dump(cfg, default_flow_style=False)

def _has_systemd_chroot(self):
return self._test_path("/lib/systemd/system")

def set_net_config(self, nics_info, dhcp):
if not dhcp:
LOG.info("Setting static IP configuration")
Expand Down Expand Up @@ -127,11 +124,6 @@ def set_net_config(self, nics_info, dhcp):
cfg_name = "%s/coriolis_netplan.yaml" % self.netplan_base
self._write_file_sudo(cfg_name, new_cfg)

def _configure_cloud_init(self):
super(BaseDebianMorphingTools, self)._configure_cloud_init()
if self._has_systemd_chroot():
self._enable_systemd_service("cloud-init")

def get_installed_packages(self):
cmd = "dpkg-query -f '${binary:Package}\\n' -W"
try:
Expand Down
5 changes: 0 additions & 5 deletions coriolis/osmorphing/redhat.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,6 @@ def _set_network_nozeroconf_config(self):
network_cfg["NOZEROCONF"] = "yes"
self._write_config_file(network_cfg_file, network_cfg)

def _configure_cloud_init(self):
super(BaseRedHatMorphingTools, self)._configure_cloud_init()
if self._has_systemd():
self._enable_systemd_service("cloud-init")

def _write_config_file(self, chroot_path, config_data):
content = self._get_config_file_content(config_data)
self._write_file_sudo(chroot_path, content)
Expand Down
5 changes: 0 additions & 5 deletions coriolis/osmorphing/suse.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,6 @@ def _has_systemd(self):
except Exception:
return False

def _configure_cloud_init(self):
super(BaseSUSEMorphingTools, self)._configure_cloud_init()
if self._has_systemd():
self._enable_systemd_service("cloud-init")

def post_packages_install(self, package_names):
self._configure_cloud_init()
self._run_dracut()
Expand Down
24 changes: 19 additions & 5 deletions coriolis/tests/osmorphing/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,8 @@ def test__create_cloudinit_user_already_exists(
["vim"],
{},
False,
None
None,
False
),
(
["cloud-init"],
Expand All @@ -724,16 +725,21 @@ def test__create_cloudinit_user_already_exists(
"ssh_pwauth": True,
"users": None,
"network": {"config": "disabled"},
}
},
True
),
(
["cloud-init", "vim"],
{"retain_user_credentials": False, "set_dhcp": True},
True,
{}
{},
False
),
)
@ddt.unpack
@mock.patch.object(base.BaseLinuxOSMorphingTools,
'_enable_systemd_service')
@mock.patch.object(base.BaseLinuxOSMorphingTools, '_has_systemd_chroot')
@mock.patch.object(base.BaseLinuxOSMorphingTools,
'_write_cloud_init_mods_config')
@mock.patch.object(base.BaseLinuxOSMorphingTools, '_create_cloudinit_user')
Expand All @@ -745,12 +751,15 @@ def test__create_cloudinit_user_already_exists(
@mock.patch.object(base.BaseLinuxOSMorphingTools, 'get_packages')
def test__configure_cloud_init(
self, returned_packages, osmorphing_params, creates_cloudinit_user,
expected_result, mock_get_packages,
expected_result, has_systemd_chroot, mock_get_packages,
mock__disable_installer_cloud_config,
mock__ensure_cloud_init_not_disabled, mock__reset_cloud_init_run,
mock__create_cloudinit_user, mock__write_cloud_init_mods_config):
mock__create_cloudinit_user, mock__write_cloud_init_mods_config,
mock__has_systemd_chroot, mock__enable_systemd_service
):
mock_get_packages.return_value = returned_packages
self.os_morphing_tools._osmorphing_parameters = osmorphing_params
mock__has_systemd_chroot.return_value = has_systemd_chroot

self.os_morphing_tools._configure_cloud_init()

Expand All @@ -763,6 +772,11 @@ def test__configure_cloud_init(
mock__create_cloudinit_user.assert_called_once()
else:
mock__create_cloudinit_user.assert_not_called()
if has_systemd_chroot:
mock__enable_systemd_service.assert_called_once_with(
"cloud-init")
else:
mock__enable_systemd_service.assert_not_called()
else:
mock__disable_installer_cloud_config.assert_not_called()

Expand Down
11 changes: 0 additions & 11 deletions coriolis/tests/osmorphing/test_debian.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,6 @@ def test_set_net_config_no_dhcp(
mock_disable_predictable_nic_names.assert_not_called()
mock_write_file_sudo.assert_not_called()

@mock.patch.object(debian.BaseDebianMorphingTools,
'_enable_systemd_service')
@mock.patch.object(debian.BaseDebianMorphingTools, '_has_systemd_chroot')
def test__configure_cloud_init(
self, mock__has_systemd_chroot, mock__enable_systemd_service):
mock__has_systemd_chroot.return_value = True

self.morpher._configure_cloud_init()

mock__enable_systemd_service.assert_called_once_with("cloud-init")

@mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot')
def test_get_installed_packages(self, mock_exec_cmd_chroot):
mock_exec_cmd_chroot.return_value = \
Expand Down
11 changes: 0 additions & 11 deletions coriolis/tests/osmorphing/test_redhat.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,17 +483,6 @@ def test__set_network_nozeroconf_config(
mock_write_config_file.assert_called_once_with(
"etc/sysconfig/network", mock_read_config_file.return_value)

@mock.patch.object(redhat.BaseRedHatMorphingTools,
'_enable_systemd_service')
@mock.patch.object(redhat.BaseRedHatMorphingTools, '_has_systemd')
def test__configure_cloud_init(
self, mock__has_systemd, mock__enable_systemd_service):
mock__has_systemd.return_value = True

self.morphing_tools._configure_cloud_init()

mock__enable_systemd_service.assert_called_once_with("cloud-init")

@mock.patch.object(
redhat.BaseRedHatMorphingTools, '_get_config_file_content'
)
Expand Down
10 changes: 0 additions & 10 deletions coriolis/tests/osmorphing/test_suse.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,6 @@ def test__has_systemd_with_exception(self, mock_exec_cmd_chroot):

self.assertFalse(result)

@mock.patch.object(suse.BaseSUSEMorphingTools, '_enable_systemd_service')
@mock.patch.object(suse.BaseSUSEMorphingTools, '_has_systemd')
def test__configure_cloud_init(
self, mock__has_systemd, mock__enable_systemd_service):
mock__has_systemd.return_value = True

self.morphing_tools._configure_cloud_init()

mock__enable_systemd_service.assert_called_once_with("cloud-init")

@mock.patch.object(suse.BaseSUSEMorphingTools, '_configure_cloud_init')
@mock.patch.object(suse.BaseSUSEMorphingTools, '_run_dracut')
@mock.patch.object(base.BaseLinuxOSMorphingTools, 'post_packages_install')
Expand Down