Skip to content

Commit

Permalink
Update unit tests for coriolis.osmorphing.redhat
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristi1324 committed Aug 22, 2024
1 parent 3df11a2 commit d8abfcb
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion coriolis/tests/osmorphing/test_redhat.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,29 @@ def test_set_net_config_no_dhcp(
mock_add_net_udev_rules.assert_called_once_with(
mock_get_net_ifaces_info.return_value)

@mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot')
def test_has_package_installed(self, mock_exec_cmd_chroot):
result = self.morphing_tools._has_package_installed("mock_package")

self.assertEqual(
True,
result
)
mock_exec_cmd_chroot.assert_called_once_with("rpm -q mock_package")

mock_exec_cmd_chroot.reset_mock()
mock_exec_cmd_chroot.side_effect = exception.CoriolisException()

with self.assertLogs(
'coriolis.osmorphing.redhat', level=logging.DEBUG):
result = self.morphing_tools._has_package_installed("mock_package")

self.assertEqual(
False,
result
)
mock_exec_cmd_chroot.assert_called_once_with("rpm -q mock_package")

@mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot')
def test__yum_install(self, mock_exec_cmd_chroot):
self.morphing_tools._yum_install(self.package_names, self.enable_repos)
Expand Down Expand Up @@ -449,17 +472,38 @@ def test__find_yum_repos_not_found(self, mock_read_file, mock_list_dir):
with self.assertLogs('coriolis.osmorphing.redhat', level=logging.WARN):
self.morphing_tools._find_yum_repos(repos_to_enable)

@mock.patch.object(redhat.BaseRedHatMorphingTools,
'_has_package_installed')
@mock.patch.object(redhat.BaseRedHatMorphingTools, '_yum_install')
@mock.patch.object(redhat.BaseRedHatMorphingTools, '_yum_clean_all')
@mock.patch.object(base.BaseLinuxOSMorphingTools, 'pre_packages_install')
def test_pre_packages_install(self, mock_pre_packages_install,
mock_yum_clean_all, mock_yum_install):
mock_yum_clean_all, mock_yum_install,
mock_has_package_installed):
mock_has_package_installed.return_value = False

self.morphing_tools.pre_packages_install(self.package_names)

mock_pre_packages_install.assert_called_once_with(self.package_names)
mock_yum_clean_all.assert_called_once()
mock_yum_install.assert_called_once_with(['grubby'])

@mock.patch.object(redhat.BaseRedHatMorphingTools,
'_has_package_installed')
@mock.patch.object(redhat.BaseRedHatMorphingTools, '_yum_install')
@mock.patch.object(redhat.BaseRedHatMorphingTools, '_yum_clean_all')
@mock.patch.object(base.BaseLinuxOSMorphingTools, 'pre_packages_install')
def test_pre_packages_install_has_grubby(
self, mock_pre_packages_install, mock_yum_clean_all, mock_yum_install,
mock_has_package_installed):
mock_has_package_installed.return_value = True

self.morphing_tools.pre_packages_install(self.package_names)

mock_pre_packages_install.assert_called_once_with(self.package_names)
mock_yum_clean_all.assert_called_once()
mock_yum_install.assert_not_called()

@mock.patch.object(redhat.BaseRedHatMorphingTools, '_yum_install')
@mock.patch.object(redhat.BaseRedHatMorphingTools, '_get_repos_to_enable')
def test_install_packages(self, mock_get_repos_to_enable,
Expand Down

0 comments on commit d8abfcb

Please sign in to comment.