Skip to content

Commit

Permalink
Fixed partition link end2end tests by waiting for completion
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Maier <[email protected]>
  • Loading branch information
andy-maier committed Jan 23, 2025
1 parent 1ba6202 commit 2cab3fa
Showing 1 changed file with 46 additions and 7 deletions.
53 changes: 46 additions & 7 deletions tests/end2end/test_partition_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)

Expand All @@ -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:
Expand Down

0 comments on commit 2cab3fa

Please sign in to comment.