Retry mechanism for check_neutron_agents_health

Disruptions tests were sometimes failing when checking neutron agents
status after controller reboots.
The error detected was the following one:
neutronclient.common.exceptions.ServiceUnavailable:
<html><body><h1>503 Service Unavailable</h1>

Change-Id: Ied892749545c251cc9a746fba185643ab09dbabf
This commit is contained in:
Eduardo Olivares 2020-06-23 09:39:00 +02:00
parent bb0a45ffde
commit 54d79e115f
1 changed files with 17 additions and 2 deletions

View File

@ -1,5 +1,8 @@
from __future__ import absolute_import
import time
from neutronclient.common import exceptions as neutron_exc
from oslo_log import log
import tobiko
@ -8,10 +11,22 @@ from tobiko.openstack import neutron
LOG = log.getLogger(__name__)
def check_neutron_agents_health():
def check_neutron_agents_health(timeout=60, interval=5):
failures = []
neutron_client = neutron.get_neutron_client()
agents = neutron_client.list_agents()
start = time.time()
while time.time() - start < timeout:
try:
# get neutron agent list
agents = neutron_client.list_agents()
except neutron_exc.ServiceUnavailable:
# retry in case neutron server was unavailable after disruption
LOG.warning("neutron server was not available - retrying...")
time.sleep(interval)
else:
LOG.info("neutron agents status retrieved")
break
for agent in agents['agents']:
if not agent['alive']: