From cef774a558661f79609cbee5f6a597a7b9378e11 Mon Sep 17 00:00:00 2001 From: Jake Callahan Date: Mon, 9 Feb 2026 14:12:54 -0500 Subject: [PATCH] djust openshift client import for compatibility Configuration: - Implement a try-except block for importing the `openshift.client` module to gracefully handle its removal in `openshift` versions >= 0.13. - Introduce a `_OPENSHIFT_CLIENT_AVAILABLE` flag to track the success of the `openshift.client` import. - Enhance the `_connect` method to raise an `ImportError` with a detailed message if the `openshift.client` module is not available. This guides users on required `openshift` library versions or migration to the dynamic client API, ensuring better compatibility with varying library versions. Refactoring: - Reordered import statements in `msazure.py` for `StorageManagementClient` for consistency. --- pyproject.toml | 3 ++- wrapanapi/systems/container/rhopenshift.py | 22 +++++++++++++++++++++- wrapanapi/systems/msazure.py | 4 ++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f1e95324..2782a779 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,6 +46,7 @@ dependencies = [ "azure-mgmt-network", "azure-mgmt-resource", "azure-mgmt-storage", + "azure-mgmt-subscription", "azure-storage-blob", "boto", "boto3", @@ -60,7 +61,7 @@ dependencies = [ "lxml", "miq-version", "msrestazure", - "openshift==0.3.4", + "openshift>=0.13.0", "ovirt-engine-sdk-python~=4.3", "packaging", "podman>5.0.0", diff --git a/wrapanapi/systems/container/rhopenshift.py b/wrapanapi/systems/container/rhopenshift.py index fbfcfce0..b47943ba 100644 --- a/wrapanapi/systems/container/rhopenshift.py +++ b/wrapanapi/systems/container/rhopenshift.py @@ -10,9 +10,21 @@ from kubernetes import client as kubeclient from kubernetes.client.rest import ApiException from miq_version import TemplateName, Version -from openshift import client as ociclient from wait_for import TimedOutError, wait_for +# Try to import openshift client module +# In openshift>=0.13, the static client module was removed in favor of the dynamic client +# For backward compatibility, we attempt the import but allow it to fail gracefully +try: + from openshift import client as ociclient + + _OPENSHIFT_CLIENT_AVAILABLE = True +except (ImportError, AttributeError): + # openshift.client module doesn't exist in openshift>=0.13 + # The OpenShift functionality will not work until code is migrated to dynamic client + ociclient = None + _OPENSHIFT_CLIENT_AVAILABLE = False + from wrapanapi.systems.base import System # this service allows to access db outside of openshift @@ -196,6 +208,14 @@ def _identifying_attrs(self): return {"hostname": self.hostname, "port": self.port} def _connect(self): + if not _OPENSHIFT_CLIENT_AVAILABLE or ociclient is None: + raise ImportError( + "The openshift.client module is not available. " + "OpenShift requires openshift<=0.13 which is incompatible with Python 3.9+, " + "or the code needs to be migrated to use the openshift.dynamic client API. " + "See https://github.com/openshift/openshift-restclient-python for guidance." + ) + url = "{proto}://{host}:{port}".format( proto=self.protocol, host=self.hostname, port=self.port ) diff --git a/wrapanapi/systems/msazure.py b/wrapanapi/systems/msazure.py index 50a5ab0c..a7c32397 100644 --- a/wrapanapi/systems/msazure.py +++ b/wrapanapi/systems/msazure.py @@ -14,10 +14,10 @@ from azure.mgmt.iothub import IotHubClient from azure.mgmt.network import NetworkManagementClient from azure.mgmt.network.models import NetworkSecurityGroup, SecurityRule -from azure.mgmt.resource import SubscriptionClient from azure.mgmt.resource.resources import ResourceManagementClient -from azure.mgmt.resource.subscriptions.models import SubscriptionState from azure.mgmt.storage import StorageManagementClient +from azure.mgmt.subscription import SubscriptionClient +from azure.mgmt.subscription.models import SubscriptionState from azure.storage.blob import BlobServiceClient from dateutil import parser from msrestazure.azure_exceptions import CloudError