Merge "Refactor test_alive_agents_are_consistent_along_time"

This commit is contained in:
Zuul 2023-04-21 08:08:17 +00:00 committed by Gerrit Code Review
commit 847db18c6d
1 changed files with 47 additions and 28 deletions

View File

@ -97,39 +97,58 @@ def test_neutron_agents_are_alive(timeout=420., interval=5.) \
return agents return agents
def test_alive_agents_are_consistent_along_time(previous_alive_agents=None): def test_alive_agents_are_consistent_along_time(retry_timeout=180.,
test_case = tobiko.get_test_case() retry_interval=5.,
if previous_alive_agents is None: consistent_sleep=5.,
# the following dict of agents is obtained when: consistent_count=5,):
# - the list_agents request is replied with 200 # the following dict of agents is obtained when:
# - the list is not empty # - the list_agents request is replied with 200
# - no agents are dead # - the list is not empty
alive_agents = {agent['id']: agent # - no agents are dead
for agent in test_neutron_agents_are_alive()} alive_agents = {agent['id']: agent
else: for agent in test_neutron_agents_are_alive()}
alive_agents = previous_alive_agents
for attempt in tobiko.retry(sleep_time=5., count=5): for attempt_out in tobiko.retry(timeout=retry_timeout,
agents = neutron.list_agents() interval=retry_interval):
actual = {agent['id']: agent LOG.debug('trying to obtain a consistent list of alive neutron agents '
for agent in agents} f'for {consistent_count} times')
for attempt_in in tobiko.retry(sleep_time=consistent_sleep,
count=consistent_count):
try:
agents = neutron.list_agents()
except (neutron.ServiceUnavailable,
neutron.NeutronClientException,
exceptions.connection.ConnectFailure):
LOG.exception('Error obtaining the list of neutron agents')
# go to the outer loop, if its timeout didn't expire yet
# the alive_agents reference is the previous list
break
actual = {agent['id']: agent for agent in agents}
# any dead agents? If yes, fail now # any dead agents? If yes, go to the outer loop
dead_agents = agents.with_items(alive=False) # the alive_agents reference is the previous list
test_case.assertEqual( dead_agents = agents.with_items(alive=False)
[], dead_agents, "Some neutron agents died") if len(dead_agents) > 0:
LOG.warn(f'Some dead agents have been found: {dead_agents}')
break
if len(actual) > len(alive_agents): # go to the outer loop if the set of agents changed
LOG.debug('Some new agents appeared! It seems not all the agents ' # the alive_agents reference is the new list
'had been started yet, so let\'s restart this check') if set(actual) != set(alive_agents):
return test_alive_agents_are_consistent_along_time(actual) alive_agents = actual
LOG.warn("The list of agents has changed")
break
# any agent disappeared? If yes, fail now LOG.debug("The new list of agents matched the previous list "
test_case.assertEqual( "%d times", attempt_in.number + 1)
set(alive_agents), set(actual), 'Some agents disappeared')
if attempt.is_last: if attempt_in.is_last:
break LOG.info(f"the list of agents obtained for {consistent_count} "
"times was consistent - the test passes")
return
if attempt_out.is_last:
tobiko.fail("No consistent neutron agent results obtained")
def ovn_dbs_vip_bindings(test_case): def ovn_dbs_vip_bindings(test_case):