Fix InternalException raised on stack-show

Getting attributes of a OS::Nova::Server raises a 500 error if the server
doesn't exist. So stack show doesn't work. We should catch the exception
and return the default values of the output keys of the server while
getting attributes to make sure the api works.

Change-Id: If569b4d73abbce93d3c56c45a1eb284720c6e416
Closes-Bug: #1279085
This commit is contained in:
huangtianhua 2014-02-26 11:56:06 +08:00
parent 5f79b9e43f
commit e811accb73
2 changed files with 22 additions and 1 deletions

View File

@ -462,7 +462,12 @@ class Server(resource.Resource):
if name == 'first_address':
return nova_utils.server_to_ipaddress(
self.nova(), self.resource_id) or ''
server = self.nova().servers.get(self.resource_id)
try:
server = self.nova().servers.get(self.resource_id)
except clients.novaclient.exceptions.NotFound as ex:
logger.warn(_('Instance (%(server)s) not found: %(ex)s') % {
'server': self.resource_id, 'ex': str(ex)})
return ''
if name == 'addresses':
return server.addresses
if name == 'networks':

View File

@ -1700,6 +1700,22 @@ class ServersTest(HeatTestCase):
"file size (10240 bytes).", str(exc))
self.m.VerifyAll()
def test_resolve_attribute_server_not_found(self):
return_server = self.fc.servers.list()[1]
server = self._create_test_server(return_server,
'srv_resolve_attr')
server.resource_id = 1234
self.m.StubOutWithMock(self.fc.client, 'get_servers_1234')
get = self.fc.client.get_servers_1234
get().AndRaise(servers.clients.novaclient.exceptions.NotFound(404))
mox.Replay(get)
self.m.ReplayAll()
self.assertEqual(server._resolve_attribute("accessIPv4"), '')
self.m.VerifyAll()
class FlavorConstraintTest(HeatTestCase):