Fix get_instance_by_id, catch NotFound appopriately
novaclient will raise a NotFound exception here instead of returning None,
which the rest of the RUG assumes.
Change-Id: I6812bd01bb4a56433bc1c408040470d3711a0005
Closes-bug: #1459445
(cherry picked from commit ceaf3ce53c
)
This commit is contained in:
parent
0d20d363bf
commit
1023978760
|
@ -18,6 +18,7 @@ from datetime import datetime
|
|||
import logging
|
||||
|
||||
from novaclient.v1_1 import client
|
||||
from novaclient import exceptions as novaclient_exceptions
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
|
@ -138,7 +139,10 @@ class Nova(object):
|
|||
return None
|
||||
|
||||
def get_instance_by_id(self, instance_id):
|
||||
return self.client.servers.get(instance_id)
|
||||
try:
|
||||
return self.client.servers.get(instance_id)
|
||||
except novaclient_exceptions.NotFound:
|
||||
return None
|
||||
|
||||
def destroy_instance(self, instance_info):
|
||||
if instance_info:
|
||||
|
|
|
@ -21,6 +21,8 @@ import unittest2 as unittest
|
|||
from six.moves import builtins as __builtins__
|
||||
from akanda.rug.api import nova
|
||||
|
||||
from novaclient import exceptions as novaclient_exceptions
|
||||
|
||||
|
||||
class FakeModel(object):
|
||||
def __init__(self, id_, **kwargs):
|
||||
|
@ -180,6 +182,12 @@ class TestNovaWrapper(unittest.TestCase):
|
|||
self.client.servers.get.assert_has_calls(expected)
|
||||
self.assertEquals(result, 'fake_instance')
|
||||
|
||||
def test_get_instance_by_id_not_found(self):
|
||||
not_found = novaclient_exceptions.NotFound('instance_id')
|
||||
self.client.servers.get.side_effect = not_found
|
||||
result = self.nova.get_instance_by_id('instance_id')
|
||||
self.assertEqual(result, None)
|
||||
|
||||
def test_destroy_router_instance(self):
|
||||
self.nova.destroy_instance(self.INSTANCE_INFO)
|
||||
self.client.servers.delete.assert_called_with(self.INSTANCE_INFO.id_)
|
||||
|
|
Loading…
Reference in New Issue