Skip to content

Commit

Permalink
Save Preupgrade conf values in PREUPGRADE_CONFIG attr of the Config c…
Browse files Browse the repository at this point in the history
…lass

Signed-off-by: Shylesh Kumar Mohan <shmohan@redhat.com>
  • Loading branch information
shylesh authored and amr1ta committed Oct 8, 2024
1 parent c7eb756 commit 9bcecd7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 35 deletions.
2 changes: 1 addition & 1 deletion ocs_ci/framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Config:
# Use this variable to store any arbitrary key/values related
# to the upgrade context. Applicable only in the multicluster upgrade
# scenario
PREUPGRADE_CONFIG = field(default_factory=dict)
PREUPGRADE_CONFIG: dict = field(default_factory=dict)

def __post_init__(self):
self.reset()
Expand Down
4 changes: 4 additions & 0 deletions ocs_ci/framework/conf/default_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,7 @@ MULTICLUSTER:
acm_cluster: False
primary_cluster: False
active_acm_cluster: False

PREUPGRADE_CONFIG:
AUTH: null
MULTICLUSTER: null
5 changes: 4 additions & 1 deletion ocs_ci/ocs/dr_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ def __init__(
resource_name=None,
):
if not version_before_upgrade:
version_before_upgrade = config.ENV_DATA.get("ocs_version")
if config.PREUPGRADE_CONFIG.get('ENV_DATA').get("ocs_version", ''):
version_before_upgrade = config.PREUPGRADE_CONFIG['ENV_DATA'].get("ocs_version")
else:
version_before_upgrade = config.ENV_DATA.get("ocs_version")
if not ocs_registry_image:
ocs_registry_image = config.UPGRADE.get("upgrade_ocs_registry_image")
self.external_cluster = None
Expand Down
27 changes: 4 additions & 23 deletions ocs_ci/ocs/ocs_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from pkg_resources import parse_version
from tempfile import NamedTemporaryFile
import time
import yaml

from selenium.webdriver.common.by import By
from ocs_ci.framework import config
Expand Down Expand Up @@ -306,18 +305,6 @@ def get_parsed_versions(self):

return parsed_version_before_upgrade, parsed_upgrade_version

def store_pre_upgrade_ctx(self):
"""
Store pre upgrade ctx values in config.upgrade_ctx
"""
version_config_file = os.path.join(
constants.OCS_VERSION_CONF_DIR, f"ocs-{self.version_before_upgrade}.yaml"
)
buf = yaml.safe_load(version_config_file)



def load_version_config_file(self, upgrade_version):
"""
Loads config file to the ocs-ci config with upgrade version
Expand All @@ -339,15 +326,6 @@ def load_version_config_file(self, upgrade_version):
version_config_file = os.path.join(
constants.OCS_VERSION_CONF_DIR, f"ocs-{upgrade_version}.yaml"
)
if config.multicluster:
# In case of multicluster upgrade
# we need to preserve the old config values so that
# any following tests will not read overwritten values
# we want to do it only once and the first test which hits this function
# will have the responsibility to store the previous config values
# TODO: CHANGE THIS TO STORE THE CONTEXT IN THE RESPECTIVE
# CONFIG CLASS DURING INITIAL STAGES OF THE UPGRADE RUN
self.save_pre_upgrade_ctx(version_config_file)
log.info(f"Reloading config file for OCS/ODF version: {upgrade_version}.")
load_config_file(version_config_file)
else:
Expand Down Expand Up @@ -394,7 +372,10 @@ def get_csv_name_pre_upgrade(self, resource_name=OCS_OPERATOR_NAME):
selector=operator_selector,
subscription_plan_approval=self.subscription_plan_approval,
)
channel = config.DEPLOYMENT.get("ocs_csv_channel")
if config.PREUPGRADE_CONFIG.et("DEPLOYMENT").get("ocs_csv_channel"):
channel = config.PREUPGRADE_CONFIG.et("DEPLOYMENT").get("ocs_csv_channel")
else:
channel = config.DEPLOYMENT.get("ocs_csv_channel")

return package_manifest.get_current_csv(channel)

Expand Down
10 changes: 0 additions & 10 deletions ocs_ci/ocs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1591,16 +1591,6 @@ def get_all_acm_indexes():
return acm_indexes


def is_acm_cluster():
"""
Check whether the current cluster in context is an ACM cluster
Returns:
bool: True if its an ACM cluster else False
"""
return ocsci_config.MULTICLUSTER["multicluster_index"] in get_all_acm_indexes()


def is_acm_cluster(cluster):
"""
Checks given cluster is acm cluster
Expand Down
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from math import floor
from shutil import copyfile, rmtree
from functools import partial
from copy import deepcopy

import boto3
import yaml
Expand Down Expand Up @@ -516,6 +517,13 @@ def pytest_collection_modifyitems(session, config, items):
log.info(
f"MARKERS = {[(i.name, i.args, i.kwargs) for i in item.iter_markers()]}"
)
# Update PREUPGRADE_CONFIG for each of the Config class
# so that in case of Y stream upgrade we will have preupgrade configurations for reference
# across the tests as Y stream upgrade will reload the config of target version
for cluster in ocsci_config.clusters:
for k in cluster.__dataclass_fields__.keys():
if k != 'PREUPGRADE_CONFIG':
cluster.PREUPGRADE_CONFIG[k] = deepcopy(getattr(cluster, k))


def pytest_collection_finish(session):
Expand Down

0 comments on commit 9bcecd7

Please sign in to comment.