]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix to enable delete of firewall in PENDING_CREATE state
authorSridar Kandaswamy <skandasw@cisco.com>
Fri, 27 Sep 2013 17:10:35 +0000 (10:10 -0700)
committerSridar Kandaswamy <skandasw@cisco.com>
Fri, 27 Sep 2013 18:40:44 +0000 (11:40 -0700)
Firewall will in PENDING_CREATE state if there is no underlying router in the
tenant. When the router and an associated i/f is created then with a sequence
of msgs it is set to ACTIVE state by the plugin. If a delete is triggered when
in PENDING_CREATE state in such a situation, the msg was ignored - fixing this to
account for the fact that a delete makes sense in this situation so the agent
sends the appropriate msg back to the plugin so it can delete it.

Change-Id: Id1db0a8413fd815b518fe4dc57fc6277c09e7f00
Closes-Bug: #1223478

neutron/services/firewall/agents/l3reference/firewall_l3_agent.py
neutron/tests/unit/services/firewall/agents/l3reference/test_firewall_l3_agent.py

index 9c0832e6dfa1d4dccde4199779a948c6b3a1338c..e69982175cff504dc4add173282b7a11910e752e 100644 (file)
@@ -113,6 +113,11 @@ class FWaaSL3AgentRpcCallback(api.FWaaSAgentRpcCallbackMixin):
                 fw['tenant_id'])
             if not router_info_list:
                 LOG.debug(_('No Routers on tenant: %s'), fw['tenant_id'])
+                # fw was created before any routers were added, and if a
+                # delete is sent then we need to ack so that plugin can
+                # cleanup.
+                if func_name == 'delete_firewall':
+                    self.fwplugin_rpc.firewall_deleted(context, fw['id'])
                 return
             LOG.debug(_("Apply fw on Router List: '%s'"),
                       [ri.router['id'] for ri in router_info_list])
index 0aa6504861b3959526304ff222d1b8a3c7da0895..0630de07d0443f5605cd756f38c2e751a05139c8 100644 (file)
@@ -149,6 +149,33 @@ class TestFwaasL3AgentRpcCallback(base.BaseTestCase):
                 mock.sentinel.context,
                 fake_firewall['id'])
 
+    def test_delete_firewall_no_router(self):
+        fake_firewall = {'id': 0, 'tenant_id': 1}
+        self.api.plugin_rpc = mock.Mock()
+        with contextlib.nested(
+            mock.patch.object(self.api.plugin_rpc, 'get_routers'),
+            mock.patch.object(self.api, '_get_router_info_list_for_tenant'),
+            mock.patch.object(self.api.fwplugin_rpc, 'firewall_deleted')
+        ) as (
+            mock_get_routers,
+            mock_get_router_info_list_for_tenant,
+            mock_firewall_deleted):
+
+            mock_get_router_info_list_for_tenant.return_value = []
+            self.api.delete_firewall(
+                context=mock.sentinel.context,
+                firewall=fake_firewall, host='host')
+
+            mock_get_routers.assert_called_once_with(
+                mock.sentinel.context)
+
+            mock_get_router_info_list_for_tenant.assert_called_once_with(
+                mock_get_routers.return_value, fake_firewall['tenant_id'])
+
+            mock_firewall_deleted.assert_called_once_with(
+                mock.sentinel.context,
+                fake_firewall['id'])
+
     def test_process_router_add_fw_update(self):
         fake_firewall_list = [{'id': 0, 'tenant_id': 1,
                                'status': constants.PENDING_UPDATE}]