Fail the introspection command if introspection has failed

Currently it only prints an error message, but exists with success.
This makes it impossible to use this command in any kind of automated
scripts or test it in our gate. This patch makes it raise an exception.

Change-Id: I150c87252a48a8062aa7ef04c7a52433dd5ee37d
This commit is contained in:
Dmitry Tantsur 2015-12-04 14:03:15 +01:00
parent 2d7017ab71
commit ad470c343e
3 changed files with 29 additions and 4 deletions

View File

@ -48,3 +48,7 @@ class RootUserExecution(Exception):
class InvalidConfiguration(ValueError):
"""Invalid parameters were specified for the deployment"""
pass
class IntrospectionError(RuntimeError):
"""Introspection failed"""

View File

@ -458,6 +458,7 @@ class TestStartBaremetalIntrospectionBulk(fakes.TestBaremetal):
client.node.list.return_value = [
mock.Mock(uuid="ABCDEFGH", provision_state="manageable")
]
get_status_mock.return_value = {'finished': True, 'error': None}
parsed_args = self.check_parser(self.cmd, [], [])
self.cmd.take_action(parsed_args)
@ -465,6 +466,25 @@ class TestStartBaremetalIntrospectionBulk(fakes.TestBaremetal):
inspection_mock.assert_called_once_with(
'ABCDEFGH', base_url=None, auth_token='TOKEN')
@mock.patch.object(baremetal.inspector_client, 'get_status', autospec=True)
@mock.patch.object(baremetal.inspector_client, 'introspect', autospec=True)
def test_introspect_bulk_failed(self, inspection_mock, get_status_mock):
client = self.app.client_manager.tripleoclient.baremetal
client.node.list.return_value = [
mock.Mock(uuid="ABCDEFGH", provision_state="manageable")
]
get_status_mock.return_value = {'finished': True,
'error': 'fake error'}
parsed_args = self.check_parser(self.cmd, [], [])
self.assertRaisesRegexp(exceptions.IntrospectionError,
'ABCDEFGH: fake error',
self.cmd.take_action, parsed_args)
inspection_mock.assert_called_once_with(
'ABCDEFGH', base_url=None, auth_token='TOKEN')
@mock.patch('tripleoclient.utils.wait_for_node_introspection',
autospec=True)
@mock.patch('tripleoclient.utils.wait_for_provision_state',

View File

@ -238,7 +238,7 @@ class StartBaremetalIntrospectionBulk(IntrospectionParser, command.Command):
time.sleep(5)
print("Waiting for introspection to finish...")
has_errors = False
errors = []
for uuid, status in utils.wait_for_node_introspection(
inspector_client, auth_token, parsed_args.inspector_url,
node_uuids):
@ -248,7 +248,7 @@ class StartBaremetalIntrospectionBulk(IntrospectionParser, command.Command):
else:
print("Introspection for UUID {0} finished with error: {1}"
.format(uuid, status['error']))
has_errors = True
errors.append("%s: %s" % (uuid, status['error']))
print("Setting manageable nodes to available...")
@ -261,8 +261,9 @@ class StartBaremetalIntrospectionBulk(IntrospectionParser, command.Command):
'available', skipped_states=("available", "active")):
print("Node {0} has been set to available.".format(uuid))
if has_errors:
print("Introspection completed with errors.")
if errors:
raise exceptions.IntrospectionError(
"Introspection completed with errors:\n%s" % '\n'.join(errors))
else:
print("Introspection completed.")