]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Prompted error message is not correct for PortNotFound
authorYang Yu <yuyangbj@cn.ibm.com>
Mon, 22 Jul 2013 06:14:36 +0000 (14:14 +0800)
committerYang Yu <yuyangbj@cn.ibm.com>
Wed, 31 Jul 2013 05:48:53 +0000 (00:48 -0500)
When deleting a non-existing port, the error message would be
"Port XXXX could not be found on network None" for some plugins.
"network None" is not correct enough here.

Fixes bug #1203631

Change-Id: Ie5d1ec99a2726ff3fec07f83f83a12d24613ae57

neutron/common/exceptions.py
neutron/db/db_base_plugin_v2.py
neutron/plugins/nicira/nvplib.py
neutron/plugins/ryu/db/api_v2.py
neutron/tests/unit/nicira/test_nvplib.py

index 4195009d3efe79f90b8da174910d17f1e4ff8343..408d609c58a0732aebb4eb725a6e72df73831c68 100644 (file)
@@ -71,6 +71,10 @@ class SubnetNotFound(NotFound):
 
 
 class PortNotFound(NotFound):
+    message = _("Port %(port_id)s could not be found")
+
+
+class PortNotFoundOnNetwork(NotFound):
     message = _("Port %(port_id)s could not be found "
                 "on network %(net_id)s")
 
index 932d5c08a94415573ea84299a663908d2bc2d13f..dd1f5aa962f5bd4b6fc4caadc9a5cc4ef0a8e484 100644 (file)
@@ -236,9 +236,7 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2,
         try:
             port = self._get_by_id(context, models_v2.Port, id)
         except exc.NoResultFound:
-            # NOTE(jkoelker) The PortNotFound exceptions requires net_id
-            #                kwarg in order to set the message correctly
-            raise q_exc.PortNotFound(port_id=id, net_id=None)
+            raise q_exc.PortNotFound(port_id=id)
         return port
 
     def _get_dns_by_subnet(self, context, subnet_id):
index 47a500170d911d02995f8695a6512cd2024b58ac..00a184f0625af1d81737303c4076487b652b77d0 100644 (file)
@@ -619,8 +619,8 @@ def delete_port(cluster, switch, port):
         do_request(HTTP_DELETE, uri, cluster=cluster)
     except exception.NotFound:
         LOG.exception(_("Port or Network not found"))
-        raise exception.PortNotFound(net_id=switch,
-                                     port_id=port)
+        raise exception.PortNotFoundOnNetwork(
+            net_id=switch, port_id=port)
     except NvpApiClient.NvpApiException:
         raise exception.NeutronException()
 
@@ -662,7 +662,8 @@ def get_port(cluster, network, port, relations=None):
         return do_request(HTTP_GET, uri, cluster=cluster)
     except exception.NotFound as e:
         LOG.error(_("Port or Network not found, Error: %s"), str(e))
-        raise exception.PortNotFound(port_id=port, net_id=network)
+        raise exception.PortNotFoundOnNetwork(
+            port_id=port, net_id=network)
 
 
 def _configure_extensions(lport_obj, mac_address, fixed_ips,
@@ -716,7 +717,8 @@ def update_port(cluster, lswitch_uuid, lport_uuid, neutron_port_id, tenant_id,
         return result
     except exception.NotFound as e:
         LOG.error(_("Port or Network not found, Error: %s"), str(e))
-        raise exception.PortNotFound(port_id=lport_uuid, net_id=lswitch_uuid)
+        raise exception.PortNotFoundOnNetwork(
+            port_id=lport_uuid, net_id=lswitch_uuid)
 
 
 def create_lport(cluster, lswitch_uuid, tenant_id, neutron_port_id,
@@ -878,7 +880,8 @@ def get_port_status(cluster, lswitch_id, port_id):
                        (lswitch_id, port_id), cluster=cluster)
     except exception.NotFound as e:
         LOG.error(_("Port not found, Error: %s"), str(e))
-        raise exception.PortNotFound(port_id=port_id, net_id=lswitch_id)
+        raise exception.PortNotFoundOnNetwork(
+            port_id=port_id, net_id=lswitch_id)
     if r['link_status_up'] is True:
         return constants.PORT_STATUS_ACTIVE
     else:
index 53f65d18de45f8faff8f33e51789fce9399e0281..4d9224dd6d3134d7595ed5432b864a00ee4d760d 100644 (file)
@@ -212,4 +212,4 @@ def set_port_status(session, port_id, status):
         session.merge(port)
         session.flush()
     except orm_exc.NoResultFound:
-        raise q_exc.PortNotFound(port_id=port_id, net_id=None)
+        raise q_exc.PortNotFound(port_id=port_id)
index 13064dcdf9fb880dd868c8452697b3bc9df60d03..e3c4a97a150796ae231c5c13866bb5616a35b360 100644 (file)
@@ -1265,7 +1265,7 @@ class TestNvplibLogicalPorts(NvplibTestCase):
         self.assertEqual(constants.PORT_STATUS_ACTIVE, status)
 
     def test_get_port_status_non_existent_raises(self):
-        self.assertRaises(exceptions.PortNotFound,
+        self.assertRaises(exceptions.PortNotFoundOnNetwork,
                           nvplib.get_port_status,
                           self.fake_cluster,
                           'boo', 'boo')
@@ -1286,7 +1286,7 @@ class TestNvplibLogicalPorts(NvplibTestCase):
         self.assertIn('vm_id', port_tags)
 
     def test_update_non_existent_port_raises(self):
-        self.assertRaises(exceptions.PortNotFound,
+        self.assertRaises(exceptions.PortNotFoundOnNetwork,
                           nvplib.update_port, self.fake_cluster,
                           'boo', 'boo', 'boo', 'boo', 'boo', 'boo', False)
 
@@ -1294,13 +1294,13 @@ class TestNvplibLogicalPorts(NvplibTestCase):
         lswitch, lport = self._create_switch_and_port()
         nvplib.delete_port(self.fake_cluster,
                            lswitch['uuid'], lport['uuid'])
-        self.assertRaises(exceptions.PortNotFound,
+        self.assertRaises(exceptions.PortNotFoundOnNetwork,
                           nvplib.get_port, self.fake_cluster,
                           lswitch['uuid'], lport['uuid'])
 
     def test_delete_non_existent_port_raises(self):
         lswitch = self._create_switch_and_port()[0]
-        self.assertRaises(exceptions.PortNotFound,
+        self.assertRaises(exceptions.PortNotFoundOnNetwork,
                           nvplib.delete_port, self.fake_cluster,
                           lswitch['uuid'], 'bad_port_uuid')