Resolved server and instance status redundancy

Instance and server resource's _check_active() methods were
stripping off an extra '(STATUS)' string from the status.
This change moves the code of consistently handling status
to the nova client in heat. So, both the resources need not
perform any exra stuff to determine the status.

Change-Id: Ib527c001a2cdae90de1545ccdd56ad722c724d07
This commit is contained in:
Unmesh Gurjar 2014-08-18 15:11:00 +05:30
parent 336d739486
commit 8cad2d1798
4 changed files with 34 additions and 15 deletions

View File

@ -117,6 +117,15 @@ class NovaClientPlugin(client_plugin.ClientPlugin):
if ip['version'] == ip_version:
return ip['addr']
def get_status(self, server):
'''
Return the server's status.
:param server: server object
:returns: status as a string
'''
# Some clouds append extra (STATUS) strings to the status, strip it
return server.status.split('(')[0]
def get_flavor_id(self, flavor):
'''
Get the id for the specified flavor name.

View File

@ -624,21 +624,21 @@ class Instance(resource.Resource):
def _check_active(self, server):
cp = self.client_plugin()
if server.status != 'ACTIVE':
status = cp.get_status(server)
if status != 'ACTIVE':
cp.refresh_server(server)
status = cp.get_status(server)
if server.status == 'ACTIVE':
if status == 'ACTIVE':
return True
# Some clouds append extra (STATUS) strings to the status
short_server_status = server.status.split('(')[0]
if short_server_status in cp.deferred_server_statuses:
if status in cp.deferred_server_statuses:
return False
if server.status == 'ERROR':
if status == 'ERROR':
fault = getattr(server, 'fault', {})
raise resource.ResourceInError(
resource_status=server.status,
resource_status=status,
status_reason=_("Message: %(message)s, Code: %(code)s") % {
'message': fault.get('message', _('Unknown')),
'code': fault.get('code', _('Unknown'))

View File

@ -531,21 +531,20 @@ class Server(stack_user.StackUser):
return self._check_active(server)
def _check_active(self, server):
cp = self.client_plugin()
if server.status != 'ACTIVE':
status = cp.get_status(server)
if status != 'ACTIVE':
cp.refresh_server(server)
status = cp.get_status(server)
# Some clouds append extra (STATUS) strings to the status
short_server_status = server.status.split('(')[0]
if short_server_status in cp.deferred_server_statuses:
if status in cp.deferred_server_statuses:
return False
elif server.status == 'ACTIVE':
elif status == 'ACTIVE':
return True
elif server.status == 'ERROR':
elif status == 'ERROR':
fault = getattr(server, 'fault', {})
raise resource.ResourceInError(
resource_status=server.status,
resource_status=status,
status_reason=_("Message: %(message)s, Code: %(code)s") % {
'message': fault.get('message', _('Unknown')),
'code': fault.get('code', _('Unknown'))

View File

@ -95,6 +95,17 @@ class NovaClientPluginTests(NovaClientPluginTestCase):
self.nova_plugin.get_keypair, 'notakey')
self.m.VerifyAll()
def test_get_status(self):
server = self.m.CreateMockAnything()
server.status = 'ACTIVE'
observed = self.nova_plugin.get_status(server)
self.assertEqual('ACTIVE', observed)
server.status = 'ACTIVE(STATUS)'
observed = self.nova_plugin.get_status(server)
self.assertEqual('ACTIVE', observed)
class NovaUtilsRefreshServerTests(NovaClientPluginTestCase):