From dd133f4491a461b44a008389cba123567fea1c45 Mon Sep 17 00:00:00 2001 From: David Parker Date: Tue, 17 Dec 2024 17:02:11 +0000 Subject: [PATCH] [patch] Return none when there is no subscription --- src/mas/devops/mas.py | 11 ++++------- test/src/test_mas.py | 5 +++++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/mas/devops/mas.py b/src/mas/devops/mas.py index 1abce036..521c16cd 100644 --- a/src/mas/devops/mas.py +++ b/src/mas/devops/mas.py @@ -149,14 +149,11 @@ def getMasChannel(dynClient: DynamicClient, instanceId: str) -> str: """ Get the MAS channel from the subscription """ - try: - masSubscription = getSubscription(dynClient, f"mas-{instanceId}-core", "ibm-mas") + masSubscription = getSubscription(dynClient, f"mas-{instanceId}-core", "ibm-mas") + if masSubscription is None: + return None + else: return masSubscription.spec.channel - except NotFoundError: - return False - except UnauthorizedError: - logger.error("Error: Unable to verify MAS instance due to failed authorization: {e}") - return False def updateIBMEntitlementKey(dynClient: DynamicClient, namespace: str, icrUsername: str, icrPassword: str, artifactoryUsername: str = None, artifactoryPassword: str = None, secretName: str = "ibm-entitlement") -> ResourceInstance: diff --git a/test/src/test_mas.py b/test/src/test_mas.py index 7b74d09d..b1b15bea 100644 --- a/test/src/test_mas.py +++ b/test/src/test_mas.py @@ -51,3 +51,8 @@ def test_entitlement_alt_name(): assert secret is not None assert isinstance(secret, ResourceInstance) assert secret.metadata.name == "ibm-entitlement-key" + + +def test_get_channel(): + channel = mas.getMasChannel(dynClient, "doesnotexist") + assert channel is None