def test_run_random_checks_after(self): status = {'machines': {}} def perform(foo_bar_self, client, foo): status['machines'].update( {'0': { 'machine-status': { 'current': 'provisioning error' } }}) with client_and_plan() as (client, cfe_mock, plan_file): foo_bar = FooBarAction(client) models = client._backend.controller_state.models model_state = models[client.model_name] with patch.object(model_state, 'get_status_dict', return_value=status, autospec=True): with patch.object(FooBarAction, 'perform', perform): with patch_actions([('one', foo_bar)]): with self.assertRaises(ProvisioningError): run_random(plan_file, 'fasd', 'juju1', 1, None, unsafe=False)
def test_run_random(self): with client_and_plan() as (cur_client, cfe_mock, plan_file): foo_bar = FooBarAction(cur_client) foo_bar_raise = FooBarAction(cur_client, wait_for=True) with patch_actions([('one', foo_bar), ('two', foo_bar_raise)]) as actions: with self.assertRaises(WaitForException): with patch.object(actions, 'list_arbitrary_actions', side_effect=[ [('one', foo_bar)], [('two', foo_bar_raise)], ]): run_random(plan_file, 'fasd', None, 3, None, unsafe=False) with open(plan_file) as f: plan = yaml.load(f) self.assertIs(True, foo_bar.performed) cfe_mock.assert_called_once_with(None, 'fasd') self.assertEqual(plan, [{ 'one': { 'foo': 'bar' } }, { 'two': { 'foo': 'bar' } }])
def test_run_random_checks_before(self): error_status = { 'machines': { '0': { 'machine-status': { 'current': 'provisioning error', } } } } with client_and_plan() as (client, cfe_mock, plan_file): foo_bar_raise = FooBarAction(client, raise_exception=True) models = client._backend.controller_state.models model_state = models[client.model_name] with patch.object(model_state, 'get_status_dict', return_value=error_status, autospec=True): with self.assertRaises(ProvisioningError): with patch_actions([('one', foo_bar_raise)]): run_random(plan_file, 'fasd', 'juju1', 1, None, unsafe=False)
def test_run_random_unsafe_true(self): with client_and_plan() as (cur_client, cfe_mock, plan_file): with patch('hammer_time.hammer_time.default_actions', wraps=default_actions) as da_mock: with patch.object(RunAvailable, 'iter_blocking_state', return_value=iter([])): run_random(plan_file, 'fasd', None, 3, None, unsafe=True) da_mock.assert_called_once_with(True)
def test_run_random_action_exception(self): # Even when a step raises an exception, its plan is still written. with client_and_plan() as (cur_client, cfe_mock, plan_file): foo_bar = FooBarAction(cur_client, raise_exception=True) with patch_actions([('one', foo_bar)]): with self.assertRaises(Exception): run_random(plan_file, 'fasd', None, 3, None, unsafe=False) with open(plan_file) as f: plan = yaml.load(f) cfe_mock.assert_called_once_with(None, 'fasd') self.assertEqual(plan, [{'one': {'foo': 'bar'}}])
def test_run_random_force_action(self): with client_and_plan() as (cur_client, cfe_mock, plan_file): run_random(plan_file, 'fasd', None, 1, 'add_remove_many_machines', unsafe=False) with open(plan_file) as f: plan = yaml.load(f) self.assertEqual(plan, [{'add_remove_many_machines': {}}])
def test_run_random_juju_bin(self): with client_and_plan() as (cur_client, cfe_mock, plan_file): foo_bar = FooBarAction(cur_client) with patch_actions([('one', foo_bar)]): run_random(plan_file, 'fasd', 'juju1', 3, None, unsafe=False) cfe_mock.assert_called_once_with('juju1', 'fasd')
def test_run_random_unsafe_false(self): with client_and_plan() as (cur_client, cfe_mock, plan_file): with patch('hammer_time.hammer_time.default_actions', wraps=default_actions) as da_mock: run_random(plan_file, 'fasd', None, 3, None, unsafe=False) da_mock.assert_called_once_with(False)