From c7eb7563942226b5507cf5479b6cd85d8627a3f1 Mon Sep 17 00:00:00 2001 From: Shylesh Kumar Mohan Date: Wed, 31 Jul 2024 22:16:05 +0100 Subject: [PATCH] Handle reload of the configs during upgrades Signed-off-by: Shylesh Kumar Mohan --- ocs_ci/framework/__init__.py | 4 ++++ ocs_ci/ocs/ocs_upgrade.py | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/ocs_ci/framework/__init__.py b/ocs_ci/framework/__init__.py index be332687753..5cc491ed755 100644 --- a/ocs_ci/framework/__init__.py +++ b/ocs_ci/framework/__init__.py @@ -37,6 +37,10 @@ class Config: COMPONENTS: dict = field(default_factory=dict) # Used for multicluster only MULTICLUSTER: dict = field(default_factory=dict) + # 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) def __post_init__(self): self.reset() diff --git a/ocs_ci/ocs/ocs_upgrade.py b/ocs_ci/ocs/ocs_upgrade.py index a791c9be76a..13ccf75afea 100644 --- a/ocs_ci/ocs/ocs_upgrade.py +++ b/ocs_ci/ocs/ocs_upgrade.py @@ -4,6 +4,7 @@ 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 @@ -305,6 +306,18 @@ 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 @@ -326,6 +339,15 @@ 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: