Handle 404 in os-baremetal-nodes GET
Handle the 404 that python-ironicclient raises so we don't return a 500 to the caller. Partial-Bug: #1425258 Change-Id: Id9304844742ee3d34f88e661aadfd737e9515aa1
This commit is contained in:
parent
0a3201dc7e
commit
a36c24d5b1
|
@ -25,6 +25,7 @@ from nova.api.openstack import wsgi
|
|||
from nova.i18n import _
|
||||
|
||||
ironic_client = importutils.try_import('ironicclient.client')
|
||||
ironic_exc = importutils.try_import('ironicclient.exc')
|
||||
|
||||
authorize = extensions.extension_authorizer('compute', 'baremetal_nodes')
|
||||
|
||||
|
@ -132,7 +133,11 @@ class BareMetalNodeController(wsgi.Controller):
|
|||
# proxy command to Ironic
|
||||
_check_ironic_client_enabled()
|
||||
icli = _get_ironic_client()
|
||||
inode = icli.node.get(id)
|
||||
try:
|
||||
inode = icli.node.get(id)
|
||||
except ironic_exc.NotFound:
|
||||
msg = _("Node %s could not be found.") % id
|
||||
raise webob.exc.HTTPNotFound(explanation=msg)
|
||||
iports = icli.node.list_ports(id)
|
||||
node = {'id': inode.uuid,
|
||||
'interfaces': [],
|
||||
|
|
|
@ -25,6 +25,7 @@ from nova.api.openstack import wsgi
|
|||
from nova.i18n import _
|
||||
|
||||
ironic_client = importutils.try_import('ironicclient.client')
|
||||
ironic_exc = importutils.try_import('ironicclient.exc')
|
||||
|
||||
CONF = cfg.CONF
|
||||
ALIAS = "os-baremetal-nodes"
|
||||
|
@ -122,7 +123,11 @@ class BareMetalNodeController(wsgi.Controller):
|
|||
# proxy command to Ironic
|
||||
_check_ironic_client_enabled()
|
||||
icli = _get_ironic_client()
|
||||
inode = icli.node.get(id)
|
||||
try:
|
||||
inode = icli.node.get(id)
|
||||
except ironic_exc.NotFound:
|
||||
msg = _("Node %s could not be found.") % id
|
||||
raise webob.exc.HTTPNotFound(explanation=msg)
|
||||
iports = icli.node.list_ports(id)
|
||||
node = {'id': inode.uuid,
|
||||
'interfaces': [],
|
||||
|
|
|
@ -14,8 +14,11 @@
|
|||
# under the License.
|
||||
|
||||
import mock
|
||||
import six
|
||||
from webob import exc
|
||||
|
||||
from ironicclient import exc as ironic_exc
|
||||
|
||||
from nova.api.openstack.compute.contrib import baremetal_nodes as b_nodes_v2
|
||||
from nova.api.openstack.compute.plugins.v3 import baremetal_nodes \
|
||||
as b_nodes_v21
|
||||
|
@ -138,6 +141,13 @@ class BareMetalNodesTestV21(test.NoDBTestCase):
|
|||
mock_get.assert_called_once_with(node.uuid)
|
||||
mock_list_ports.assert_called_once_with(node.uuid)
|
||||
|
||||
@mock.patch.object(FAKE_IRONIC_CLIENT.node, 'get',
|
||||
side_effect=ironic_exc.NotFound())
|
||||
def test_show_ironic_node_not_found(self, mock_get):
|
||||
error = self.assertRaises(exc.HTTPNotFound, self.controller.show,
|
||||
self.request, 'fake-uuid')
|
||||
self.assertIn('fake-uuid', six.text_type(error))
|
||||
|
||||
def test_show_ironic_not_implemented(self):
|
||||
with mock.patch.object(self.mod, 'ironic_client', None):
|
||||
properties = {'cpus': 1, 'memory_mb': 512, 'local_gb': 10}
|
||||
|
|
Loading…
Reference in New Issue