diff --git a/neutron/common/exceptions.py b/neutron/common/exceptions.py index 4195009d3e..408d609c58 100644 --- a/neutron/common/exceptions.py +++ b/neutron/common/exceptions.py @@ -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") diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 932d5c08a9..dd1f5aa962 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -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): diff --git a/neutron/plugins/nicira/nvplib.py b/neutron/plugins/nicira/nvplib.py index 47a500170d..00a184f062 100644 --- a/neutron/plugins/nicira/nvplib.py +++ b/neutron/plugins/nicira/nvplib.py @@ -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: diff --git a/neutron/plugins/ryu/db/api_v2.py b/neutron/plugins/ryu/db/api_v2.py index 53f65d18de..4d9224dd6d 100644 --- a/neutron/plugins/ryu/db/api_v2.py +++ b/neutron/plugins/ryu/db/api_v2.py @@ -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) diff --git a/neutron/tests/unit/nicira/test_nvplib.py b/neutron/tests/unit/nicira/test_nvplib.py index 13064dcdf9..e3c4a97a15 100644 --- a/neutron/tests/unit/nicira/test_nvplib.py +++ b/neutron/tests/unit/nicira/test_nvplib.py @@ -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')