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
This is a backport of a36c24d5b1
Change-Id: Id9304844742ee3d34f88e661aadfd737e9515aa1
This commit is contained in:
@@ -29,6 +29,7 @@ from nova.openstack.common import log as logging
|
||||
from nova.virt.baremetal import db
|
||||
|
||||
ironic_client = importutils.try_import('ironicclient.client')
|
||||
ironic_exc = importutils.try_import('ironicclient.exc')
|
||||
|
||||
authorize = extensions.extension_authorizer('compute', 'baremetal_nodes')
|
||||
|
||||
@@ -216,7 +217,11 @@ class BareMetalNodeController(wsgi.Controller):
|
||||
if _use_ironic():
|
||||
# proxy command to Ironic
|
||||
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': [],
|
||||
|
||||
@@ -13,8 +13,10 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from ironicclient import exc as ironic_exc
|
||||
import mock
|
||||
from oslo.config import cfg
|
||||
import six
|
||||
from webob import exc
|
||||
|
||||
from nova.api.openstack.compute.contrib import baremetal_nodes
|
||||
@@ -262,6 +264,14 @@ class BareMetalNodesTest(test.NoDBTestCase):
|
||||
def test_show_no_interfaces_ext_status(self):
|
||||
self._test_show_no_interfaces(ext_status=True)
|
||||
|
||||
@mock.patch.object(FAKE_IRONIC_CLIENT.node, 'get',
|
||||
side_effect=ironic_exc.NotFound())
|
||||
def test_show_ironic_node_not_found(self, mock_get):
|
||||
CONF.set_override('compute_driver', 'nova.virt.ironic.driver')
|
||||
error = self.assertRaises(exc.HTTPNotFound, self.controller.show,
|
||||
self.request, 'fake-uuid')
|
||||
self.assertIn('fake-uuid', six.text_type(error))
|
||||
|
||||
def test_add_interface(self):
|
||||
node_id = 1
|
||||
address = '11:22:33:ab:cd:ef'
|
||||
|
||||
Reference in New Issue
Block a user