]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Do not schedule network when creating reserved DHCP port
authorItsuro Oda <oda@valinux.co.jp>
Thu, 5 Jun 2014 05:32:13 +0000 (14:32 +0900)
committerItsuro Oda <oda@valinux.co.jp>
Tue, 29 Jul 2014 22:42:20 +0000 (07:42 +0900)
If device_id is DEVICE_ID_RESERVED_DHCP_PORT, do not schedule
network nor notify to dhcp-agent.

Closes-Bug: #1327000
Change-Id: Idf88767596bf0fc31bf856a423d35cb1575b57f3

neutron/api/rpc/agentnotifiers/dhcp_rpc_agent_api.py
neutron/tests/unit/api/rpc/agentnotifiers/test_dhcp_rpc_agent_api.py
neutron/tests/unit/openvswitch/test_agent_scheduler.py

index 96c50bce918250be10431635e74b487c732e1b42..a11533707f9348a7e821ba6af764687bcd3a7a4e 100644 (file)
@@ -95,6 +95,9 @@ class DhcpAgentNotifyAPI(n_rpc.RpcProxy):
                              'payload': payload})
         return enabled_agents
 
+    def _is_reserved_dhcp_port(self, port):
+        return port.get('device_id') == constants.DEVICE_ID_RESERVED_DHCP_PORT
+
     def _notify_agents(self, context, method, payload, network_id):
         """Notify all the agents that are hosting the network."""
         # fanout is required as we do not know who is "listening"
@@ -115,7 +118,9 @@ class DhcpAgentNotifyAPI(n_rpc.RpcProxy):
                 context, [network_id])
 
             # schedule the network first, if needed
-            schedule_required = method == 'port_create_end'
+            schedule_required = (
+                method == 'port_create_end' and
+                not self._is_reserved_dhcp_port(payload['port']))
             if schedule_required:
                 agents = self._schedule_network(admin_ctx, network, agents)
 
index 5d29f6cbd0ce8a9e9bed28f459f1cfd783b12a92..6df1bbf9c7e22a02c758a715a4d9b1d86dc9f8c3 100644 (file)
@@ -124,8 +124,9 @@ class TestDhcpAgentNotifyAPI(base.BaseTestCase):
                 agent.admin_state_up = True
                 agent.heartbeat_timestamp = timeutils.utcnow()
                 g.return_value = [agent]
+                dummy_payload = {'port': {}}
                 self.notifier._notify_agents(mock.Mock(), method,
-                                             mock.ANY, 'foo_network_id')
+                                             dummy_payload, 'foo_network_id')
                 self.assertEqual(expected_scheduling, f.call_count)
                 self.assertEqual(expected_casts, self.mock_cast.call_count)
 
index f094daabc9c5702261bc666c734e3da580534589..62fdfe55747eaf760a9fb46b70f031a221b8e238 100644 (file)
@@ -1158,6 +1158,29 @@ class OvsDhcpAgentNotifierTestCase(test_l3_plugin.L3NatTestCaseMixin,
         for expected in expected_calls[DHCP_HOSTC]:
             self.assertIn(expected, self.dhcp_notifier_cast.call_args_list)
 
+    def _is_schedule_network_called(self, device_id):
+        plugin = manager.NeutronManager.get_plugin()
+        notifier = plugin.agent_notifiers[constants.AGENT_TYPE_DHCP]
+        with contextlib.nested(
+            self.subnet(),
+            mock.patch.object(plugin,
+                              'get_dhcp_agents_hosting_networks',
+                              return_value=[]),
+            mock.patch.object(notifier,
+                              '_schedule_network',
+                              return_value=[])
+                              ) as (subnet, _, mock_sched):
+            with self.port(subnet=subnet, device_id=device_id):
+                return mock_sched.called
+
+    def test_reserved_dhcp_port_creation(self):
+        device_id = constants.DEVICE_ID_RESERVED_DHCP_PORT
+        self.assertFalse(self._is_schedule_network_called(device_id))
+
+    def test_unreserved_dhcp_port_creation(self):
+        device_id = 'not_reserved'
+        self.assertTrue(self._is_schedule_network_called(device_id))
+
 
 class OvsL3AgentNotifierTestCase(test_l3_plugin.L3NatTestCaseMixin,
                                  test_agent_ext_plugin.AgentDBTestMixIn,