Merge "Fix node check no server found record error"
This commit is contained in:
commit
e7bf8ba7c6
|
@ -230,6 +230,11 @@ class EResourceDeletion(InternalError):
|
|||
msg_fmt = _("Failed in deleting %(type)s '%(id)s': %(message)s.")
|
||||
|
||||
|
||||
class EServerNotFound(InternalError):
|
||||
# Used when deleting resources from other services
|
||||
msg_fmt = _("Failed in found %(type)s '%(id)s': %(message)s.")
|
||||
|
||||
|
||||
class EResourceOperation(InternalError):
|
||||
"""Generic exception for resource fail operation.
|
||||
|
||||
|
|
|
@ -320,6 +320,10 @@ class Node(object):
|
|||
|
||||
try:
|
||||
res = pb.Profile.check_object(context, self)
|
||||
except exc.EServerNotFound as ex:
|
||||
self.set_status(context, consts.NS_ERROR, six.text_type(ex),
|
||||
physical_id=None)
|
||||
return True
|
||||
except exc.EResourceOperation as ex:
|
||||
self.set_status(context, consts.NS_ERROR, six.text_type(ex))
|
||||
return False
|
||||
|
|
|
@ -1425,9 +1425,14 @@ class ServerProfile(base.Profile):
|
|||
try:
|
||||
server = self.compute(obj).server_get(obj.physical_id)
|
||||
except exc.InternalError as ex:
|
||||
raise exc.EResourceOperation(op='checking', type='server',
|
||||
id=obj.physical_id,
|
||||
message=six.text_type(ex))
|
||||
if "No Server found" in six.text_type(ex):
|
||||
raise exc.EServerNotFound(type='server',
|
||||
id=obj.physical_id,
|
||||
message=six.text_type(ex))
|
||||
else:
|
||||
raise exc.EResourceOperation(op='checking', type='server',
|
||||
id=obj.physical_id,
|
||||
message=six.text_type(ex))
|
||||
|
||||
if (server is None or server.status != 'ACTIVE'):
|
||||
return False
|
||||
|
|
|
@ -575,6 +575,26 @@ class TestNode(base.SenlinTestCase):
|
|||
|
||||
self.assertFalse(res)
|
||||
|
||||
@mock.patch.object(nodem.Node, 'set_status')
|
||||
@mock.patch.object(pb.Profile, 'check_object')
|
||||
def test_node_check_no_server(self, mock_check, mock_status):
|
||||
node = nodem.Node('node1', PROFILE_ID, '')
|
||||
node.physical_id = 'd94d6333-82e6-4f87-b7ab-b786776df9d1'
|
||||
|
||||
err = exception.EServerNotFound(type='server',
|
||||
id=node.physical_id,
|
||||
message='No Server found')
|
||||
mock_check.side_effect = err
|
||||
|
||||
res = node.do_check(self.context)
|
||||
|
||||
self.assertTrue(res)
|
||||
mock_status.assert_called_once_with(
|
||||
self.context, consts.NS_ERROR,
|
||||
"Failed in found server '%s': No Server found."
|
||||
% node.physical_id,
|
||||
physical_id=None)
|
||||
|
||||
@mock.patch.object(nodem.Node, 'set_status')
|
||||
@mock.patch.object(pb.Profile, 'recover_object')
|
||||
def test_node_recover_new_object(self, mock_recover, mock_status):
|
||||
|
|
|
@ -1105,6 +1105,32 @@ class TestNovaServerBasic(base.SenlinTestCase):
|
|||
cc.server_get.assert_called_with('FAKE_ID')
|
||||
self.assertTrue(res)
|
||||
|
||||
def test_do_check_no_physical_id(self):
|
||||
obj = mock.Mock(physical_id=None)
|
||||
profile = server.ServerProfile('t', self.spec)
|
||||
|
||||
# do it
|
||||
res = profile.do_check(obj)
|
||||
|
||||
self.assertFalse(res)
|
||||
|
||||
def test_do_check_no_server(self):
|
||||
profile = server.ServerProfile('t', self.spec)
|
||||
cc = mock.Mock()
|
||||
err = exc.InternalError(code=404, message='No Server found')
|
||||
cc.server_get.side_effect = err
|
||||
profile._computeclient = cc
|
||||
node_obj = mock.Mock(physical_id='FAKE_ID')
|
||||
|
||||
ex = self.assertRaises(exc.EServerNotFound,
|
||||
profile.do_check,
|
||||
node_obj)
|
||||
|
||||
self.assertEqual("Failed in found server 'FAKE_ID': "
|
||||
"No Server found.",
|
||||
six.text_type(ex))
|
||||
cc.server_get.assert_called_once_with('FAKE_ID')
|
||||
|
||||
@mock.patch.object(server.ServerProfile, 'do_delete')
|
||||
@mock.patch.object(server.ServerProfile, 'do_create')
|
||||
def test_do_recover_operation_is_none(self, mock_create, mock_delete):
|
||||
|
|
Loading…
Reference in New Issue