Fix exception that is not properly raised
This commit fixes an exception that was not properly raised, and also makes the exception more relevant. This also fixes an outstanding bug where, if the agent was not associated with a node, get_node_uuid() would fail in an unexpected manner. Change-Id: Ifca474a73dd50b5fd2242e5b7e938a5db04f27a8
This commit is contained in:
parent
123603edd9
commit
a9f2179761
|
@ -181,8 +181,8 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
|
|||
return iface_list
|
||||
|
||||
def get_node_uuid(self):
|
||||
if 'uuid' not in self.node:
|
||||
errors.HeartbeatError('Tried to heartbeat without node UUID.')
|
||||
if self.node is None or 'uuid' not in self.node:
|
||||
raise errors.UnknownNodeError()
|
||||
return self.node['uuid']
|
||||
|
||||
def list_command_results(self):
|
||||
|
|
|
@ -236,3 +236,14 @@ class VirtualMediaBootError(RESTError):
|
|||
|
||||
class ExtensionError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class UnknownNodeError(Exception):
|
||||
"""Error raised when the agent is not associated with an Ironic node."""
|
||||
|
||||
message = 'Agent is not associated with an Ironic node.'
|
||||
|
||||
def __init__(self, message=None):
|
||||
if message is not None:
|
||||
self.message = message
|
||||
super(UnknownNodeError, self).__init__(self.message)
|
||||
|
|
|
@ -284,6 +284,19 @@ class TestBaseAgent(test_base.BaseTestCase):
|
|||
|
||||
self.assertEqualEncoded(result, expected_result)
|
||||
|
||||
def test_get_node_uuid(self):
|
||||
self.agent.node = {'uuid': 'fake-node'}
|
||||
self.assertEqual('fake-node', self.agent.get_node_uuid())
|
||||
|
||||
def test_get_node_uuid_unassociated(self):
|
||||
self.assertRaises(errors.UnknownNodeError,
|
||||
self.agent.get_node_uuid)
|
||||
|
||||
def test_get_node_uuid_invalid_node(self):
|
||||
self.agent.node = {}
|
||||
self.assertRaises(errors.UnknownNodeError,
|
||||
self.agent.get_node_uuid)
|
||||
|
||||
|
||||
class TestAgentCmd(test_base.BaseTestCase):
|
||||
@mock.patch('ironic_python_agent.openstack.common.log.getLogger')
|
||||
|
|
Loading…
Reference in New Issue