Skip to content
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

Ansisilon 2077 info module #117

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
37 changes: 30 additions & 7 deletions plugins/modules/info.py
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we update the documentation with the following.

  1. Call out that smb files would return for all the clusters for this fact.
  2. It is assumed that credentials of all node is same as the I(hostname). if not only the smb files of the nodes that has same credentials will be returned.

Original file line number Diff line number Diff line change
Expand Up @@ -3700,17 +3700,41 @@ def get_storagepool_tiers(self):
LOG.error(error_msg)
self.module.fail_json(msg=error_msg)

def get_smb_files(self):
def get_smb_file_for_each_cluster(self, client):
"""Get the list of smb open files given PowerScale Storage"""
try:
smb_files_details = (self.protocol_api.get_smb_openfiles())\
.to_dict()
LOG.info('Got smb_files from PowerScale cluster %s',
self.module.params['onefs_host'])
return smb_files_details['openfiles']
self.protocol_api = self.isi_sdk.ProtocolsApi(client)
cluster_response = self.protocol_api.get_smb_openfiles().to_dict()
return cluster_response["openfiles"]
except Exception as e:
error_msg = (
'Getting list of smb open files for PowerScale: {0} failed with'
' error: {1}'.format(
client.onefs_host,
utils.determine_error(e)))
LOG.error(error_msg)
self.module.fail_json(msg=error_msg)

def get_smb_files(self):
"""Get the list of smb open files given PowerScale Storage"""
try:
api_response = self.cluster_api.get_cluster_external_ips()
smb_files_list = []
for each_ip in api_response:
LOG.info(self.api_client)
self.api_client.onefs_host = each_ip
smb_file = self.get_smb_file_for_each_cluster(self.api_client)
smb_files_list.append(smb_file)
filtered_smb_files_list = []
filters = self.module.params.get('filters')
filters_dict = self.get_filters(filters)
if filters_dict:
filtered_smb_files_list = filter_dict_list(smb_files_list, filters_dict)
return filtered_smb_files_list
return smb_files_list
except Exception as e:
error_msg = (
'Getting list of cluster external ips for PowerScale: {0} failed with'
' error: {1}'.format(
self.module.params['onefs_host'],
utils.determine_error(e)))
Expand Down Expand Up @@ -4078,7 +4102,6 @@ def perform_module_operation(self):
'smb_global_settings', 'ntp_servers', 'email_settings', 'cluster_identity', 'cluster_owner',
'snmp_settings', 'server_certificate', 'event_group', 'smartquota', 'filesystem',
'writable_snapshots', 'users']

for key in subset:
if key not in subset_list:
result[key] = subset_mapping[key]()
Expand Down
10 changes: 6 additions & 4 deletions tests/unit/plugins/module_utils/mock_info_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,9 +626,10 @@ def get_smb_files_response(response_type):
"user": "admin"
}
]
elif response_type == 'cluster_ip_exception':
return "Getting list of cluster external ips for PowerScale:"
else:
return "Getting list of smb open files for PowerScale: %s failed with error: SDK Error message" % (
MockGatherfactsApi.GATHERFACTS_COMMON_ARGS['onefs_host'])
return "Getting list of smb open files for PowerScale:"

@staticmethod
def get_user_mapping_rules_response(response_type):
Expand Down Expand Up @@ -1770,8 +1771,9 @@ def get_gather_facts_api_response(gather_subset):
return subset_error_dict.get(gather_subset)

@staticmethod
def get_gather_facts_error_response(gather_subset):
param = "error"
def get_gather_facts_error_response(gather_subset, param=None):
if not param:
param = "error"
path = "ifs"
subset_error_dict = {
"nfs_global_settings": MockGatherfactsApi.get_nfsglobal_settings(param),
Expand Down
64 changes: 62 additions & 2 deletions tests/unit/plugins/modules/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def gatherfacts_module_mock(self, mocker):
gatherfacts_module_mock.snapshot_api = MagicMock()
gatherfacts_module_mock.smartquota_api = MagicMock()
utils.ISI_SDK_VERSION_9 = MagicMock(return_value=True)
gatherfacts_module_mock.api_client = MagicMock()
gatherfacts_module_mock.isi_sdk = MagicMock()
return gatherfacts_module_mock

def test_empty_gather_subset(self, gatherfacts_module_mock):
Expand Down Expand Up @@ -365,7 +367,6 @@ def test_get_facts_auth_api_exception(self, gatherfacts_module_mock, gather_subs
gather_subset) == gatherfacts_module_mock.module.fail_json.call_args[1]['msg']

@pytest.mark.parametrize("input_params", [
{"gather_subset": "smb_files", "return_key": "SmbOpenFiles"},
{"gather_subset": "nfs_aliases", "return_key": "NfsAliases"},
{"gather_subset": "smb_global_settings", "return_key": "SmbGlobalSettings"},
{"gather_subset": "nfs_global_settings", "return_key": "NfsGlobalSettings"},
Expand Down Expand Up @@ -395,11 +396,36 @@ def test_get_facts_protocols_api_module(self, gatherfacts_module_mock, input_par
assert MockGatherfactsApi.get_gather_facts_module_response(
gather_subset) == gatherfacts_module_mock.module.exit_json.call_args[1][return_key]

@pytest.mark.parametrize("input_params", [
{"gather_subset": "smb_files", "return_key": "SmbOpenFiles"},
{"gather_subset": "smb_files", "return_key": "SmbOpenFiles", "filters":
[{"filter_key": "id", "filter_operator": "equal", "filter_value": 1880}]}
]
)
def test_get_facts_smb_files_module(self, gatherfacts_module_mock, input_params):
"""Test the get_facts that uses the protocols api endpoint to get the module response"""
return_key = input_params.get('return_key')
gather_subset = input_params.get('gather_subset')
smb_files_list = MockGatherfactsApi.get_gather_facts_api_response(
gather_subset)
self.get_module_args.update({
'gather_subset': [gather_subset],
'zone': "System",
"filters": input_params.get('filters')
})
gatherfacts_module_mock.cluster_api.get_cluster_external_ips = MagicMock(return_value=['192.168.0.1'])
gatherfacts_module_mock.module.params = self.get_module_args
gatherfacts_module_mock.api_client.to_dict.onefs_host = MagicMock(return_value='192.168.0.1')
gatherfacts_module_mock.protocol_api.get_smb_openfiles.to_dict = MagicMock(
return_value=MockSDKResponse(MockGatherfactsApi.get_gather_facts_api_response(
gather_subset)))
gatherfacts_module_mock.perform_module_operation()
gatherfacts_module_mock.protocol_api.get_smb_openfiles.assert_called()

@pytest.mark.parametrize("gather_subset", [
"nfs_global_settings",
"smb_global_settings",
"nfs_zone_settings",
"smb_files",
"nfs_aliases",
"smb_shares",
"nfs_exports",
Expand All @@ -421,6 +447,40 @@ def test_get_facts_protocols_api_exception(self, gatherfacts_module_mock, gather
assert MockGatherfactsApi.get_gather_facts_error_response(
gather_subset) == gatherfacts_module_mock.module.fail_json.call_args[1]['msg']

def test_get_facts_smb_files_cluseter_ip_exception(self, gatherfacts_module_mock):
"""Test the get_facts that uses the protocols api endpoint to get the exception"""
gather_subset = "smb_files"
self.get_module_args.update({
'gather_subset': [gather_subset],
'zone': "System",
})
gatherfacts_module_mock.module.params = self.get_module_args
gatherfacts_module_mock.cluster_api.get_cluster_external_ips = MagicMock(
side_effect=MockApiException)
gatherfacts_module_mock.perform_module_operation()
assert MockGatherfactsApi.get_gather_facts_error_response(gather_subset, "cluster_ip_exception") in\
gatherfacts_module_mock.module.fail_json.call_args[1]['msg']

def test_get_facts_smb_files_exception(self, gatherfacts_module_mock):
"""Test the get_facts that uses the protocols api endpoint to get the exception"""
gather_subset = "smb_files"
return_key = "SmbOpenFiles"
smb_files_list = MockGatherfactsApi.get_gather_facts_api_response(
gather_subset)
self.get_module_args.update({
'gather_subset': [gather_subset],
'zone': "System",
})
gatherfacts_module_mock.cluster_api.get_cluster_external_ips = MagicMock(return_value=['192.168.0.1'])
gatherfacts_module_mock.module.params = self.get_module_args
gatherfacts_module_mock.api_client.to_dict.onefs_host = MagicMock(return_value='192.168.0.1')
gatherfacts_module_mock.isi_sdk.ProtocolsApi = MagicMock(return_value=gatherfacts_module_mock.protocol_api)
gatherfacts_module_mock.protocol_api.get_smb_openfiles = MagicMock(
side_effect=MockApiException)
gatherfacts_module_mock.get_smb_file_for_each_cluster(gatherfacts_module_mock.api_client)
assert MockGatherfactsApi.get_gather_facts_error_response(gather_subset) in\
gatherfacts_module_mock.module.fail_json.call_args[1]['msg']

@pytest.mark.parametrize("input_params", [
{"gather_subset": "support_assist_settings", "return_key": "support_assist_settings"}
]
Expand Down
Loading