Skip to content

Commit 6c821fb

Browse files
authored
Update python SDK version and Fix info module (#190)
Signed-off-by: Luis Liu <[email protected]>
1 parent f10d149 commit 6c821fb

File tree

7 files changed

+59
-13
lines changed

7 files changed

+59
-13
lines changed

plugins/module_utils/storage/dell/shared_library/cluster.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,16 @@ def get_cluster_owner_details(self):
6363
error_message = f"Failed to get the details of cluster owner details with error: {utils.determine_error(e)}"
6464
LOG.error(error_message)
6565
self.module.fail_json(msg=error_message)
66+
67+
def get_maintenance_settings_details(self):
68+
"""
69+
Get cluster maintenance settings
70+
:return: Cluster maintenance settings details.
71+
"""
72+
try:
73+
cluster_maintenance_settings = self.cluster_api.get_maintenance_settings()
74+
return cluster_maintenance_settings.to_dict()
75+
except Exception as e:
76+
error_message = f"Failed to get the details of cluster maintenance settings with error: {utils.determine_error(e)}"
77+
LOG.error(error_message)
78+
self.module.fail_json(msg=error_message)

plugins/module_utils/storage/dell/utils.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def get_powerscale_management_host_parameters():
114114
def get_powerscale_connection(module_params):
115115
if HAS_POWERSCALE_SDK:
116116
if isi_sdk.__name__ == "isilon_sdk":
117-
conn = isi_sdk.v9_5_0.Configuration()
117+
conn = isi_sdk.v9_10_0.Configuration()
118118
else:
119119
conn = isi_sdk.Configuration()
120120
if module_params['port_no'] is not None:
@@ -126,7 +126,7 @@ def get_powerscale_connection(module_params):
126126
conn.username = module_params['api_user']
127127
conn.password = module_params['api_password']
128128
if isi_sdk.__name__ == "isilon_sdk":
129-
api_client = isi_sdk.v9_5_0.ApiClient(conn)
129+
api_client = isi_sdk.v9_10_0.ApiClient(conn)
130130
else:
131131
api_client = isi_sdk.ApiClient(conn)
132132
return api_client
@@ -266,12 +266,14 @@ def validate_module_pre_reqs(module_params):
266266
''' Import compatible powerscale sdk based on onefs version '''
267267

268268

269-
def import_powerscale_sdk(sdk):
269+
def import_powerscale_sdk(sdk, major, minor):
270270
try:
271271
global isi_sdk
272272
global ApiException
273273
global HAS_POWERSCALE_SDK
274274
isi_sdk = importlib.import_module(sdk)
275+
isi_sdk.major = major
276+
isi_sdk.minor = minor
275277
ApiException = getattr(importlib.import_module(sdk + ".rest"),
276278
'ApiException')
277279
HAS_POWERSCALE_SDK = True
@@ -291,7 +293,7 @@ def find_compatible_powerscale_sdk(module_params):
291293
if pkg.key.startswith("isilon-sdk")]
292294
if powerscale_packages:
293295
powerscale_sdk = powerscale_packages[0].key.replace('-', '_')
294-
import_powerscale_sdk(powerscale_sdk + ".v9_5_0")
296+
import_powerscale_sdk(powerscale_sdk + ".v9_10_0", 9, 10)
295297
try:
296298
HAS_POWERSCALE_SDK = True
297299
api_client = get_powerscale_connection(module_params)
@@ -300,11 +302,8 @@ def find_compatible_powerscale_sdk(module_params):
300302
minor = str(parse_version(cluster_api.get_cluster_config().to_dict()['onefs_version']['release'].split('.')[1]))
301303
array_version = major + "_" + minor + "_0"
302304

303-
if int(minor) >= 5:
304-
compatible_powerscale_sdk = "isilon_sdk.v9_5_0"
305-
else:
306-
compatible_powerscale_sdk = "isilon_sdk.v" + array_version
307-
import_powerscale_sdk(compatible_powerscale_sdk)
305+
compatible_powerscale_sdk = "isilon_sdk.v" + array_version
306+
import_powerscale_sdk(compatible_powerscale_sdk, int(major), int(minor))
308307

309308
except Exception as e:
310309
HAS_POWERSCALE_SDK = False

plugins/modules/info.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3270,8 +3270,8 @@ def __init__(self):
32703270

32713271
self.api_client = utils.get_powerscale_connection(self.module.params)
32723272
self.isi_sdk = utils.get_powerscale_sdk()
3273-
self.major = int(str(self.isi_sdk)[21])
3274-
self.minor = int(str(self.isi_sdk)[23])
3273+
self.major = self.isi_sdk.major
3274+
self.minor = self.isi_sdk.minor
32753275
LOG.info('Got python SDK instance for provisioning on PowerScale ')
32763276

32773277
self.cluster_api = self.isi_sdk.ClusterApi(self.api_client)
@@ -4003,6 +4003,13 @@ def get_support_assist_settings(self):
40034003
else:
40044004
return {}
40054005

4006+
def get_maintenance_settings(self):
4007+
"""Get maintenance settings based on the version."""
4008+
if self.major > 9 or (self.major == 9 and self.minor > 9):
4009+
return Cluster(self.cluster_api, self.module).get_maintenance_settings_details()
4010+
else:
4011+
return Events(self.event_api, self.module).get_event_maintenance()
4012+
40064013
def perform_module_operation(self):
40074014
"""Perform different actions on Gatherfacts based on user parameter chosen in playbook"""
40084015
include_all_access_zones = self.module.params['include_all_access_zones']
@@ -4109,7 +4116,7 @@ def perform_module_operation(self):
41094116
'server_certificate': lambda: Certificate(self.certificate_api, self.module).get_server_certificate_with_default(),
41104117
'roles': lambda: Auth(self.auth_api, self.module).get_auth_roles(access_zone),
41114118
'support_assist_settings': self.get_support_assist_settings,
4112-
'alert_settings': lambda: Events(self.event_api, self.module).get_event_maintenance(),
4119+
'alert_settings': self.get_maintenance_settings,
41134120
'alert_rules': lambda: Events(self.event_api, self.module).get_alert_rules(),
41144121
'alert_categories': lambda: Events(self.event_api, self.module).get_alert_categories(),
41154122
'alert_channels': lambda: Events(self.event_api, self.module).get_event_channels(),

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
isilon-sdk==0.3.0.1
1+
isilon-sdk==0.6.0

tests/unit/plugins/module_utils/mock_info_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,6 +1953,7 @@ def get_gather_facts_error_method(gather_subset):
19531953
"alert_categories": "get_event_categories",
19541954
"alert_channels": "list_event_channels",
19551955
"alert_settings": "get_event_maintenance",
1956+
"alert_settings_911": "get_maintenance_settings",
19561957
"smartquota": "list_quota_quotas",
19571958
"filesystem": "get_directory_contents",
19581959
"writable_snapshots": "list_snapshot_writable",

tests/unit/plugins/module_utils/shared_library/initial_mock.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
utils.get_logger = MagicMock()
1313
utils.isi_sdk = MagicMock()
14+
utils.isi_sdk.major = 9
15+
utils.isi_sdk.minor = 7
1416
utils.ISI_SDK_VERSION_9 = MagicMock(return_value=True)
1517
PREREQS_VALIDATE = {
1618
"all_packages_found": True

tests/unit/plugins/modules/test_info.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,30 @@ def test_get_facts_alert_settings_api_module(self, powerscale_module_mock, input
601601
assert MockGatherfactsApi.get_gather_facts_module_response(
602602
gather_subset) == powerscale_module_mock.module.exit_json.call_args[1][return_key]
603603

604+
@pytest.mark.parametrize("input_params", [
605+
{"gather_subset": "alert_settings", "return_key": "alert_settings"}
606+
]
607+
)
608+
def test_get_facts_alert_settings_api_911_module(self, powerscale_module_mock, input_params):
609+
"""Test the get_facts that uses the alert settings api endpoint to get the module response"""
610+
611+
gather_subset = input_params.get('gather_subset')
612+
return_key = input_params.get('return_key')
613+
api_response = MockGatherfactsApi.get_gather_facts_api_response(
614+
gather_subset)
615+
self.get_module_args.update({
616+
'gather_subset': ['alert_settings']
617+
})
618+
powerscale_module_mock.major = 9
619+
powerscale_module_mock.minor = 11
620+
powerscale_module_mock.module.params = self.get_module_args
621+
with patch.object(powerscale_module_mock.cluster_api,
622+
MockGatherfactsApi.get_gather_facts_error_method("alert_settings_911")) as mock_method:
623+
mock_method.return_value = MockSDKResponse(api_response)
624+
powerscale_module_mock.perform_module_operation()
625+
assert MockGatherfactsApi.get_gather_facts_module_response(
626+
gather_subset) == powerscale_module_mock.module.exit_json.call_args[1][return_key]
627+
604628
@pytest.mark.parametrize("gather_subset", ["alert_settings"])
605629
def test_get_facts_alert_settings_api_exception(self, powerscale_module_mock, gather_subset):
606630
"""Test the get_facts that uses the alert settings api endpoint to get the exception"""

0 commit comments

Comments
 (0)