From 2cab3fa33eec4d5996a9d1e06ffc04bc02c77ded Mon Sep 17 00:00:00 2001 From: Andreas Maier Date: Thu, 23 Jan 2025 12:29:49 +0100 Subject: [PATCH] Fixed partition link end2end tests by waiting for completion Signed-off-by: Andreas Maier --- tests/end2end/test_partition_link.py | 53 ++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/tests/end2end/test_partition_link.py b/tests/end2end/test_partition_link.py index c2635918..7cdd0fc9 100644 --- a/tests/end2end/test_partition_link.py +++ b/tests/end2end/test_partition_link.py @@ -20,11 +20,11 @@ """ -import warnings import random import uuid from copy import copy from pprint import pprint +import time import pytest from requests.packages import urllib3 @@ -91,6 +91,38 @@ def replace_expressions(obj, replacements): return copy(obj) +def wait_for_states( + partitionlink, states=('complete', 'incomplete'), timeout=300): + """ + Wait for a partition link to reach one of the specified states. + + Raises: + OperationTimeout: Timed out. + """ + + if timeout > 0: + start_time = time.time() + + while True: + try: + partitionlink.pull_properties(['state']) + if partitionlink.properties['state'] in states: + return + except ConnectionError: + print("Retrying after ConnectionError while waiting for states " + f"{states} in partition link {partitionlink.name!r}.") + + if timeout > 0: + current_time = time.time() + if current_time > start_time + timeout: + raise zhmcclient.OperationTimeout( + f"Waiting for states {states} in partition link " + f"{partitionlink.name} timed out (timeout: {timeout} s)", + timeout) + + time.sleep(2) # Avoid hot spin loop + + @pytest.mark.parametrize( "pl_type", [ 'hipersockets', @@ -206,18 +238,16 @@ def test_partlink_crud(dpm_mode_cpcs, pl_type): # noqa: F811 except zhmcclient.NotFound: pass else: - warnings.warn( - f"Deleting test partition link from previous run: " - f"{partlink_name!r} on CPC {cpc.name}", UserWarning) + print("Deleting test partition link from previous run: " + f"{partlink_name!r} on CPC {cpc.name}") partlink.delete() try: partlink = console.partition_links.find(name=partlink_name_new) except zhmcclient.NotFound: pass else: - warnings.warn( - "Deleting test partition link from previous run: " - f"{partlink_name_new!r} on CPC {cpc.name}", UserWarning) + print("Deleting test partition link from previous run: " + f"{partlink_name_new!r} on CPC {cpc.name}") partlink.delete() # Test creating the partition link. @@ -258,11 +288,14 @@ def test_partlink_crud(dpm_mode_cpcs, pl_type): # noqa: F811 partlink_auto_props = { 'cpc-name': cpc.name, + 'state': 'complete', } # The code to be tested partlink = console.partition_links.create(partlink_input_props) + wait_for_states(partlink, ['complete']) + # Remove input properties that are not in data model or that are # different iindata model, so that we can check. if 'partitions' in partlink_input_props: @@ -311,6 +344,8 @@ def test_partlink_crud(dpm_mode_cpcs, pl_type): # noqa: F811 # Test deleting the partition link + wait_for_states(partlink, ['complete']) + # The code to be tested partlink.delete() @@ -483,11 +518,14 @@ def test_partlink_create_delete( pprint(partlink_input_props) raise + wait_for_states(partlink, ['complete']) + # Prepare the expected properties partlink_exp_props = { 'cpc-uri': cpc.uri, 'name': partlink_name, 'type': pl_type, + 'state': 'complete', } partlink_exp_props.update(exp_props) @@ -500,6 +538,7 @@ def test_partlink_create_delete( finally: # Cleanup, but also code to be tested + wait_for_states(partlink) if partlink: partlink.delete() if part1: