diff --git a/neutron/tests/fullstack/resources/config.py b/neutron/tests/fullstack/resources/config.py index b550470997b..91c845ec559 100644 --- a/neutron/tests/fullstack/resources/config.py +++ b/neutron/tests/fullstack/resources/config.py @@ -115,6 +115,9 @@ class NeutronConfigFixture(ConfigFixture): def _generate_policy_json(self): return c_helpers.find_sample_file('policy.json') + def get_host(self): + return self.config['DEFAULT']['host'] + class ML2ConfigFixture(ConfigFixture): diff --git a/neutron/tests/fullstack/test_l3_agent.py b/neutron/tests/fullstack/test_l3_agent.py index 7ad69deb7f5..084e07d6392 100644 --- a/neutron/tests/fullstack/test_l3_agent.py +++ b/neutron/tests/fullstack/test_l3_agent.py @@ -23,7 +23,6 @@ from neutron.agent.l3 import ha_router from neutron.agent.l3 import namespaces from neutron.agent.linux import ip_lib from neutron.common import utils as common_utils -from neutron.tests import base as tests_base from neutron.tests.common.exclusive_resources import ip_network from neutron.tests.common import machine_fixtures from neutron.tests.fullstack import base @@ -274,6 +273,19 @@ class TestHAL3Agent(TestL3Agent): if self._get_keepalived_state(keepalived_state_file) == "master": return keepalived_state_file + def _get_l3_agents_with_ha_state(self, l3_agents, router_id, ha_state): + found_agents = [] + agents_hosting_router = self.client.list_l3_agent_hosting_routers( + router_id)['agents'] + for agent in l3_agents: + agent_host = agent.neutron_cfg_fixture.get_host() + for agent_hosting_router in agents_hosting_router: + if (agent_hosting_router['host'] == agent_host and + agent_hosting_router['ha_state'] == ha_state): + found_agents.append(agent) + break + return found_agents + def test_keepalived_multiple_sighups_does_not_forfeit_mastership(self): """Setup a complete "Neutron stack" - both an internal and an external network+subnet, and a router connected to both. @@ -323,8 +335,7 @@ class TestHAL3Agent(TestL3Agent): "master", self._get_keepalived_state(keepalived_state_file)) - @tests_base.unstable_test("bug 1776459") - def test_ha_router_restart_agents_no_packet_lost(self): + def test_ha_router_restart_standby_agents_no_packet_lost(self): tenant_id = uuidutils.generate_uuid() ext_net, ext_sub = self._create_external_network_and_subnet(tenant_id) router = self.safe_client.create_router(tenant_id, ha=True, @@ -354,6 +365,8 @@ class TestHAL3Agent(TestL3Agent): external_vm.block_until_ping(router_ip) l3_agents = [host.agents['l3'] for host in self.environment.hosts] + l3_standby_agents = self._get_l3_agents_with_ha_state( + l3_agents, router['id'], 'standby') self._assert_ping_during_agents_restart( - l3_agents, external_vm.namespace, [router_ip], count=60) + l3_standby_agents, external_vm.namespace, [router_ip], count=60)