From eafd39720a2542dc267b7fd8e9b26e251badf9bb Mon Sep 17 00:00:00 2001 From: Omer Date: Fri, 19 Nov 2021 18:22:06 +0100 Subject: [PATCH] Fix traffic test - add curl timeout error This patch fixes the timeout error we get at the traffic test, which happens when we send the traffic to the loadbalancer when it is not ready/stable. Change-Id: Ia3eaa4f9dfddf29828a40f19b46127fd7e7a8e05 --- tobiko/openstack/octavia/__init__.py | 1 + tobiko/openstack/octavia/_exceptions.py | 4 ++++ tobiko/openstack/octavia/_validators.py | 19 +++++++++++++------ tobiko/tests/scenario/octavia/test_traffic.py | 3 ++- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/tobiko/openstack/octavia/__init__.py b/tobiko/openstack/octavia/__init__.py index 2dba5c390..3652c71be 100644 --- a/tobiko/openstack/octavia/__init__.py +++ b/tobiko/openstack/octavia/__init__.py @@ -45,6 +45,7 @@ RequestException = _exceptions.RequestException TimeoutException = _exceptions.TimeoutException OctaviaClientException = _exceptions.OctaviaClientException RoundRobinException = _exceptions.RoundRobinException +TrafficTimeoutError = _exceptions.TrafficTimeoutError # Constants PROVISIONING_STATUS = _constants.PROVISIONING_STATUS diff --git a/tobiko/openstack/octavia/_exceptions.py b/tobiko/openstack/octavia/_exceptions.py index 16122e1e4..a52256789 100644 --- a/tobiko/openstack/octavia/_exceptions.py +++ b/tobiko/openstack/octavia/_exceptions.py @@ -33,3 +33,7 @@ OctaviaClientException = exceptions.OctaviaClientException class RoundRobinException(tobiko.TobikoException): message = "Round robin exception: {reason}" + + +class TrafficTimeoutError(tobiko.TobikoException): + message = "Traffic timeout error: {reason}" diff --git a/tobiko/openstack/octavia/_validators.py b/tobiko/openstack/octavia/_validators.py index ef0a64dce..6a294deb1 100644 --- a/tobiko/openstack/octavia/_validators.py +++ b/tobiko/openstack/octavia/_validators.py @@ -23,6 +23,7 @@ import tobiko from tobiko.openstack import octavia from tobiko.shell import curl from tobiko.shell import ssh +from tobiko.shell import sh LOG = log.getLogger(__name__) @@ -57,12 +58,18 @@ def check_members_balanced(ip_address: str, replies: typing.Dict[str, int] = collections.defaultdict(lambda: 0) for attempt in tobiko.retry(count=members_count * requests_count, interval=interval): - content = curl.execute_curl(hostname=ip_address, - scheme=protocol, - port=port, - path='id', - connect_timeout=connect_timeout, - ssh_client=ssh_client).strip() + try: + content = curl.execute_curl(hostname=ip_address, + scheme=protocol, + port=port, + path='id', + connect_timeout=connect_timeout, + ssh_client=ssh_client).strip() + except sh.ShellCommandFailed as ex: + if ex.exit_status == 28: + raise octavia.TrafficTimeoutError( + reason=str(ex.stderr)) from ex + replies[content] += 1 if last_content is not None and lb_algorithm == 'ROUND_ROBIN': diff --git a/tobiko/tests/scenario/octavia/test_traffic.py b/tobiko/tests/scenario/octavia/test_traffic.py index add73ef03..d3e7fe885 100644 --- a/tobiko/tests/scenario/octavia/test_traffic.py +++ b/tobiko/tests/scenario/octavia/test_traffic.py @@ -86,7 +86,8 @@ class OctaviaBasicTrafficScenarioTest(testtools.TestCase): break - except octavia.RoundRobinException as e: + except (octavia.RoundRobinException, + octavia.TrafficTimeoutError) as e: if attempt.is_last: raise e