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

Changes for getting auth user list #113

Merged
merged 16 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
26 changes: 26 additions & 0 deletions plugins/module_utils/storage/dell/shared_library/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,29 @@ def get_auth_roles(self, zone):
f'due to error {error_msg}.'
LOG.error(error_message)
self.module.fail_json(msg=error_message)

def get_auth_users(self, zone):
"""
Get list of the auth user for a given access zone
"""
LOG.info("Getting list of auth users.")
try:
user_list = []
user_list_details = (self.auth_api.list_auth_users(zone=zone)).to_dict()
user_list.extend(user_list_details['users'])
resume = user_list_details.get('resume')
while resume:
user_list_details = (self.auth_api.list_auth_users(resume=resume)).to_dict()
user_list.extend(user_list_details['users'])
resume = user_list_details['resume']
msg = f"Got user list from PowerScale cluster {self.module.params['onefs_host']}"
LOG.info(msg)
return user_list
except Exception as e:
error_msg = (
'Get Users List for PowerScale cluster: {0} and access zone: {1} '
'failed with error: {2}' .format(
self.module.params['onefs_host'], zone,
utils.determine_error(e)))
LOG.error(error_msg)
self.module.fail_json(msg=error_msg)
21 changes: 1 addition & 20 deletions plugins/modules/info.py
meenakshidembi691 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -3341,25 +3341,6 @@ def get_providers_list(self, access_zone):
LOG.error(error_msg)
self.module.fail_json(msg=error_msg)

def get_users_list(self, access_zone):
"""Get the list of users for an access zone of a given PowerScale
Storage"""
try:
users_list = (self.auth_api.list_auth_users(zone=access_zone))\
.to_dict()
LOG.info('Got Users from PowerScale cluster %s',
self.module.params['onefs_host'])
return users_list
except Exception as e:
error_msg = (
'Get Users List for PowerScale cluster: {0} and access zone: {1} '
'failed with error: {2}' .format(
self.module.params['onefs_host'],
access_zone,
utils.determine_error(e)))
LOG.error(error_msg)
self.module.fail_json(msg=error_msg)

def get_groups_list(self, access_zone):
"""Get the list of groups for an access zone of a given PowerScale
Storage"""
Expand Down Expand Up @@ -3995,7 +3976,7 @@ def perform_module_operation(self):
'access_zones': self.get_access_zones_list,
'nodes': self.get_nodes_list,
'providers': lambda: self.get_providers_list(access_zone),
'users': lambda: self.get_users_list(access_zone),
'users': lambda: Auth(self.auth_api, self.module).get_auth_users(access_zone),
'groups': lambda: self.get_groups_list(access_zone),
'smb_shares': lambda: self.get_smb_shares_list(access_zone),
'clients': self.get_clients_list,
Expand Down
41 changes: 26 additions & 15 deletions tests/unit/plugins/module_utils/mock_info_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,16 +989,27 @@ def get_providers_response(response_type):
return resp

@staticmethod
def get_users_response(response_type):
resp = [{
"name": "testuser",
}, {
"name": "testuser1",
}]
if response_type == "error":
return "Get Users List for PowerScale cluster: **.***.**.*** and access zone: System failed with error: SDK Error message"
def get_auth_users(response_type):
if response_type == "api":
meenakshidembi691 marked this conversation as resolved.
Show resolved Hide resolved
return {
"users": [
{
"id": "id1",
"id_name": "id_name1",
"name": "name1"
}
]
}
elif response_type == "module":
return [
{
"id": "id1",
"id_name": "id_name1",
"name": "name1"
}
]
else:
return resp
return "Get Users List for PowerScale cluster: **.***.**.*** and access zone: System failed with error: SDK Error message"

@staticmethod
def get_groups_response(response_type):
Expand Down Expand Up @@ -1393,7 +1404,7 @@ def get_event_maintenance(response_type):
"start": 1719831994
}
],
"maintenance": "true"
"maintenance": "True"
}
else:
return "Fetching maintenance events failed with error: SDK Error message"
Expand Down Expand Up @@ -1422,7 +1433,7 @@ def get_event_channels(response_type):
"channels": [
{
"allowed_nodes": [],
"enabled": "true",
"enabled": "True",
"excluded_nodes": [],
"id": 2,
"name": MockGatherfactsApi.NAME,
Expand All @@ -1441,7 +1452,7 @@ def get_event_channels(response_type):
"subject": ""
},
"rules": ["Heatrbeat"],
"system": "true",
"system": "True",
"type": "heartbreak"
}
],
Expand Down Expand Up @@ -1691,7 +1702,7 @@ def get_gather_facts_module_response(gather_subset):
"network_pools": MockGatherfactsApi.get_network_pools_response(param),
"network_groupnets": MockGatherfactsApi.get_network_groupnets_response(param),
"providers": MockGatherfactsApi.get_providers_response(param),
"users": MockGatherfactsApi.get_users_response(param),
"users": MockGatherfactsApi.get_auth_users(param),
"groups": MockGatherfactsApi.get_groups_response(param),
"smb_shares": MockGatherfactsApi.get_smb_shares_response(param),
"nfs_exports": MockGatherfactsApi.get_nfs_exports_response(param),
Expand Down Expand Up @@ -1738,7 +1749,7 @@ def get_gather_facts_api_response(gather_subset):
"network_pools": MockGatherfactsApi.get_network_pools_response(param),
"network_groupnets": MockGatherfactsApi.get_network_groupnets_response(param),
"providers": MockGatherfactsApi.get_providers_response(param),
"users": MockGatherfactsApi.get_users_response(param),
"users": MockGatherfactsApi.get_auth_users(param),
"groups": MockGatherfactsApi.get_groups_response(param),
"smb_shares": MockGatherfactsApi.get_smb_shares_response(param),
"nfs_exports": MockGatherfactsApi.get_nfs_exports_response(param),
Expand Down Expand Up @@ -1786,7 +1797,7 @@ def get_gather_facts_error_response(gather_subset):
"network_pools": MockGatherfactsApi.get_network_pools_response(param),
"network_groupnets": MockGatherfactsApi.get_network_groupnets_response(param),
"providers": MockGatherfactsApi.get_providers_response(param),
"users": MockGatherfactsApi.get_users_response(param),
"users": MockGatherfactsApi.get_auth_users(param),
"groups": MockGatherfactsApi.get_groups_response(param),
"smb_shares": MockGatherfactsApi.get_smb_shares_response(param),
"nfs_exports": MockGatherfactsApi.get_nfs_exports_response(param),
Expand Down
1 change: 0 additions & 1 deletion tests/unit/plugins/modules/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,6 @@ def test_get_facts_supportassist_exception(self, gatherfacts_module_mock, gather
gatherfacts_module_mock.major = 8
gatherfacts_module_mock.minor = 4
resp = gatherfacts_module_mock.get_support_assist_settings()
print(f"response is: {resp}")
assert "support_assist_settings is supported for One FS version 9.5.0 and above" in gatherfacts_module_mock.module.fail_json.call_args[1]['msg']

@pytest.mark.parametrize("input_params", [
Expand Down
Loading