Merge "Prompted error message is not correct for PortNotFound"

This commit is contained in:
Jenkins 2013-07-31 19:50:20 +00:00 committed by Gerrit Code Review
commit df21183425
5 changed files with 18 additions and 13 deletions

View 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")

View 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):

View 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:

View 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)

View 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')