From 955a966b0b616cca58242ea2841f23f868be058e Mon Sep 17 00:00:00 2001 From: Sridar Kandaswamy Date: Fri, 27 Sep 2013 10:10:35 -0700 Subject: [PATCH] Fix to enable delete of firewall in PENDING_CREATE state 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 --- .../agents/l3reference/firewall_l3_agent.py | 5 ++++ .../l3reference/test_firewall_l3_agent.py | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/neutron/services/firewall/agents/l3reference/firewall_l3_agent.py b/neutron/services/firewall/agents/l3reference/firewall_l3_agent.py index 9c0832e6dfa..e69982175cf 100644 --- a/neutron/services/firewall/agents/l3reference/firewall_l3_agent.py +++ b/neutron/services/firewall/agents/l3reference/firewall_l3_agent.py @@ -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]) diff --git a/neutron/tests/unit/services/firewall/agents/l3reference/test_firewall_l3_agent.py b/neutron/tests/unit/services/firewall/agents/l3reference/test_firewall_l3_agent.py index 0aa6504861b..0630de07d04 100644 --- a/neutron/tests/unit/services/firewall/agents/l3reference/test_firewall_l3_agent.py +++ b/neutron/tests/unit/services/firewall/agents/l3reference/test_firewall_l3_agent.py @@ -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}]