Skip to content

Update python SDK version and Fix info module #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions plugins/module_utils/storage/dell/shared_library/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,16 @@ def get_cluster_owner_details(self):
error_message = f"Failed to get the details of cluster owner details with error: {utils.determine_error(e)}"
LOG.error(error_message)
self.module.fail_json(msg=error_message)

def get_maintenance_settings_details(self):
"""
Get cluster maintenance settings
:return: Cluster maintenance settings details.
"""
try:
cluster_maintenance_settings = self.cluster_api.get_maintenance_settings()
return cluster_maintenance_settings.to_dict()
except Exception as e:
error_message = f"Failed to get the details of cluster maintenance settings with error: {utils.determine_error(e)}"
LOG.error(error_message)
self.module.fail_json(msg=error_message)
17 changes: 8 additions & 9 deletions plugins/module_utils/storage/dell/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def get_powerscale_management_host_parameters():
def get_powerscale_connection(module_params):
if HAS_POWERSCALE_SDK:
if isi_sdk.__name__ == "isilon_sdk":
conn = isi_sdk.v9_5_0.Configuration()
conn = isi_sdk.v9_10_0.Configuration()
else:
conn = isi_sdk.Configuration()
if module_params['port_no'] is not None:
Expand All @@ -126,7 +126,7 @@ def get_powerscale_connection(module_params):
conn.username = module_params['api_user']
conn.password = module_params['api_password']
if isi_sdk.__name__ == "isilon_sdk":
api_client = isi_sdk.v9_5_0.ApiClient(conn)
api_client = isi_sdk.v9_10_0.ApiClient(conn)
else:
api_client = isi_sdk.ApiClient(conn)
return api_client
Expand Down Expand Up @@ -266,12 +266,14 @@ def validate_module_pre_reqs(module_params):
''' Import compatible powerscale sdk based on onefs version '''


def import_powerscale_sdk(sdk):
def import_powerscale_sdk(sdk, major, minor):
try:
global isi_sdk
global ApiException
global HAS_POWERSCALE_SDK
isi_sdk = importlib.import_module(sdk)
isi_sdk.major = major
isi_sdk.minor = minor
ApiException = getattr(importlib.import_module(sdk + ".rest"),
'ApiException')
HAS_POWERSCALE_SDK = True
Expand All @@ -291,7 +293,7 @@ def find_compatible_powerscale_sdk(module_params):
if pkg.key.startswith("isilon-sdk")]
if powerscale_packages:
powerscale_sdk = powerscale_packages[0].key.replace('-', '_')
import_powerscale_sdk(powerscale_sdk + ".v9_5_0")
import_powerscale_sdk(powerscale_sdk + ".v9_10_0", 9, 10)
try:
HAS_POWERSCALE_SDK = True
api_client = get_powerscale_connection(module_params)
Expand All @@ -300,11 +302,8 @@ def find_compatible_powerscale_sdk(module_params):
minor = str(parse_version(cluster_api.get_cluster_config().to_dict()['onefs_version']['release'].split('.')[1]))
array_version = major + "_" + minor + "_0"

if int(minor) >= 5:
compatible_powerscale_sdk = "isilon_sdk.v9_5_0"
else:
compatible_powerscale_sdk = "isilon_sdk.v" + array_version
import_powerscale_sdk(compatible_powerscale_sdk)
compatible_powerscale_sdk = "isilon_sdk.v" + array_version
import_powerscale_sdk(compatible_powerscale_sdk, int(major), int(minor))

except Exception as e:
HAS_POWERSCALE_SDK = False
Expand Down
13 changes: 10 additions & 3 deletions plugins/modules/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3270,8 +3270,8 @@ def __init__(self):

self.api_client = utils.get_powerscale_connection(self.module.params)
self.isi_sdk = utils.get_powerscale_sdk()
self.major = int(str(self.isi_sdk)[21])
self.minor = int(str(self.isi_sdk)[23])
self.major = self.isi_sdk.major
self.minor = self.isi_sdk.minor
LOG.info('Got python SDK instance for provisioning on PowerScale ')

self.cluster_api = self.isi_sdk.ClusterApi(self.api_client)
Expand Down Expand Up @@ -4003,6 +4003,13 @@ def get_support_assist_settings(self):
else:
return {}

def get_maintenance_settings(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would UT be updated to cover the change?

Copy link
Contributor

@P-Cao P-Cao Jun 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is partially covered. Is it possible to add test for utils.isi_sdk.minor > 9 to cover the other case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add overall coverage report

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check #190 (comment)

"""Get maintenance settings based on the version."""
if self.major > 9 or (self.major == 9 and self.minor > 9):
return Cluster(self.cluster_api, self.module).get_maintenance_settings_details()
else:
return Events(self.event_api, self.module).get_event_maintenance()

def perform_module_operation(self):
"""Perform different actions on Gatherfacts based on user parameter chosen in playbook"""
include_all_access_zones = self.module.params['include_all_access_zones']
Expand Down Expand Up @@ -4109,7 +4116,7 @@ def perform_module_operation(self):
'server_certificate': lambda: Certificate(self.certificate_api, self.module).get_server_certificate_with_default(),
'roles': lambda: Auth(self.auth_api, self.module).get_auth_roles(access_zone),
'support_assist_settings': self.get_support_assist_settings,
'alert_settings': lambda: Events(self.event_api, self.module).get_event_maintenance(),
'alert_settings': self.get_maintenance_settings,
'alert_rules': lambda: Events(self.event_api, self.module).get_alert_rules(),
'alert_categories': lambda: Events(self.event_api, self.module).get_alert_categories(),
'alert_channels': lambda: Events(self.event_api, self.module).get_event_channels(),
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
isilon-sdk==0.3.0.1
isilon-sdk==0.6.0
1 change: 1 addition & 0 deletions tests/unit/plugins/module_utils/mock_info_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1953,6 +1953,7 @@ def get_gather_facts_error_method(gather_subset):
"alert_categories": "get_event_categories",
"alert_channels": "list_event_channels",
"alert_settings": "get_event_maintenance",
"alert_settings_911": "get_maintenance_settings",
"smartquota": "list_quota_quotas",
"filesystem": "get_directory_contents",
"writable_snapshots": "list_snapshot_writable",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

utils.get_logger = MagicMock()
utils.isi_sdk = MagicMock()
utils.isi_sdk.major = 9
utils.isi_sdk.minor = 7
utils.ISI_SDK_VERSION_9 = MagicMock(return_value=True)
PREREQS_VALIDATE = {
"all_packages_found": True
Expand Down
24 changes: 24 additions & 0 deletions tests/unit/plugins/modules/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,30 @@ def test_get_facts_alert_settings_api_module(self, powerscale_module_mock, input
assert MockGatherfactsApi.get_gather_facts_module_response(
gather_subset) == powerscale_module_mock.module.exit_json.call_args[1][return_key]

@pytest.mark.parametrize("input_params", [
{"gather_subset": "alert_settings", "return_key": "alert_settings"}
]
)
def test_get_facts_alert_settings_api_911_module(self, powerscale_module_mock, input_params):
"""Test the get_facts that uses the alert settings api endpoint to get the module response"""

gather_subset = input_params.get('gather_subset')
return_key = input_params.get('return_key')
api_response = MockGatherfactsApi.get_gather_facts_api_response(
gather_subset)
self.get_module_args.update({
'gather_subset': ['alert_settings']
})
powerscale_module_mock.major = 9
powerscale_module_mock.minor = 11
powerscale_module_mock.module.params = self.get_module_args
with patch.object(powerscale_module_mock.cluster_api,
MockGatherfactsApi.get_gather_facts_error_method("alert_settings_911")) as mock_method:
mock_method.return_value = MockSDKResponse(api_response)
powerscale_module_mock.perform_module_operation()
assert MockGatherfactsApi.get_gather_facts_module_response(
gather_subset) == powerscale_module_mock.module.exit_json.call_args[1][return_key]

@pytest.mark.parametrize("gather_subset", ["alert_settings"])
def test_get_facts_alert_settings_api_exception(self, powerscale_module_mock, gather_subset):
"""Test the get_facts that uses the alert settings api endpoint to get the exception"""
Expand Down