Skip to content

Commit

Permalink
Introduce run_for_all_clusters wrapper
Browse files Browse the repository at this point in the history
run_for_all_clusters allow to run existing function on all cluster
configs. It's usefull when you need to globally update some config value
for all clusters.

Signed-off-by: Petr Balogh <[email protected]>
  • Loading branch information
petr-balogh committed Dec 4, 2024
1 parent cef9105 commit 77b7b59
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ocs_ci/framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""
# Use the new python 3.7 dataclass decorator, which provides an object similar
# to a namedtuple, but allows type enforcement and defining methods.
import functools
import os
import yaml
import logging
Expand Down Expand Up @@ -451,6 +452,21 @@ def switch_to_cluster_by_cluster_type(self, cluster_type, num_of_cluster=0):
self.get_cluster_type_indices_list(cluster_type)[num_of_cluster]
)

def run_for_all_clusters(self, func):
"""
A decorator to run the decorated function for all clusters
and switch context between them.
"""

@functools.wraps(func)
def wrapper(*args, **kwargs):
for cluster_index in range(self.nclusters):
self.switch_ctx(cluster_index)
logger.info(f"Running '{func.__name__}' for cluster {cluster_index}")
func(*args, **kwargs)

return wrapper

class RunWithConfigContext(object):
def __init__(self, config_index):
self.original_config_index = config.cur_index
Expand Down
1 change: 1 addition & 0 deletions ocs_ci/utility/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def get_rp_launch_description():
return description


@config.run_for_all_clusters
def update_live_must_gather_image():
"""
Update live must gather image in the config.
Expand Down

0 comments on commit 77b7b59

Please sign in to comment.