]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
fix generation of exception for mismatched floating ip tenant-ids
authorDan Wendlandt <dan@nicira.com>
Sun, 9 Sep 2012 05:25:19 +0000 (22:25 -0700)
committerDan Wendlandt <dan@nicira.com>
Sun, 9 Sep 2012 05:25:19 +0000 (22:25 -0700)
bug 1048104

There was a KeyError in the case where we tried to throw an exception
to inform the user that a newly created floating ip could not be
associated with the requested port because they belonged to different
tenants.

Change-Id: I387e5f166761da78b941b62a9a396809491b8f09

quantum/db/l3_db.py

index cea813d86599f41458fce31353a22a09b27072ef..6e5b59a553630bed031ce861f1db67fedf04b0fc 100644 (file)
@@ -399,10 +399,17 @@ class L3_NAT_db_mixin(l3.RouterPluginBase):
         """
         internal_port = self._get_port(context, fip['port_id'])
         if not internal_port['tenant_id'] == fip['tenant_id']:
-            msg = ('Port %s is associated with a different tenant'
-                   'and therefore cannot be found to floating IP %s'
-                   % (fip['port_id'], fip['id']))
-            raise q_exc.BadRequest(resource='floating', msg=msg)
+            port_id = fip['port_id']
+            if 'id' in fip:
+                floatingip_id = fip['id']
+                msg = _('Port %(port_id)s is associated with a different '
+                        'tenant than Floating IP %(floatingip_id)s and '
+                        'therefore cannot be bound.')
+            else:
+                msg = _('Cannnot create floating IP and bind it to '
+                        'Port %(port_id)s, since that port is owned by a '
+                        'different tenant.')
+            raise q_exc.BadRequest(resource='floatingip', msg=msg % locals())
 
         internal_subnet_id = None
         if 'fixed_ip_address' in fip and fip['fixed_ip_address']: