def test_rename_bootstrap_profile_for_systems(mocker, exists): mock_calls = mock.Mock() mocker.patch("octane.util.cobbler.profile_exists", new=mock_calls.exists) mock_calls.exists.return_value = exists mocker.patch("octane.util.cobbler.get_default_profile", new=mock_calls.default) mock_calls.default.return_value = "ubuntu" mocker.patch("octane.util.cobbler.profile_copy", new=mock_calls.copy) mocker.patch("octane.util.cobbler.systems_edit_profile", new=mock_calls.edit) mocker.patch("octane.util.cobbler.profile_remove", new=mock_calls.remove) with cobbler.rename_bootstrap_profile_for_systems(): mock_calls.let() calls_enter = [ mock.call.default(), mock.call.exists("bootstrap"), ] calls_exit = [ mock.call.edit("bootstrap", "ubuntu"), ] if not exists: calls_enter.extend([ mock.call.copy("ubuntu", "bootstrap"), ]) calls_exit.extend([ mock.call.remove("bootstrap"), ]) expected_calls = calls_enter + [mock.call.let()] + calls_exit assert mock_calls.mock_calls == expected_calls if exists: assert not mock_calls.copy.called assert not mock_calls.remove.called
def restore(self): # NOTE(akscram): Ubuntu systems created in the 7.0 release # use the 'bootstrap' profile that was removed since 9.0. with cobbler.rename_bootstrap_profile_for_systems(): super(CobblerArchivator, self).restore() subprocess.call(["systemctl", "stop", "cobblerd"]) puppet.apply_task("cobbler")