Prompted error message is not correct for PortNotFound

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
This commit is contained in:
Yang Yu 2013-07-22 14:14:36 +08:00
parent ed7ee9d995
commit 8209fe1fd0
5 changed files with 18 additions and 13 deletions

View File

@ -71,6 +71,10 @@ class SubnetNotFound(NotFound):
class PortNotFound(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 " message = _("Port %(port_id)s could not be found "
"on network %(net_id)s") "on network %(net_id)s")

View File

@ -236,9 +236,7 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2,
try: try:
port = self._get_by_id(context, models_v2.Port, id) port = self._get_by_id(context, models_v2.Port, id)
except exc.NoResultFound: except exc.NoResultFound:
# NOTE(jkoelker) The PortNotFound exceptions requires net_id raise q_exc.PortNotFound(port_id=id)
# kwarg in order to set the message correctly
raise q_exc.PortNotFound(port_id=id, net_id=None)
return port return port
def _get_dns_by_subnet(self, context, subnet_id): def _get_dns_by_subnet(self, context, subnet_id):

View File

@ -619,8 +619,8 @@ def delete_port(cluster, switch, port):
do_request(HTTP_DELETE, uri, cluster=cluster) do_request(HTTP_DELETE, uri, cluster=cluster)
except exception.NotFound: except exception.NotFound:
LOG.exception(_("Port or Network not found")) LOG.exception(_("Port or Network not found"))
raise exception.PortNotFound(net_id=switch, raise exception.PortNotFoundOnNetwork(
port_id=port) net_id=switch, port_id=port)
except NvpApiClient.NvpApiException: except NvpApiClient.NvpApiException:
raise exception.NeutronException() raise exception.NeutronException()
@ -662,7 +662,8 @@ def get_port(cluster, network, port, relations=None):
return do_request(HTTP_GET, uri, cluster=cluster) return do_request(HTTP_GET, uri, cluster=cluster)
except exception.NotFound as e: except exception.NotFound as e:
LOG.error(_("Port or Network not found, Error: %s"), str(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, 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 return result
except exception.NotFound as e: except exception.NotFound as e:
LOG.error(_("Port or Network not found, Error: %s"), str(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, 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) (lswitch_id, port_id), cluster=cluster)
except exception.NotFound as e: except exception.NotFound as e:
LOG.error(_("Port not found, Error: %s"), str(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: if r['link_status_up'] is True:
return constants.PORT_STATUS_ACTIVE return constants.PORT_STATUS_ACTIVE
else: else:

View File

@ -212,4 +212,4 @@ def set_port_status(session, port_id, status):
session.merge(port) session.merge(port)
session.flush() session.flush()
except orm_exc.NoResultFound: except orm_exc.NoResultFound:
raise q_exc.PortNotFound(port_id=port_id, net_id=None) raise q_exc.PortNotFound(port_id=port_id)

View File

@ -1265,7 +1265,7 @@ class TestNvplibLogicalPorts(NvplibTestCase):
self.assertEqual(constants.PORT_STATUS_ACTIVE, status) self.assertEqual(constants.PORT_STATUS_ACTIVE, status)
def test_get_port_status_non_existent_raises(self): def test_get_port_status_non_existent_raises(self):
self.assertRaises(exceptions.PortNotFound, self.assertRaises(exceptions.PortNotFoundOnNetwork,
nvplib.get_port_status, nvplib.get_port_status,
self.fake_cluster, self.fake_cluster,
'boo', 'boo') 'boo', 'boo')
@ -1286,7 +1286,7 @@ class TestNvplibLogicalPorts(NvplibTestCase):
self.assertIn('vm_id', port_tags) self.assertIn('vm_id', port_tags)
def test_update_non_existent_port_raises(self): def test_update_non_existent_port_raises(self):
self.assertRaises(exceptions.PortNotFound, self.assertRaises(exceptions.PortNotFoundOnNetwork,
nvplib.update_port, self.fake_cluster, nvplib.update_port, self.fake_cluster,
'boo', 'boo', 'boo', 'boo', 'boo', 'boo', False) 'boo', 'boo', 'boo', 'boo', 'boo', 'boo', False)
@ -1294,13 +1294,13 @@ class TestNvplibLogicalPorts(NvplibTestCase):
lswitch, lport = self._create_switch_and_port() lswitch, lport = self._create_switch_and_port()
nvplib.delete_port(self.fake_cluster, nvplib.delete_port(self.fake_cluster,
lswitch['uuid'], lport['uuid']) lswitch['uuid'], lport['uuid'])
self.assertRaises(exceptions.PortNotFound, self.assertRaises(exceptions.PortNotFoundOnNetwork,
nvplib.get_port, self.fake_cluster, nvplib.get_port, self.fake_cluster,
lswitch['uuid'], lport['uuid']) lswitch['uuid'], lport['uuid'])
def test_delete_non_existent_port_raises(self): def test_delete_non_existent_port_raises(self):
lswitch = self._create_switch_and_port()[0] lswitch = self._create_switch_and_port()[0]
self.assertRaises(exceptions.PortNotFound, self.assertRaises(exceptions.PortNotFoundOnNetwork,
nvplib.delete_port, self.fake_cluster, nvplib.delete_port, self.fake_cluster,
lswitch['uuid'], 'bad_port_uuid') lswitch['uuid'], 'bad_port_uuid')