Skip to content

Commit

Permalink
Fix context manager
Browse files Browse the repository at this point in the history
Signed-off-by: oviner <[email protected]>
  • Loading branch information
OdedViner committed Jun 6, 2024
1 parent 5791194 commit 4e822ab
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions ocs_ci/ocs/acm/acm.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ def create_credential(self):
Create credential
"""
with RunWithConfigContext():
with RunWithAcmConfigContext():
cred_vsphere = templating.load_yaml(constants.ACM_VSPHERE_CRED_YAML)
cred_vsphere["stringData"]["vCenter"] = config.ENV_DATA["vsphere_server"]
cred_vsphere["stringData"]["username"] = config.ENV_DATA["vsphere_user"]
Expand All @@ -690,7 +690,7 @@ def create_credential(self):
manifest = tempfile.NamedTemporaryFile(
mode="w+", prefix="manifest-", delete=False
)
logging.info(f"Tmp file name: {manifest.name}")
log.info(f"Tmp file name: {manifest.name}")
templating.dump_data_to_temp_yaml(cred_vsphere, manifest.name)
run_cmd(f"oc apply -f {manifest.name}")

Expand Down Expand Up @@ -881,7 +881,7 @@ def delete_cluster(self):
Delete cluster
"""
with RunWithConfigContext():
with RunWithAcmConfigContext():
ocp_obj = OCP()
log.info(f"Detach a managed cluster {self.cluster_name}")
ocp_obj.exec_oc_cmd(
Expand All @@ -904,7 +904,7 @@ def apply_manifest(self, data):
manifest = tempfile.NamedTemporaryFile(
mode="w+", prefix="manifest-", delete=False
)
logging.info(f"Tmp file name: {manifest.name}")
log.info(f"Tmp file name: {manifest.name}")
templating.dump_data_to_temp_yaml(data, manifest.name)
self.file_paths.append(manifest.name)

Expand All @@ -916,7 +916,7 @@ def download_kubeadmin_password(self):
kuconfig, kubeadmin-password (tuple):
"""
with RunWithConfigContext():
with RunWithAcmConfigContext():
kubeadmin_password_secret_name = get_secret_name_by_pattern(
pattern="admin-password", namespace=self.cluster_name
)
Expand Down Expand Up @@ -945,7 +945,7 @@ def verify_cluster_status(self):
Verify new OCP cluster created
"""
with RunWithConfigContext():
with RunWithAcmConfigContext():
ocp_obj = OCP(kind=constants.ACM_MANAGEDCLUSTER)
ocp_obj.wait_for_resource(
timeout=10,
Expand Down Expand Up @@ -993,13 +993,19 @@ def create_cluster(self):


class RunWithConfigContext(object):
def __init__(self):
def __init__(self, config_index):
self.original_config_index = config.cur_index
self.acm_index = get_all_acm_indexes()[0]
self.config_index = config_index

def __enter__(self):
config.switch_ctx(self.acm_index)
config.switch_ctx(self.config_index)
return self

def __exit__(self, exc_type, exc_value, exc_traceback):
config.switch_ctx(self.original_config_index)


class RunWithAcmConfigContext(RunWithConfigContext):
def __init__(self):
acm_index = get_all_acm_indexes()[0]
super().__init__(acm_index)

0 comments on commit 4e822ab

Please sign in to comment.