From 12a76fb53466ed016d3a33bdcb549d83e0df8bff Mon Sep 17 00:00:00 2001 From: Ori Haran Date: Wed, 31 May 2023 19:52:21 +0300 Subject: [PATCH 01/10] Use addon_installation_instance_sampler as static method --- ocm_python_wrapper/cluster.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/ocm_python_wrapper/cluster.py b/ocm_python_wrapper/cluster.py index 979b94f..c725a0b 100644 --- a/ocm_python_wrapper/cluster.py +++ b/ocm_python_wrapper/cluster.py @@ -457,19 +457,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 @@ -504,7 +499,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") @@ -574,3 +571,11 @@ 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): + return TimeoutSampler( + wait_timeout=wait_timeout, + sleep=SLEEP_1SEC, + func=func, + ) From 95b76e68462904a3c46c713591c29c3494a2afa0 Mon Sep 17 00:00:00 2001 From: Ori Haran Date: Wed, 31 May 2023 20:26:17 +0300 Subject: [PATCH 02/10] Try sampler --- ocm_python_wrapper/cluster.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ocm_python_wrapper/cluster.py b/ocm_python_wrapper/cluster.py index c725a0b..666aa9e 100644 --- a/ocm_python_wrapper/cluster.py +++ b/ocm_python_wrapper/cluster.py @@ -1,6 +1,7 @@ import os from importlib.util import find_spec +import ipdb import rosa.cli as rosa_cli import yaml from benedict import benedict @@ -579,3 +580,22 @@ def addon_installation_instance_sampler(func, wait_timeout=TIMEOUT_30MIN): sleep=SLEEP_1SEC, func=func, ) + + +def wait_for_rosa_installation(command, wait_timeout=TIMEOUT_30MIN): + ipdb.set_trace() + for rosa_sampler in TimeoutSampler( + wait_timeout=wait_timeout, + sleep=SLEEP_1SEC, + func=lambda: rosa_cli.execute(command=command), + ): + ipdb.set_trace() + if rosa_sampler: + return True + ipdb.set_trace() + # except TimeoutExpiredError: + # LOGGER.error( + # f"Timeout waiting for {self.addon_name} state to execute {command}" + # ) + # raise + return False From fc9a52085d4558278baee7e6290a5d9a478d0cc6 Mon Sep 17 00:00:00 2001 From: Ori Haran Date: Thu, 1 Jun 2023 14:51:26 +0300 Subject: [PATCH 03/10] Rebased --- ocm_python_wrapper/cluster.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/ocm_python_wrapper/cluster.py b/ocm_python_wrapper/cluster.py index 666aa9e..08a25d5 100644 --- a/ocm_python_wrapper/cluster.py +++ b/ocm_python_wrapper/cluster.py @@ -402,6 +402,7 @@ def install_addon( command=f"install addon {self.addon_name} --cluster {self.name} {params_command}" f" --billing-model standard" ) + ipdb.set_trace() else: if parameters: _parameters = [] @@ -583,19 +584,16 @@ def addon_installation_instance_sampler(func, wait_timeout=TIMEOUT_30MIN): def wait_for_rosa_installation(command, wait_timeout=TIMEOUT_30MIN): - ipdb.set_trace() - for rosa_sampler in TimeoutSampler( - wait_timeout=wait_timeout, - sleep=SLEEP_1SEC, - func=lambda: rosa_cli.execute(command=command), - ): - ipdb.set_trace() - if rosa_sampler: - return True - ipdb.set_trace() - # except TimeoutExpiredError: - # LOGGER.error( - # f"Timeout waiting for {self.addon_name} state to execute {command}" - # ) - # raise - return False + try: + for rosa_sampler in TimeoutSampler( + wait_timeout=wait_timeout, + sleep=SLEEP_1SEC, + func=lambda: rosa_cli.execute(command=command), + ): + ipdb.set_trace() + print(rosa_sampler) + if "Failed to add operator role to cluster" not in rosa_sampler: + return rosa_sampler + except TimeoutExpiredError: + LOGGER.error(f"Timeout waiting to execute {command}") + raise From 7f8ecd743f3f40c63eb9178c94dfb24d425f9607 Mon Sep 17 00:00:00 2001 From: Ori Haran Date: Thu, 1 Jun 2023 16:24:50 +0300 Subject: [PATCH 04/10] Updated to _wait_for_rhoam_installation --- ocm_python_wrapper/cluster.py | 47 ++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/ocm_python_wrapper/cluster.py b/ocm_python_wrapper/cluster.py index 08a25d5..51b18e2 100644 --- a/ocm_python_wrapper/cluster.py +++ b/ocm_python_wrapper/cluster.py @@ -1,7 +1,6 @@ import os from importlib.util import find_spec -import ipdb import rosa.cli as rosa_cli import yaml from benedict import benedict @@ -25,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 @@ -378,6 +378,20 @@ def install_addon( Returns: AddOnInstallation or list: list of stdout responses if rosa is True, else AddOnInstallation """ + + def _wait_for_rhoam_installation(_command): + try: + for rosa_sampler in TimeoutSampler( + wait_timeout=TIMEOUT_5MIN, + sleep=SLEEP_1SEC, + func=rosa_cli.execute, + command=_command, + ): + return rosa_sampler + except TimeoutExpiredError: + LOGGER.error(f"Timeout waiting to execute {_command}") + raise + addon = AddOn(id=self.addon_name) _addon_installation_dict = { "id": self.addon_name, @@ -397,12 +411,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" - ) - ipdb.set_trace() + + # 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 = [] @@ -581,19 +598,3 @@ def addon_installation_instance_sampler(func, wait_timeout=TIMEOUT_30MIN): sleep=SLEEP_1SEC, func=func, ) - - -def wait_for_rosa_installation(command, wait_timeout=TIMEOUT_30MIN): - try: - for rosa_sampler in TimeoutSampler( - wait_timeout=wait_timeout, - sleep=SLEEP_1SEC, - func=lambda: rosa_cli.execute(command=command), - ): - ipdb.set_trace() - print(rosa_sampler) - if "Failed to add operator role to cluster" not in rosa_sampler: - return rosa_sampler - except TimeoutExpiredError: - LOGGER.error(f"Timeout waiting to execute {command}") - raise From 44af094a8539a2997a1e07c33be632e8cea5f9f4 Mon Sep 17 00:00:00 2001 From: Ori Haran Date: Wed, 31 May 2023 19:52:21 +0300 Subject: [PATCH 05/10] Use addon_installation_instance_sampler as static method --- ocm_python_wrapper/cluster.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/ocm_python_wrapper/cluster.py b/ocm_python_wrapper/cluster.py index 979b94f..c725a0b 100644 --- a/ocm_python_wrapper/cluster.py +++ b/ocm_python_wrapper/cluster.py @@ -457,19 +457,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 @@ -504,7 +499,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") @@ -574,3 +571,11 @@ 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): + return TimeoutSampler( + wait_timeout=wait_timeout, + sleep=SLEEP_1SEC, + func=func, + ) From 6a4a1ad2c1828d332b9e04646f42f542c5757db3 Mon Sep 17 00:00:00 2001 From: Ori Haran Date: Wed, 31 May 2023 20:26:17 +0300 Subject: [PATCH 06/10] Try sampler --- ocm_python_wrapper/cluster.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ocm_python_wrapper/cluster.py b/ocm_python_wrapper/cluster.py index c725a0b..666aa9e 100644 --- a/ocm_python_wrapper/cluster.py +++ b/ocm_python_wrapper/cluster.py @@ -1,6 +1,7 @@ import os from importlib.util import find_spec +import ipdb import rosa.cli as rosa_cli import yaml from benedict import benedict @@ -579,3 +580,22 @@ def addon_installation_instance_sampler(func, wait_timeout=TIMEOUT_30MIN): sleep=SLEEP_1SEC, func=func, ) + + +def wait_for_rosa_installation(command, wait_timeout=TIMEOUT_30MIN): + ipdb.set_trace() + for rosa_sampler in TimeoutSampler( + wait_timeout=wait_timeout, + sleep=SLEEP_1SEC, + func=lambda: rosa_cli.execute(command=command), + ): + ipdb.set_trace() + if rosa_sampler: + return True + ipdb.set_trace() + # except TimeoutExpiredError: + # LOGGER.error( + # f"Timeout waiting for {self.addon_name} state to execute {command}" + # ) + # raise + return False From 81e5041f795fed98d811135a5db8428ef8bc6b10 Mon Sep 17 00:00:00 2001 From: Ori Haran Date: Thu, 1 Jun 2023 14:51:26 +0300 Subject: [PATCH 07/10] Rebased --- ocm_python_wrapper/cluster.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/ocm_python_wrapper/cluster.py b/ocm_python_wrapper/cluster.py index 666aa9e..08a25d5 100644 --- a/ocm_python_wrapper/cluster.py +++ b/ocm_python_wrapper/cluster.py @@ -402,6 +402,7 @@ def install_addon( command=f"install addon {self.addon_name} --cluster {self.name} {params_command}" f" --billing-model standard" ) + ipdb.set_trace() else: if parameters: _parameters = [] @@ -583,19 +584,16 @@ def addon_installation_instance_sampler(func, wait_timeout=TIMEOUT_30MIN): def wait_for_rosa_installation(command, wait_timeout=TIMEOUT_30MIN): - ipdb.set_trace() - for rosa_sampler in TimeoutSampler( - wait_timeout=wait_timeout, - sleep=SLEEP_1SEC, - func=lambda: rosa_cli.execute(command=command), - ): - ipdb.set_trace() - if rosa_sampler: - return True - ipdb.set_trace() - # except TimeoutExpiredError: - # LOGGER.error( - # f"Timeout waiting for {self.addon_name} state to execute {command}" - # ) - # raise - return False + try: + for rosa_sampler in TimeoutSampler( + wait_timeout=wait_timeout, + sleep=SLEEP_1SEC, + func=lambda: rosa_cli.execute(command=command), + ): + ipdb.set_trace() + print(rosa_sampler) + if "Failed to add operator role to cluster" not in rosa_sampler: + return rosa_sampler + except TimeoutExpiredError: + LOGGER.error(f"Timeout waiting to execute {command}") + raise From 42d1343b950e8c65e6cbd03c89f0e066702a2feb Mon Sep 17 00:00:00 2001 From: Ori Haran Date: Thu, 1 Jun 2023 16:24:50 +0300 Subject: [PATCH 08/10] Updated to _wait_for_rhoam_installation --- ocm_python_wrapper/cluster.py | 47 ++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/ocm_python_wrapper/cluster.py b/ocm_python_wrapper/cluster.py index 08a25d5..51b18e2 100644 --- a/ocm_python_wrapper/cluster.py +++ b/ocm_python_wrapper/cluster.py @@ -1,7 +1,6 @@ import os from importlib.util import find_spec -import ipdb import rosa.cli as rosa_cli import yaml from benedict import benedict @@ -25,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 @@ -378,6 +378,20 @@ def install_addon( Returns: AddOnInstallation or list: list of stdout responses if rosa is True, else AddOnInstallation """ + + def _wait_for_rhoam_installation(_command): + try: + for rosa_sampler in TimeoutSampler( + wait_timeout=TIMEOUT_5MIN, + sleep=SLEEP_1SEC, + func=rosa_cli.execute, + command=_command, + ): + return rosa_sampler + except TimeoutExpiredError: + LOGGER.error(f"Timeout waiting to execute {_command}") + raise + addon = AddOn(id=self.addon_name) _addon_installation_dict = { "id": self.addon_name, @@ -397,12 +411,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" - ) - ipdb.set_trace() + + # 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 = [] @@ -581,19 +598,3 @@ def addon_installation_instance_sampler(func, wait_timeout=TIMEOUT_30MIN): sleep=SLEEP_1SEC, func=func, ) - - -def wait_for_rosa_installation(command, wait_timeout=TIMEOUT_30MIN): - try: - for rosa_sampler in TimeoutSampler( - wait_timeout=wait_timeout, - sleep=SLEEP_1SEC, - func=lambda: rosa_cli.execute(command=command), - ): - ipdb.set_trace() - print(rosa_sampler) - if "Failed to add operator role to cluster" not in rosa_sampler: - return rosa_sampler - except TimeoutExpiredError: - LOGGER.error(f"Timeout waiting to execute {command}") - raise From b5c70ca1a9b4400482714b807ef9e28b978732dd Mon Sep 17 00:00:00 2001 From: Ori Haran Date: Sun, 4 Jun 2023 17:16:14 +0300 Subject: [PATCH 09/10] Removed try;except --- ocm_python_wrapper/cluster.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/ocm_python_wrapper/cluster.py b/ocm_python_wrapper/cluster.py index 51b18e2..727d5ff 100644 --- a/ocm_python_wrapper/cluster.py +++ b/ocm_python_wrapper/cluster.py @@ -380,17 +380,13 @@ def install_addon( """ def _wait_for_rhoam_installation(_command): - try: - for rosa_sampler in TimeoutSampler( - wait_timeout=TIMEOUT_5MIN, - sleep=SLEEP_1SEC, - func=rosa_cli.execute, - command=_command, - ): - return rosa_sampler - except TimeoutExpiredError: - LOGGER.error(f"Timeout waiting to execute {_command}") - raise + for rosa_sampler in TimeoutSampler( + wait_timeout=TIMEOUT_5MIN, + sleep=SLEEP_1SEC, + func=rosa_cli.execute, + command=_command, + ): + return rosa_sampler addon = AddOn(id=self.addon_name) _addon_installation_dict = { From 8f7ca4506670529ce17e48eb2414826f93103a65 Mon Sep 17 00:00:00 2001 From: Ori Haran Date: Mon, 5 Jun 2023 21:48:38 +0300 Subject: [PATCH 10/10] Added kwargs to addon_installation_instance_sampler --- ocm_python_wrapper/cluster.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/ocm_python_wrapper/cluster.py b/ocm_python_wrapper/cluster.py index 727d5ff..5bccb1f 100644 --- a/ocm_python_wrapper/cluster.py +++ b/ocm_python_wrapper/cluster.py @@ -380,11 +380,8 @@ def install_addon( """ def _wait_for_rhoam_installation(_command): - for rosa_sampler in TimeoutSampler( - wait_timeout=TIMEOUT_5MIN, - sleep=SLEEP_1SEC, - func=rosa_cli.execute, - command=_command, + for rosa_sampler in self.addon_installation_instance_sampler( + func=rosa_cli.execute, wait_timeout=TIMEOUT_5MIN, command=_command ): return rosa_sampler @@ -588,9 +585,7 @@ def check_param_conditions(clusters_dict, condition, condition_value): ) or cluster_condition_value == condition_value @staticmethod - def addon_installation_instance_sampler(func, wait_timeout=TIMEOUT_30MIN): + def addon_installation_instance_sampler(func, wait_timeout=TIMEOUT_30MIN, **kwargs): return TimeoutSampler( - wait_timeout=wait_timeout, - sleep=SLEEP_1SEC, - func=func, + wait_timeout=wait_timeout, sleep=SLEEP_1SEC, func=func, **kwargs )