Skip to content

Commit bd1e39a

Browse files
committed
[4.18] eus upgrade alignment
Signed-off-by: Harel Meir <hmeir@redhat.com>
1 parent 9e05bf1 commit bd1e39a

9 files changed

Lines changed: 256 additions & 184 deletions

File tree

conftest.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from _pytest.runner import CallInfo
2323
from kubernetes.dynamic.exceptions import ConflictError
2424
from ocp_resources.resource import get_client
25+
from packaging.version import Version
2526
from pyhelper_utils.shell import run_command
2627
from pytest import Item
2728
from pytest_testconfig import config as py_config
@@ -150,7 +151,6 @@ def pytest_addoption(parser):
150151
"--eus-ocp-images",
151152
help="Comma-separated OCP images to use for EUS-to-EUS upgrade.",
152153
)
153-
install_upgrade_group.addoption("--eus-cnv-target-version", help="target CNV version for eus upgrade")
154154
install_upgrade_group.addoption(
155155
"--upgrade-skip-default-sc-setup",
156156
help="Skip the fixture that changes the default sc in upgrade lane",
@@ -302,18 +302,21 @@ def pytest_cmdline_main(config):
302302
if upgrade_option == "ocp" and not config.getoption("ocp_image"):
303303
raise ValueError("Running with --upgrade ocp: Missing --ocp-image")
304304

305-
if upgrade_option == "cnv":
305+
if upgrade_option in ("cnv", "eus"):
306306
if not config.getoption("cnv_version"):
307307
raise ValueError("Missing --cnv-version")
308308
if not config.getoption("cnv_image"):
309-
if config.getoption("cnv_source") != "production":
309+
if upgrade_option == "eus" or config.getoption("cnv_source") != "production":
310310
raise ValueError("Missing --cnv-image")
311311

312-
if upgrade_option == "eus":
312+
if upgrade_option == "eus" and not config.option.collectonly:
313+
cnv_version = config.getoption("cnv_version")
314+
if Version(version=cnv_version).minor % 2:
315+
raise ValueError(f"EUS target version {cnv_version} must have an even minor version")
313316
eus_ocp_images = config.getoption("eus_ocp_images")
314317
if not (eus_ocp_images and len(eus_ocp_images.split(",")) == 2):
315318
raise ValueError(
316-
f"Two OCP images are needed to perform EUS-to-EUS upgrade with --eus-ocp-images."
319+
f"Two OCP images are needed for EUS-to-EUS upgrade with --eus-ocp-images."
317320
f" Provided images: {eus_ocp_images}"
318321
)
319322

@@ -784,7 +787,7 @@ def is_skip_must_gather(node: Node) -> bool:
784787

785788
def get_inspect_command_namespace_string(node: Node, test_name: str) -> str:
786789
namespace_str = ""
787-
components = [key for key in NAMESPACE_COLLECTION.keys() if f"tests/{key}/" in test_name]
790+
components = [key for key in NAMESPACE_COLLECTION if f"tests/{key}/" in test_name]
788791
if not components:
789792
LOGGER.warning(f"{test_name} does not require special data collection on failure")
790793
else:

tests/conftest.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
from ocp_resources.virtual_machine_instancetype import VirtualMachineInstancetype
6464
from ocp_resources.virtual_machine_preference import VirtualMachinePreference
6565
from ocp_utilities.monitoring import Prometheus
66-
from packaging.version import Version, parse
66+
from packaging.version import parse
6767
from pytest_testconfig import config as py_config
6868
from timeout_sampler import TimeoutSampler
6969

@@ -1898,27 +1898,14 @@ def hco_target_csv_name(cnv_target_version):
18981898
return get_hco_csv_name_by_version(cnv_target_version=cnv_target_version) if cnv_target_version else None
18991899

19001900

1901-
@pytest.fixture(scope="session")
1902-
def eus_hco_target_csv_name(eus_target_cnv_version):
1903-
return get_hco_csv_name_by_version(cnv_target_version=eus_target_cnv_version)
1904-
1905-
19061901
@pytest.fixture(scope="session")
19071902
def cnv_target_version(pytestconfig):
19081903
return pytestconfig.option.cnv_version
19091904

19101905

19111906
@pytest.fixture(scope="session")
1912-
def eus_target_cnv_version(pytestconfig, cnv_current_version):
1913-
cnv_current_version = Version(version=cnv_current_version)
1914-
minor = cnv_current_version.minor
1915-
# EUS-to-EUS upgrades are only viable between even-numbered minor versions, exit if non-eus version
1916-
if minor % 2:
1917-
exit_pytest_execution(
1918-
message=f"EUS upgrade can not be performed from non-eus version: {cnv_current_version}",
1919-
return_code=EUS_ERROR_CODE,
1920-
)
1921-
return pytestconfig.option.eus_cnv_target_version or f"{cnv_current_version.major}.{minor + 2}.0"
1907+
def cnv_channel(pytestconfig):
1908+
return pytestconfig.option.cnv_channel
19221909

19231910

19241911
@pytest.fixture()

tests/install_upgrade_operators/product_upgrade/conftest.py

Lines changed: 47 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@
1515
)
1616
from tests.install_upgrade_operators.product_upgrade.utils import (
1717
approve_cnv_upgrade_install_plan,
18+
build_eus_upgrade_path_dict,
1819
extract_ocp_version_from_ocp_image,
1920
get_alerts_fired_during_upgrade,
2021
get_all_firing_cnv_alerts,
21-
get_iib_images_of_cnv_versions,
2222
get_nodes_labels,
2323
get_nodes_taints,
24-
get_upgrade_path,
2524
perform_cnv_upgrade,
2625
run_ocp_upgrade_command,
2726
set_workload_update_methods_hco,
@@ -49,8 +48,8 @@
4948
get_data_collector_base_directory,
5049
)
5150
from utilities.infra import (
51+
exit_pytest_execution,
5252
generate_openshift_pull_secret_file,
53-
get_csv_by_name,
5453
get_prometheus_k8s_token,
5554
get_related_images_name_and_version,
5655
get_subscription,
@@ -66,6 +65,7 @@
6665

6766
LOGGER = logging.getLogger(__name__)
6867
POD_STR_NOT_MANAGED_BY_HCO = "hostpath-"
68+
EUS_ERROR_CODE = 98
6969

7070

7171
@pytest.fixture(scope="session")
@@ -323,64 +323,25 @@ def fired_alerts_during_upgrade(
323323

324324

325325
@pytest.fixture(scope="session")
326-
def eus_shortest_upgrade_path_info(eus_target_cnv_version, cnv_current_version):
327-
# if cant get from stable - try candidate
328-
if upgrade_paths_target_version := get_upgrade_path(target_version=eus_target_cnv_version):
329-
target_channel = "stable"
330-
else:
331-
target_channel = "candidate"
332-
upgrade_paths_target_version = get_upgrade_path(target_version=eus_target_cnv_version, channel=target_channel)
333-
assert upgrade_paths_target_version, f"Couldn't find upgrade path for {eus_target_cnv_version} version"
334-
335-
sorted_upgrade_paths = sorted(
336-
upgrade_paths_target_version, key=lambda path: Version(version=str(path["startVersion"])), reverse=True
337-
)
338-
for path in sorted_upgrade_paths:
339-
if intermediate_upgrade_paths := get_upgrade_path(target_version=path["startVersion"]):
340-
if intermediate_path_dict := next(
341-
(item for item in intermediate_upgrade_paths if item["startVersion"] == f"v{cnv_current_version}"), None
342-
):
343-
return {
344-
"target_versions": path["versions"],
345-
"intermediate_versions": intermediate_path_dict["versions"],
346-
"target_channel": target_channel,
347-
}
348-
raise AssertionError(f"Couldn't find upgrade path for {eus_target_cnv_version} version from {cnv_current_version}")
349-
350-
351-
@pytest.fixture(scope="session")
352-
def eus_target_channel(eus_shortest_upgrade_path_info):
353-
return eus_shortest_upgrade_path_info["target_channel"]
354-
355-
356-
@pytest.fixture(scope="session")
357-
def eus_cnv_upgrade_path(eus_shortest_upgrade_path_info, eus_target_channel):
358-
if not (
359-
target_paths := get_iib_images_of_cnv_versions(
360-
versions=eus_shortest_upgrade_path_info["target_versions"],
361-
target_channel=eus_target_channel,
362-
)
363-
):
364-
target_paths = get_iib_images_of_cnv_versions(
365-
versions=eus_shortest_upgrade_path_info["target_versions"],
366-
errata_status="false",
367-
target_channel=eus_target_channel,
326+
def eus_cnv_upgrade_path(
327+
cnv_target_version,
328+
cnv_current_version,
329+
cnv_channel,
330+
cnv_image_url,
331+
):
332+
if Version(version=cnv_current_version).minor % 2:
333+
exit_pytest_execution(
334+
message=f"EUS upgrade can not be performed from non-eus version: {cnv_current_version}",
335+
return_code=EUS_ERROR_CODE,
336+
filename="eus_upgrade_failure.txt",
368337
)
369-
intermediate_paths = get_iib_images_of_cnv_versions(
370-
versions=eus_shortest_upgrade_path_info["intermediate_versions"],
371-
)
372-
assert intermediate_paths, (
373-
f"Couldn't find build info for {eus_shortest_upgrade_path_info['intermediate_versions']} versions"
338+
return build_eus_upgrade_path_dict(
339+
current_cnv_version=cnv_current_version,
340+
target_cnv_version=cnv_target_version,
341+
target_channel=cnv_channel,
342+
target_cnv_image_url=cnv_image_url,
374343
)
375344

376-
# Return a dictionary with the versions and images for the EUS-to-EUS upgrade
377-
upgrade_path_dict = {
378-
EUS: target_paths,
379-
"non-eus": intermediate_paths,
380-
}
381-
LOGGER.info(f"Upgrade path for EUS-to-EUS upgrade: {upgrade_path_dict}")
382-
return upgrade_path_dict
383-
384345

385346
@pytest.fixture(scope="session")
386347
def default_workload_update_strategy(hyperconverged_resource_scope_session):
@@ -564,18 +525,25 @@ def source_eus_to_non_eus_cnv_upgraded(
564525
admin_client,
565526
hco_namespace,
566527
eus_cnv_upgrade_path,
567-
eus_target_channel,
528+
cnv_subscription_scope_session,
529+
cnv_registry_source,
568530
hyperconverged_resource_scope_function,
569-
updated_cnv_subscription_source,
570531
):
571-
for version, cnv_image in sorted(eus_cnv_upgrade_path["non-eus"].items()):
532+
for version, build_info in sorted(
533+
eus_cnv_upgrade_path["non-eus"].items(),
534+
key=lambda item: Version(version=item[0]),
535+
):
536+
cnv_image = build_info["cnv_image_url"]
572537
LOGGER.info(f"Cnv upgrade to version {version} using image: {cnv_image}")
573538
perform_cnv_upgrade(
574539
admin_client=admin_client,
575540
cnv_image_url=cnv_image,
576541
cr_name=hyperconverged_resource_scope_function.name,
577542
hco_namespace=hco_namespace,
578-
cnv_target_version=version.lstrip("v"),
543+
cnv_target_version=version,
544+
subscription=cnv_subscription_scope_session,
545+
subscription_source=cnv_registry_source["cnv_subscription_source"],
546+
subscription_channel=build_info["channel"],
579547
)
580548
LOGGER.info("Successfully performed cnv upgrades from source EUS to non-EUS version.")
581549

@@ -585,32 +553,27 @@ def non_eus_to_target_eus_cnv_upgraded(
585553
admin_client,
586554
hco_namespace,
587555
eus_cnv_upgrade_path,
588-
eus_target_channel,
589556
cnv_subscription_scope_session,
590557
cnv_registry_source,
591558
hyperconverged_resource_scope_function,
592559
):
593-
version, cnv_image = next(iter(eus_cnv_upgrade_path[EUS].items()))
594-
LOGGER.info(f"Cnv upgrade to version {version} using image: {cnv_image}")
595-
perform_cnv_upgrade(
596-
admin_client=admin_client,
597-
cnv_image_url=cnv_image,
598-
cr_name=hyperconverged_resource_scope_function.name,
599-
hco_namespace=hco_namespace,
600-
cnv_target_version=version.lstrip("v"),
601-
subscription=cnv_subscription_scope_session,
602-
subscription_source=cnv_registry_source["cnv_subscription_source"],
603-
subscription_channel=eus_target_channel,
604-
)
605-
606-
607-
@pytest.fixture()
608-
def eus_created_target_hco_csv(admin_client, hco_namespace, eus_hco_target_csv_name):
609-
return get_csv_by_name(
610-
csv_name=eus_hco_target_csv_name,
611-
admin_client=admin_client,
612-
namespace=hco_namespace.name,
613-
)
560+
for version, build_info in sorted(
561+
eus_cnv_upgrade_path[EUS].items(),
562+
key=lambda item: Version(version=item[0]),
563+
):
564+
cnv_image = build_info["cnv_image_url"]
565+
LOGGER.info(f"Cnv upgrade to version {version} using image: {cnv_image}")
566+
perform_cnv_upgrade(
567+
admin_client=admin_client,
568+
cnv_image_url=cnv_image,
569+
cr_name=hyperconverged_resource_scope_function.name,
570+
hco_namespace=hco_namespace,
571+
cnv_target_version=version,
572+
subscription=cnv_subscription_scope_session,
573+
subscription_source=cnv_registry_source["cnv_subscription_source"],
574+
subscription_channel=build_info["channel"],
575+
)
576+
LOGGER.info("Successfully performed cnv upgrades from non-EUS to target EUS version.")
614577

615578

616579
@pytest.fixture()

tests/install_upgrade_operators/product_upgrade/test_eus_upgrade.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
LOGGER = logging.getLogger(__name__)
1010

11+
pytestmark = pytest.mark.usefixtures(
12+
"nodes_taints_before_upgrade",
13+
"nodes_labels_before_upgrade",
14+
)
15+
1116

1217
@pytest.mark.product_upgrade_test
1318
@pytest.mark.upgrade
@@ -20,7 +25,6 @@ def test_eus_upgrade_process(
2025
self,
2126
admin_client,
2227
hco_namespace,
23-
eus_target_cnv_version,
2428
eus_cnv_upgrade_path,
2529
worker_machine_config_pools_conditions,
2630
eus_applied_all_icsp,
@@ -31,14 +35,14 @@ def test_eus_upgrade_process(
3135
upgraded_odf,
3236
non_eus_to_target_eus_ocp_upgraded,
3337
non_eus_to_target_eus_cnv_upgraded,
34-
eus_created_target_hco_csv,
38+
created_target_hco_csv,
3539
eus_unpaused_workload_update,
3640
eus_unpaused_worker_mcp,
3741
):
3842
LOGGER.info("Validate EUS to EUS upgrade process")
3943
verify_upgrade_cnv(
4044
dyn_client=admin_client,
4145
hco_namespace=hco_namespace,
42-
expected_images=get_related_images_name_and_version(csv=eus_created_target_hco_csv).values(),
46+
expected_images=get_related_images_name_and_version(csv=created_target_hco_csv).values(),
4347
)
4448
LOGGER.info("EUS post upgrade validation completed.")

0 commit comments

Comments
 (0)