def test_wait_with_check_errors_no_raise_exception(self): nodes = ['uuid1', 'uuid2', 'uuid3'] arglist = ['--wait'] + ['--check-errors'] + nodes verifylist = [('node', nodes), ('wait', True), ('check_errors', True)] self.client.wait_for_finish.return_value = { 'uuid1': { 'finished': True, 'error': None }, 'uuid2': { 'finished': True, 'error': None }, 'uuid3': { 'finished': True, 'error': None }, } cmd = shell.StartCommand(self.app, None) parsed_args = self.check_parser(cmd, arglist, verifylist) _c, values = cmd.take_action(parsed_args) calls = [mock.call(node) for node in nodes] self.assertEqual(calls, self.client.introspect.call_args_list) self.assertEqual([('uuid1', None), ('uuid2', None), ('uuid3', None)], sorted(values))
def test_wait(self): nodes = ['uuid1', 'uuid2', 'uuid3'] arglist = ['--wait'] + nodes verifylist = [('node', nodes), ('wait', True)] self.client.wait_for_finish.return_value = { 'uuid1': { 'finished': True, 'error': None }, 'uuid2': { 'finished': True, 'error': 'boom' }, 'uuid3': { 'finished': True, 'error': None }, } cmd = shell.StartCommand(self.app, None) parsed_args = self.check_parser(cmd, arglist, verifylist) _c, values = cmd.take_action(parsed_args) calls = [ mock.call(node, new_ipmi_password=None, new_ipmi_username=None) for node in nodes ] self.assertEqual(calls, self.client.introspect.call_args_list) self.assertEqual([('uuid1', None), ('uuid2', 'boom'), ('uuid3', None)], sorted(values))
def test_introspect_many(self): arglist = ['uuid1', 'uuid2', 'uuid3'] verifylist = [('node', arglist)] cmd = shell.StartCommand(self.app, None) parsed_args = self.check_parser(cmd, arglist, verifylist) cmd.take_action(parsed_args) calls = [mock.call(node) for node in arglist] self.assertEqual(calls, self.client.introspect.call_args_list)
def test_introspect_one(self): arglist = ['uuid1'] verifylist = [('node', arglist)] cmd = shell.StartCommand(self.app, None) parsed_args = self.check_parser(cmd, arglist, verifylist) result = cmd.take_action(parsed_args) self.assertEqual((shell.StartCommand.COLUMNS, []), result) self.client.introspect.assert_called_once_with('uuid1')
def test_introspect_many_fails(self): arglist = ['uuid1', 'uuid2', 'uuid3'] verifylist = [('node', arglist)] self.client.introspect.side_effect = (None, RuntimeError()) cmd = shell.StartCommand(self.app, None) parsed_args = self.check_parser(cmd, arglist, verifylist) self.assertRaises(RuntimeError, cmd.take_action, parsed_args) calls = [mock.call(node) for node in arglist[:2]] self.assertEqual(calls, self.client.introspect.call_args_list)
def test_introspect_set_credentials(self): uuids = ['uuid1', 'uuid2', 'uuid3'] arglist = ['--new-ipmi-password', '1234'] + uuids verifylist = [('node', uuids), ('new_ipmi_password', '1234')] cmd = shell.StartCommand(self.app, None) parsed_args = self.check_parser(cmd, arglist, verifylist) with mock.patch('sys.stdout', write=lambda s: None): cmd.take_action(parsed_args) calls = [ mock.call(node, new_ipmi_password='******', new_ipmi_username=None) for node in uuids ] self.assertEqual(calls, self.client.introspect.call_args_list)
def test_wait_with_check_errors(self): nodes = ['uuid1', 'uuid2', 'uuid3'] arglist = ['--wait'] + ['--check-errors'] + nodes verifylist = [('node', nodes), ('wait', True), ('check_errors', True)] self.client.wait_for_finish.return_value = { 'uuid1': { 'finished': True, 'error': None }, 'uuid2': { 'finished': True, 'error': 'boom' }, 'uuid3': { 'finished': True, 'error': None }, } cmd = shell.StartCommand(self.app, None) parsed_args = self.check_parser(cmd, arglist, verifylist) msg = "Introspection failed for" self.assertRaisesRegex(Exception, msg, cmd.take_action, parsed_args)
def test_check_errors_alone(self): nodes = ['uuid1', 'uuid2', 'uuid3'] arglist = ['--check-errors'] + nodes verifylist = [('node', nodes), ('check_errors', True)] self.client.wait_for_finish.return_value = { 'uuid1': { 'finished': True, 'error': None }, 'uuid2': { 'finished': True, 'error': 'boom' }, 'uuid3': { 'finished': True, 'error': None }, } cmd = shell.StartCommand(self.app, None) parsed_args = self.check_parser(cmd, arglist, verifylist) msg = "--check-errors can only be used with --wait" self.assertRaisesRegex(exceptions.CommandError, msg, cmd.take_action, parsed_args)