]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix KeyError exception while updating dhcp port
authorarmando-migliaccio <armamig@gmail.com>
Wed, 28 May 2014 17:37:15 +0000 (10:37 -0700)
committerarmando-migliaccio <armamig@gmail.com>
Wed, 28 May 2014 18:46:13 +0000 (11:46 -0700)
This is caused by a missing network_id in the port body.
This patch adds it so that a warning message can be traced
correctly. Wording is slightly tweaked to ensure it applies
to the right context.

Closes-bug: #1324194

Change-Id: I4b67b5c3584aa33278eb0e9e879ca338ba0ca8b0

neutron/agent/linux/dhcp.py
neutron/db/dhcp_rpc_base.py
neutron/tests/unit/test_dhcp_agent.py

index c6153027a5255260b69ccc78e4cf7f1c135a301a..0cc73d5f808b19d39d183c352b20a124a2d2203d 100644 (file)
@@ -767,7 +767,8 @@ class DeviceManager(object):
                     port_fixed_ips.extend(
                         [dict(subnet_id=s) for s in dhcp_enabled_subnet_ids])
                     dhcp_port = self.plugin.update_dhcp_port(
-                        port.id, {'port': {'fixed_ips': port_fixed_ips}})
+                        port.id, {'port': {'network_id': network.id,
+                                           'fixed_ips': port_fixed_ips}})
                     if not dhcp_port:
                         raise exceptions.Conflict()
                 else:
@@ -784,7 +785,8 @@ class DeviceManager(object):
                 port_device_id = getattr(port, 'device_id', None)
                 if port_device_id == constants.DEVICE_ID_RESERVED_DHCP_PORT:
                     dhcp_port = self.plugin.update_dhcp_port(
-                        port.id, {'port': {'device_id': device_id}})
+                        port.id, {'port': {'network_id': network.id,
+                                           'device_id': device_id}})
                     if dhcp_port:
                         break
 
index 106ad5ed7a04d277be0bf5d5388323caea9dfcbb..e42099c63c369f831be255d24dc9924dd3656518 100644 (file)
@@ -71,9 +71,10 @@ class DhcpRpcCallbackMixin(object):
                         pass
                     else:
                         ctxt.reraise = True
-                network_id = port['port']['network_id']
-                LOG.warn(_("Port for network %(net_id)s could not be created: "
-                           "%(reason)s") % {"net_id": network_id, 'reason': e})
+                net_id = port['port']['network_id']
+                LOG.warn(_("Action %(action)s for network %(net_id)s "
+                           "could not complete successfully: %(reason)s")
+                         % {"action": action, "net_id": net_id, 'reason': e})
 
     def get_active_networks(self, context, **kwargs):
         """Retrieve and return a list of the active network ids."""
index 5f58b8c00d2957e88a484ce91ad82e95e4daf1a1..ebe2be4c04a83cb0b17007518ed565b871665e48 100644 (file)
@@ -1180,6 +1180,7 @@ class TestDeviceManager(base.BaseTestCase):
         plugin.update_dhcp_port.return_value = fake_network.ports[0]
         dh.setup_dhcp_port(fake_network_copy)
         port_body = {'port': {
+                     'network_id': fake_network.id,
                      'fixed_ips': [{'subnet_id': fake_fixed_ip1.subnet_id,
                                     'ip_address': fake_fixed_ip1.ip_address},
                                    {'subnet_id': fake_subnet2.id}]}}