diff --git a/neutron_fwaas/services/firewall/fwaas_plugin.py b/neutron_fwaas/services/firewall/fwaas_plugin.py index 08632a38b..f54647fe7 100644 --- a/neutron_fwaas/services/firewall/fwaas_plugin.py +++ b/neutron_fwaas/services/firewall/fwaas_plugin.py @@ -179,9 +179,18 @@ class FirewallPlugin( l3_plugin, nl_constants.L3_AGENT_SCHEDULER_EXT_ALIAS) and getattr(l3_plugin, 'get_l3_agents_hosting_routers', False)) if no_broadcast: + # This call checks for all scheduled routers to the network node agents = l3_plugin.get_l3_agents_hosting_routers( context, router_ids, admin_state_up=True, active=True) - return [a.host for a in agents] + scheduled_rtr_hosts = set([a.host for a in agents]) + # Now check for unscheduled DVR router on distributed compute hosts + unscheduled_dvr_hosts = set() + for router_id in router_ids: + hosts = set(l3_plugin._get_dvr_hosts_for_router( + context, router_id)) + unscheduled_dvr_hosts |= hosts + total_hosts = scheduled_rtr_hosts.union(unscheduled_dvr_hosts) + return total_hosts # NOTE(blallau): default: FirewallAgentAPI performs RPC broadcast return [None] diff --git a/neutron_fwaas/tests/unit/services/firewall/test_fwaas_plugin.py b/neutron_fwaas/tests/unit/services/firewall/test_fwaas_plugin.py index fbaaeeff1..a992b4739 100644 --- a/neutron_fwaas/tests/unit/services/firewall/test_fwaas_plugin.py +++ b/neutron_fwaas/tests/unit/services/firewall/test_fwaas_plugin.py @@ -377,6 +377,33 @@ class TestFirewallPluginBase(TestFirewallRouterInsertionBase, self.assertEqual('other-tenant', fw1['firewall']['tenant_id']) self.assertEqual(self._tenant_id, fw2['firewall']['tenant_id']) + def test_update_firewall_calls_get_dvr_hosts_for_router(self): + ctx = context.get_admin_context() + name = "user_fw" + attrs = self._get_test_firewall_attrs(name) + with self.router(name='router1', admin_state_up=True, + tenant_id=self._tenant_id) as router1: + with self.firewall_policy() as fwp: + fwp_id = fwp['firewall_policy']['id'] + attrs['firewall_policy_id'] = fwp_id + with self.firewall( + firewall_policy_id=fwp_id, + admin_state_up=test_db_firewall.ADMIN_STATE_UP, + router_ids=[router1['router']['id']] + ) as firewall: + fw_id = firewall['firewall']['id'] + self.callbacks.set_firewall_status(ctx, fw_id, + nl_constants.ACTIVE) + with mock.patch.object( + self.l3_plugin, + 'get_l3_agents_hosting_routers') as s_hosts, \ + mock.patch.object( + self.l3_plugin, + '_get_dvr_hosts_for_router') as u_hosts: + self.plugin.update_firewall(ctx, fw_id, firewall) + self.assertTrue(u_hosts.called) + self.assertTrue(s_hosts.called) + def test_update_firewall(self): ctx = context.get_admin_context() name = "new_firewall1"