Skip to content

Commit

Permalink
Merge pull request #55 from oharan2/rosa_sampler
Browse files Browse the repository at this point in the history
Use sampler for rosa cli
  • Loading branch information
myakove authored Jun 6, 2023
2 parents c46961f + 8f7ca45 commit 70da58c
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions ocm_python_wrapper/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from ocm_python_wrapper.exceptions import MissingResourceError

LOGGER = get_logger(__name__)
TIMEOUT_5MIN = 5 * 60
TIMEOUT_10MIN = 10 * 60
TIMEOUT_30MIN = 30 * 60
SLEEP_1SEC = 1
Expand Down Expand Up @@ -377,6 +378,13 @@ def install_addon(
Returns:
AddOnInstallation or list: list of stdout responses if rosa is True, else AddOnInstallation
"""

def _wait_for_rhoam_installation(_command):
for rosa_sampler in self.addon_installation_instance_sampler(
func=rosa_cli.execute, wait_timeout=TIMEOUT_5MIN, command=_command
):
return rosa_sampler

addon = AddOn(id=self.addon_name)
_addon_installation_dict = {
"id": self.addon_name,
Expand All @@ -396,11 +404,15 @@ def install_addon(
params_command = ""
for parameter in parameters:
params_command += f" --{parameter['id']} {parameter['value']}"
# TODO remove support for billing-model flag once https://github.com/openshift/rosa/issues/1279 resolved
res = rosa_cli.execute(
command=f"install addon {self.addon_name} --cluster {self.name} {params_command}"
f" --billing-model standard"
)

# TODO: remove support for billing-model flag once https://github.com/openshift/rosa/issues/1279 resolved
command = f"install addon {self.addon_name} --cluster {self.name} {params_command} --billing-model standard"

if self.addon_name == "managed-api-service":
# TODO: remove _wait_for_rhoam_installation after https://github.com/openshift/rosa/issues/970 resolved
res = _wait_for_rhoam_installation(_command=command)
else:
res = rosa_cli.execute(command=command)
else:
if parameters:
_parameters = []
Expand Down Expand Up @@ -457,19 +469,14 @@ def addon_installation_instance(self):
LOGGER.info(f"{self.addon_name} not found")
return

def addon_installation_instance_sampler(self, wait_timeout=TIMEOUT_30MIN):
return TimeoutSampler(
wait_timeout=wait_timeout,
sleep=SLEEP_1SEC,
func=self.addon_installation_instance,
)

def wait_for_install_state(self, state, wait_timeout=TIMEOUT_30MIN):
_state = None
try:
for (
_addon_installation_instance
) in self.addon_installation_instance_sampler(wait_timeout=wait_timeout):
) in self.addon_installation_instance_sampler(
func=self.addon_installation_instance, wait_timeout=wait_timeout
):
_state = str(_addon_installation_instance.get("state"))
if _state == state:
return True
Expand Down Expand Up @@ -504,7 +511,9 @@ def uninstall_addon(self, wait=True, wait_timeout=TIMEOUT_30MIN, rosa=False):
if wait:
for (
_addon_installation_instance
) in self.addon_installation_instance_sampler(wait_timeout=wait_timeout):
) in self.addon_installation_instance_sampler(
func=self.addon_installation_instance, wait_timeout=wait_timeout
):
if not _addon_installation_instance:
return True
LOGGER.info(f"{self.addon_name} v{self.addon_version} was successfully removed")
Expand Down Expand Up @@ -574,3 +583,9 @@ def check_param_conditions(clusters_dict, condition, condition_value):
isinstance(condition_value, list)
and cluster_condition_value in condition_value
) or cluster_condition_value == condition_value

@staticmethod
def addon_installation_instance_sampler(func, wait_timeout=TIMEOUT_30MIN, **kwargs):
return TimeoutSampler(
wait_timeout=wait_timeout, sleep=SLEEP_1SEC, func=func, **kwargs
)

0 comments on commit 70da58c

Please sign in to comment.