diff options
author | Kevin Benton <kevin@benton.pub> | 2017-09-02 02:58:48 -0700 |
---|---|---|
committer | Ihar Hrachyshka <ihrachys@redhat.com> | 2017-09-06 01:43:55 +0000 |
commit | 680a34d7584f64ce0495313a889e0cdc509430df (patch) | |
tree | 351cd282cff75234e1eef3ae6d81a7bc2a35c02c | |
parent | 042cd342ddc6d96adba15247b61a572fe790a016 (diff) | |
download | neutron-680a34d7584f64ce0495313a889e0cdc509430df.tar.gz |
DHCP provisioning block only on port addr update
Don't add a DHCP provisioning block during port updates
unless the IP address or MAC address has changed. There is
no point in waiting on the DHCP agent after a port update
unless the addresses have changed. We already wait on the
DHCP agent after the port has been initially created so
we will be guaranteed that a reservation exists for the
correct MAC/IP in the DHCP agent.
Closes-Bug: #1714655
Change-Id: Idef5994e274ea99260367edb8331fd10b98a1432
(cherry picked from commit 8f3c27cd853d9e4d029939cbd8b371bf880c2cae)
-rw-r--r-- | neutron/plugins/ml2/plugin.py | 7 | ||||
-rw-r--r-- | neutron/tests/unit/plugins/ml2/test_plugin.py | 16 |
2 files changed, 18 insertions, 5 deletions
diff --git a/neutron/plugins/ml2/plugin.py b/neutron/plugins/ml2/plugin.py index dd3554a22c..eab74b8365 100644 --- a/neutron/plugins/ml2/plugin.py +++ b/neutron/plugins/ml2/plugin.py @@ -1352,8 +1352,11 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2, bound_mech_contexts.append(dist_mech_context) else: self.mechanism_manager.update_port_precommit(mech_context) - self._setup_dhcp_agent_provisioning_component( - context, updated_port) + if any(updated_port[k] != original_port[k] + for k in ('fixed_ips', 'mac_address')): + # only add block if fixed_ips or mac_address changed + self._setup_dhcp_agent_provisioning_component( + context, updated_port) bound_mech_contexts.append(mech_context) # Notifications must be sent after the above transaction is complete diff --git a/neutron/tests/unit/plugins/ml2/test_plugin.py b/neutron/tests/unit/plugins/ml2/test_plugin.py index 488a661724..7012c80b1c 100644 --- a/neutron/tests/unit/plugins/ml2/test_plugin.py +++ b/neutron/tests/unit/plugins/ml2/test_plugin.py @@ -772,16 +772,26 @@ class TestMl2PortsV2(test_plugin.TestPortsV2, Ml2PluginV2TestCase): with self.port(subnet=subnet): self.assertFalse(ap.called) - def test_dhcp_provisioning_blocks_inserted_on_update(self): + def _test_dhcp_provisioning_blocks_inserted_on_update(self, update_dict, + expected_block): ctx = context.get_admin_context() plugin = manager.NeutronManager.get_plugin() self._add_fake_dhcp_agent() with self.port() as port: with mock.patch.object(provisioning_blocks, 'add_provisioning_component') as ap: - port['port']['binding:host_id'] = 'newhost' + port['port'].update(update_dict) plugin.update_port(ctx, port['port']['id'], port) - self.assertTrue(ap.called) + self.assertEqual(expected_block, ap.called) + + def test_dhcp_provisioning_blocks_not_inserted_on_no_addr_change(self): + update = {'binding:host_id': 'newhost'} + self._test_dhcp_provisioning_blocks_inserted_on_update(update, False) + + def test_dhcp_provisioning_blocks_inserted_on_addr_change(self): + update = {'binding:host_id': 'newhost', + 'mac_address': '11:22:33:44:55:66'} + self._test_dhcp_provisioning_blocks_inserted_on_update(update, True) def test_dhcp_provisioning_blocks_removed_without_dhcp_agents(self): with mock.patch.object(provisioning_blocks, |