From 3294152ac7c8bfc496aa9a04758f9cd91598f5ee Mon Sep 17 00:00:00 2001 From: Federico Ressi Date: Fri, 16 Jul 2021 15:17:49 +0200 Subject: [PATCH] Remove OSP specific assumptions in test_neutron_agents_are_alive Change-Id: I1f40c37efa08bf3b8efeacf563ce50675ac448d9 Depends-On: https://review.opendev.org/c/x/devstack-plugin-tobiko/+/801272 --- tobiko/openstack/tests/_neutron.py | 41 ++++++++----------- .../unit/openstack/tests/test_neutron.py | 5 +-- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/tobiko/openstack/tests/_neutron.py b/tobiko/openstack/tests/_neutron.py index 7856cfa69..8b2bec062 100644 --- a/tobiko/openstack/tests/_neutron.py +++ b/tobiko/openstack/tests/_neutron.py @@ -37,38 +37,29 @@ def build_ovn_db_show_dict(ovn_db_show_str): return ovn_master_db_dict -def test_neutron_agents_are_alive(timeout=300., interval=5.): - test_case = tobiko.get_test_case() +def test_neutron_agents_are_alive(timeout=300., interval=5.) \ + -> tobiko.Selection[neutron.NeutronAgentType]: for attempt in tobiko.retry(timeout=timeout, interval=interval): LOG.debug("Look for unhealthy Neutron agents...") try: # get Neutron agent list agents = neutron.list_agents() except neutron.ServiceUnavailable as ex: - attempt.check_limits() - # retry because Neutron server could still be unavailable after - # a disruption - LOG.debug(f"Waiting for neutron service... ({ex})") - continue # Let retry - - if (topology.verify_osp_version('14.0', lower=True) - and is_ovn_configured()): - LOG.debug("Neutron list agents should return an empty list with" - "OVN and RHOSP releases 13 or earlier") - test_case.assertEqual([], agents) - return agents - - if not agents: - test_case.fail("Neutron has no agents") + if attempt.is_last: + raise + else: + # retry because Neutron server could still be unavailable + # after a disruption + LOG.debug(f"Waiting for neutron service... ({ex})") + continue # Let retry dead_agents = agents.with_items(alive=False) if dead_agents: dead_agents_details = json.dumps(agents, indent=4, sort_keys=True) - try: - test_case.fail("Unhealthy agent(s) found:\n" - f"{dead_agents_details}\n") - except tobiko.FailureException: - attempt.check_limits() + if attempt.is_last: + tobiko.fail("Unhealthy agent(s) found:\n" + f"{dead_agents_details}\n") + else: # retry because some Neutron agent could still be unavailable # after a disruption LOG.debug("Waiting for Neutron agents to get alive...\n" @@ -76,7 +67,11 @@ def test_neutron_agents_are_alive(timeout=300., interval=5.): continue LOG.debug(f"All {len(agents)} Neutron agents are alive.") - return agents + break + else: + raise RuntimeError("Retry loop broken") + + return agents def ovn_dbs_are_synchronized(test_case): diff --git a/tobiko/tests/unit/openstack/tests/test_neutron.py b/tobiko/tests/unit/openstack/tests/test_neutron.py index 65f8c1cee..1f3804245 100644 --- a/tobiko/tests/unit/openstack/tests/test_neutron.py +++ b/tobiko/tests/unit/openstack/tests/test_neutron.py @@ -38,9 +38,8 @@ class NeutronAgentTest(openstack.OpenstackTest): def test_neutron_agents_are_alive_when_no_agents(self): self.patch_list_agents(return_value=[]) - ex = self.assertRaises(self.failureException, - tests.test_neutron_agents_are_alive) - self.assertEqual('Neutron has no agents', str(ex)) + agents = tests.test_neutron_agents_are_alive() + self.assertEqual([], agents) def test_neutron_agents_are_alive_when_unhealthy(self): self.patch_list_agents(return_value=[{'alive': False}])