From e9f93a9d54c19f3b28d659b99ddbeb09bef1ce92 Mon Sep 17 00:00:00 2001 From: Kritika-Bhateja-03 Date: Fri, 2 Aug 2024 06:12:41 +0000 Subject: [PATCH 01/11] Added writable snapshot in info module --- docs/modules/info.rst | 77 +++++++++++++- .../dell/shared_library/writable_snapshot.py | 58 ++++++++++ plugins/modules/info.py | 100 ++++++++++++++++-- .../plugins/module_utils/mock_info_api.py | 47 +++++++- tests/unit/plugins/modules/test_info.py | 40 +++++++ 5 files changed, 311 insertions(+), 11 deletions(-) create mode 100644 plugins/module_utils/storage/dell/shared_library/writable_snapshot.py diff --git a/docs/modules/info.rst b/docs/modules/info.rst index 733fed68..de2804bb 100644 --- a/docs/modules/info.rst +++ b/docs/modules/info.rst @@ -192,6 +192,8 @@ Parameters Event groups - \ :literal:`event\_group`\ . + Writable snapshots - \ :literal:`writable\_snapshot`\ . + filters (False, list, None) List of filters to support filtered output for storage entities. @@ -219,6 +221,32 @@ Parameters Applicable to \ :literal:`alert\_rules`\ , \ :literal:`event\_group`\ , \ :literal:`event\_channels`\ and \ :literal:`filesystem`\ . + If \ :literal:`writable\_snapshot`\ is passed as \ :emphasis:`gather\_subset`\ , if \ :emphasis:`wspath`\ is given, all other query parameters inside \ :emphasis:`writable\_snapshot`\ will be ignored. + + + writable_snapshot (optional, dict, None) + The query parameters for \ :emphasis:`gather\_subset`\ 'writable\_snapshot'. + + Supports the following query parameters. + + + dir (optional, str, None) + The direction of the sort. + + + limit (optional, int, None) + The limit. + + + sort (optional, str, None) + The field that is used for sorting. + + + state (optional, str, None) + To list the writable snapshot matching this state. + + + onefs_host (True, str, None) IP address or FQDN of the PowerScale cluster. @@ -254,7 +282,7 @@ Notes - The parameters \ :emphasis:`access\_zone`\ and \ :emphasis:`include\_all\_access\_zones`\ are mutually exclusive. - Listing of SyncIQ target cluster certificates is not supported by isi\_sdk\_8\_1\_1 version. - The \ :emphasis:`check\_mode`\ is supported. - - Filter functionality is supported only for the following 'gather\_subset'- 'nfs', 'smartquota', 'filesystem'. + - Filter functionality is supported only for the following 'gather\_subset'- 'nfs', 'smartquota', 'filesystem' 'writable\_snapshot'. - The modules present in this collection named as 'dellemc.powerscale' are built to support the Dell PowerScale storage platform. @@ -782,6 +810,53 @@ Examples filter_operator: "equal" filter_value: "xxx" + - name: Get all writable snapshots from PowerScale cluster + dellemc.powerscale.info: + onefs_host: "{{ onefs_host }}" + verify_ssl: "{{ verify_ssl }}" + api_user: "{{ api_user }}" + api_password: "{{ api_password }}" + gather_subset: + - writable_snapshot + + - name: To get the specific writable snapshot. + dellemc.powerscale.info: + onefs_host: "{{ onefs_host }}" + verify_ssl: "{{ verify_ssl }}" + api_user: "{{ api_user }}" + api_password: "{{ api_password }}" + gather_subset: + - writable_snapshot + query_parameters: + writable_snapshot: + wspath: "/ifs/test_mkdir" + + - name: To filter the writable snapshot in ascending order. + dellemc.powerscale.info: + onefs_host: "{{ onefs_host }}" + verify_ssl: "{{ verify_ssl }}" + api_user: "{{ api_user }}" + api_password: "{{ api_password }}" + gather_subset: + - writable_snapshot + query_parameters: + writable_snapshot: + dir: ASC + limit: 1 + + - name: To sort the writable snapshot in ascending order. + dellemc.powerscale.info: + onefs_host: "{{ onefs_host }}" + verify_ssl: "{{ verify_ssl }}" + api_user: "{{ api_user }}" + api_password: "{{ api_password }}" + gather_subset: + - writable_snapshot + query_parameters: + writable_snapshot: + sort: src_snap + state: active + Return Values diff --git a/plugins/module_utils/storage/dell/shared_library/writable_snapshot.py b/plugins/module_utils/storage/dell/shared_library/writable_snapshot.py new file mode 100644 index 00000000..acf026af --- /dev/null +++ b/plugins/module_utils/storage/dell/shared_library/writable_snapshot.py @@ -0,0 +1,58 @@ +# Copyright: (c) 2024, Dell Technologies + +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import (absolute_import, division, print_function) + +__metaclass__ = type + +from ansible_collections.dellemc.powerscale.plugins.module_utils.storage.dell \ + import utils + +LOG = utils.get_logger('snapshot') + + +class WritableSnapshot: + + '''Class with shared snapshot operations''' + + def __init__(self, snapshot_api, module): + """ + Initialize the snapshot class + :param snapshot_api: The snapshot sdk instance + :param module: Ansible module object + """ + self.snapshot_api = snapshot_api + self.module = module + + def list_writable_snapshots(self): + """ + List the writable snapshots. + + :param filter: The filter for the list. + :type filter: dict + :returns: The list of snapshots. + :rtype: list + """ + try: + query_params = self.module.params.get('query_parameters') + writable_snapshot_query_params = query_params.get('writable_snapshot', []) if query_params else [] + filter_params = {} + if writable_snapshot_query_params: + if "wspath" in writable_snapshot_query_params: + return self.snapshot_api.get_snapshot_writable_wspath( + snapshot_writable_wspath=writable_snapshot_query_params["wspath"] + ).to_dict() + else: + filter_params = dict(writable_snapshot_query_params.items()) + writable_snapshots = [] + snapshot_list = \ + self.snapshot_api.list_snapshot_writable(**filter_params).to_dict() + writable_snapshots.extend(snapshot_list['writable']) + return writable_snapshots + except Exception as e: + error_msg = utils.determine_error(error_obj=e) + error_message = 'Failed to get writeable snapshots ' \ + 'due to error {0}'.format((str(error_msg))) + LOG.error(error_message) + self.module.fail_json(msg=error_message) diff --git a/plugins/modules/info.py b/plugins/modules/info.py index b03731eb..5ab49c6b 100644 --- a/plugins/modules/info.py +++ b/plugins/modules/info.py @@ -142,6 +142,7 @@ - Alert channels - C(alert_channels). - Alert categories - C(alert_categories). - Event groups - C(event_group). + - Writable snapshots - C(writable_snapshot). required: true choices: [attributes, access_zones, nodes, providers, users, groups, smb_shares, nfs_exports, nfs_aliases, clients, synciq_reports, synciq_target_reports, @@ -151,7 +152,7 @@ nfs_zone_settings, nfs_default_settings, nfs_global_settings, synciq_global_settings, s3_buckets, smb_global_settings, ntp_servers, email_settings, cluster_identity, cluster_owner, snmp_settings, server_certificate, roles, support_assist_settings, smartquota, filesystem, alert_settings, - alert_rules, alert_channels, alert_categories, event_group] + alert_rules, alert_channels, alert_categories, event_group, writable_snapshot] type: list elements: str filters: @@ -184,13 +185,38 @@ description: - Contains dictionary of query parameters for specific I(gather_subset). - Applicable to C(alert_rules), C(event_group), C(event_channels) and C(filesystem). + - If C(writable_snapshot) is passed as I(gather_subset), if I(wspath) is given, + all other query parameters inside I(writable_snapshot) will be ignored. + suboptions: + writable_snapshot: + description: + - The query parameters for I(gather_subset) 'writable_snapshot'. + - Supports the following query parameters. + type: dict + suboptions: + dir: + description: The direction of the sort. + type: str + choices: [ASC, DESC] + limit: + description: The limit. + type: int + sort: + description: The field that is used for sorting. + type: str + choices: [created, src_path, phys_size, state, src_snap] + state: + description: To list the writable snapshot matching this state. + type: str + choices: [all, active, deleting] type: dict version_added: '3.2.0' notes: - The parameters I(access_zone) and I(include_all_access_zones) are mutually exclusive. - Listing of SyncIQ target cluster certificates is not supported by isi_sdk_8_1_1 version. - The I(check_mode) is supported. -- Filter functionality is supported only for the following 'gather_subset'- 'nfs', 'smartquota', 'filesystem'. +- Filter functionality is supported only for the following 'gather_subset'- 'nfs', 'smartquota', 'filesystem' + 'writable_snapshot'. ''' EXAMPLES = r''' @@ -709,6 +735,53 @@ - filter_key: "name" filter_operator: "equal" filter_value: "xxx" + +- name: Get all writable snapshots from PowerScale cluster + dellemc.powerscale.info: + onefs_host: "{{ onefs_host }}" + verify_ssl: "{{ verify_ssl }}" + api_user: "{{ api_user }}" + api_password: "{{ api_password }}" + gather_subset: + - writable_snapshot + +- name: To get the specific writable snapshot. + dellemc.powerscale.info: + onefs_host: "{{ onefs_host }}" + verify_ssl: "{{ verify_ssl }}" + api_user: "{{ api_user }}" + api_password: "{{ api_password }}" + gather_subset: + - writable_snapshot + query_parameters: + writable_snapshot: + wspath: "/ifs/test_mkdir" + +- name: To filter the writable snapshot in ascending order. + dellemc.powerscale.info: + onefs_host: "{{ onefs_host }}" + verify_ssl: "{{ verify_ssl }}" + api_user: "{{ api_user }}" + api_password: "{{ api_password }}" + gather_subset: + - writable_snapshot + query_parameters: + writable_snapshot: + dir: ASC + limit: 1 + +- name: To sort the writable snapshot in ascending order. + dellemc.powerscale.info: + onefs_host: "{{ onefs_host }}" + verify_ssl: "{{ verify_ssl }}" + api_user: "{{ api_user }}" + api_password: "{{ api_password }}" + gather_subset: + - writable_snapshot + query_parameters: + writable_snapshot: + sort: src_snap + state: active ''' RETURN = r''' @@ -3158,6 +3231,8 @@ import Quota from ansible_collections.dellemc.powerscale.plugins.module_utils.storage.dell.shared_library.snapshot \ import Snapshot +from ansible_collections.dellemc.powerscale.plugins.module_utils.storage.dell.shared_library.writable_snapshot \ + import WritableSnapshot LOG = utils.get_logger('info') @@ -3753,6 +3828,16 @@ def get_smartquota_list(self): LOG.error(error_msg) self.module.fail_json(msg=error_msg) + def get_writable_snapshots(self): + writable_snapshots = WritableSnapshot(self.snapshot_api, self.module).list_writable_snapshots() + filtered_writable_snapshots = [] + filters = self.module.params.get('filters') + filters_dict = self.get_filters(filters) + if filters_dict: + filtered_writable_snapshots = filter_dict_list(writable_snapshots, filters_dict) + return filtered_writable_snapshots + return writable_snapshots + def get_metadata(self, effective_path): return Namespace(self.namespace_api, self.module).get_filesystem(effective_path) @@ -3974,7 +4059,8 @@ def perform_module_operation(self): 'alert_channels': lambda: Events(self.event_api, self.module).get_event_channels(), 'event_group': lambda: Events(self.event_api, self.module).get_event_groups(), 'smartquota': self.get_smartquota_list, - 'filesystem': lambda: self.get_filesystem_list(path, query_params) + 'filesystem': lambda: self.get_filesystem_list(path, query_params), + 'writable_snapshot': self.get_writable_snapshots } key_mapping = { @@ -4017,7 +4103,8 @@ def perform_module_operation(self): 'synciq_target_cluster_certificates': 'SynciqTargetClusterCertificate', 'event_group': 'event_groups', 'smartquota': 'smart_quota', - 'filesystem': 'file_system' + 'filesystem': 'file_system', + 'writable_snapshot': 'writable_snapshots' } # Map the subset to the appropriate Key @@ -4028,7 +4115,8 @@ def perform_module_operation(self): 'storagepool_tiers', 'smb_files', 'user_mapping_rules', 'ldap', 'nfs_zone_settings', 'nfs_default_settings', 'nfs_global_settings', 'synciq_global_settings', 's3_buckets', 'smb_global_settings', 'ntp_servers', 'email_settings', 'cluster_identity', 'cluster_owner', - 'snmp_settings', 'server_certificate', 'event_group', 'smartquota', 'filesystem'] + 'snmp_settings', 'server_certificate', 'event_group', 'smartquota', 'filesystem', + 'writable_snapshot'] for key in subset: if key not in subset_list: result[key] = subset_mapping[key]() @@ -4080,7 +4168,7 @@ def get_info_parameters(): 'snmp_settings', 'server_certificate', 'roles', 'support_assist_settings', 'alert_settings', 'alert_rules', 'alert_channels', 'alert_categories', 'event_group', - 'filesystem', 'smartquota']), + 'filesystem', 'smartquota', 'writable_snapshot']), filters=dict(type='list', required=False, elements='dict', diff --git a/tests/unit/plugins/module_utils/mock_info_api.py b/tests/unit/plugins/module_utils/mock_info_api.py index 7e99bff0..ed4e9dda 100644 --- a/tests/unit/plugins/module_utils/mock_info_api.py +++ b/tests/unit/plugins/module_utils/mock_info_api.py @@ -1636,6 +1636,41 @@ def get_filesystem_list(response_type): else: return "Failed to get details of Filesystem" + @staticmethod + def get_writable_snapshot_list(response_type): + if response_type == 'api': + return { + "writable": [ + { + "created": 1722504407, + "dst_path": "/ifs/test2", + "id": 66258688, + "log_size": 0, + "phys_size": 2048, + "src_id": 230, + "src_path": "/ifs/tfacc_test_dirNew", + "src_snap": "ScheduleName_duration_2024-07-26_11:00", + "state": "active" + } + ] + } + elif response_type == "module": + return [ + { + "created": 1722504407, + "dst_path": "/ifs/test2", + "id": 66258688, + "log_size": 0, + "phys_size": 2048, + "src_id": 230, + "src_path": "/ifs/tfacc_test_dirNew", + "src_snap": "ScheduleName_duration_2024-07-26_11:00", + "state": "active" + } + ] + else: + return "Failed to get writeable snapshots" + @staticmethod def get_gather_facts_module_response(gather_subset): param = "module" @@ -1679,7 +1714,8 @@ def get_gather_facts_module_response(gather_subset): "alert_channels": MockGatherfactsApi.get_event_channels(param), "alert_settings": MockGatherfactsApi.get_event_maintenance(param), "filesystem": MockGatherfactsApi.get_filesystem_list(param), - "smartquota": MockGatherfactsApi.get_smartquota_list(param) + "smartquota": MockGatherfactsApi.get_smartquota_list(param), + "writable_snapshot": MockGatherfactsApi.get_writable_snapshot_list(param) } return subset_error_dict.get(gather_subset) @@ -1725,7 +1761,8 @@ def get_gather_facts_api_response(gather_subset): "alert_channels": MockGatherfactsApi.get_event_channels(param), "alert_settings": MockGatherfactsApi.get_event_maintenance(param), "filesystem": MockGatherfactsApi.get_filesystem_list(param), - "smartquota": MockGatherfactsApi.get_smartquota_list(param) + "smartquota": MockGatherfactsApi.get_smartquota_list(param), + "writable_snapshot": MockGatherfactsApi.get_writable_snapshot_list(param) } return subset_error_dict.get(gather_subset) @@ -1773,7 +1810,8 @@ def get_gather_facts_error_response(gather_subset): "alert_channels": MockGatherfactsApi.get_event_channels(param), "alert_settings": MockGatherfactsApi.get_event_maintenance(param), "filesystem": MockGatherfactsApi.get_filesystem_list(param), - "smartquota": MockGatherfactsApi.get_smartquota_list(param) + "smartquota": MockGatherfactsApi.get_smartquota_list(param), + "writable_snapshot": MockGatherfactsApi.get_writable_snapshot_list(param) } return subset_error_dict.get(gather_subset) @@ -1825,6 +1863,7 @@ def get_gather_facts_error_method(gather_subset): "alert_channels": "list_event_channels", "alert_settings": "get_event_maintenance", "smartquota": "list_quota_quotas", - "filesystem": "get_directory_contents" + "filesystem": "get_directory_contents", + "writable_snapshot": "list_snapshot_writable", } return subset_method_dict.get(gather_subset) diff --git a/tests/unit/plugins/modules/test_info.py b/tests/unit/plugins/modules/test_info.py index d11b24f9..141a3257 100644 --- a/tests/unit/plugins/modules/test_info.py +++ b/tests/unit/plugins/modules/test_info.py @@ -723,3 +723,43 @@ def test_get_facts_filesystem_api_exception(self, gatherfacts_module_mock, gathe gatherfacts_module_mock.perform_module_operation() 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": "writable_snapshot", "return_key": "writable_snapshots"} + ] + ) + def test_get_facts_writable_snapshot_api_module(self, gatherfacts_module_mock, input_params): + """Test the get_facts that uses the writable snapshot 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': ['writable_snapshot'], + 'zone': "System", + }) + gatherfacts_module_mock.module.params = self.get_module_args + + with patch.object(gatherfacts_module_mock.snapshot_api, MockGatherfactsApi.get_gather_facts_error_method(gather_subset)) as mock_method: + mock_method.return_value = MockSDKResponse(api_response) + gatherfacts_module_mock.perform_module_operation() + assert MockGatherfactsApi.get_gather_facts_module_response( + gather_subset) == gatherfacts_module_mock.module.exit_json.call_args[1][return_key] + + @pytest.mark.parametrize("gather_subset", [ + "writable_snapshot" + ] + ) + def test_get_facts_writable_snapshot_api_exception(self, gatherfacts_module_mock, gather_subset): + """Test the get_facts that uses the writable snapshot api endpoint to get the exception""" + self.get_module_args.update({ + 'gather_subset': ['writable_snapshot'], + 'zone': "System", + }) + gatherfacts_module_mock.module.params = self.get_module_args + with patch.object(gatherfacts_module_mock.snapshot_api, MockGatherfactsApi.get_gather_facts_error_method(gather_subset)) as mock_method: + mock_method.side_effect = MagicMock(side_effect=MockApiException) + gatherfacts_module_mock.perform_module_operation() + assert MockGatherfactsApi.get_gather_facts_error_response( + gather_subset) in gatherfacts_module_mock.module.fail_json.call_args[1]['msg'] From d148b0d78977b82ef7d4cde39ed91e8986cef105 Mon Sep 17 00:00:00 2001 From: Kritika-Bhateja-03 Date: Fri, 2 Aug 2024 06:21:38 +0000 Subject: [PATCH 02/11] Added examples in playbook --- playbooks/modules/info.yml | 47 ++++++++++++++++++++++++++++++++++++++ plugins/modules/info.py | 6 ++--- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/playbooks/modules/info.yml b/playbooks/modules/info.yml index 39011c13..fc8e9207 100644 --- a/playbooks/modules/info.yml +++ b/playbooks/modules/info.yml @@ -395,3 +395,50 @@ - filter_key: "name" filter_operator: "equal" filter_value: "xxx" + + - name: Get all writable snapshots from PowerScale cluster + dellemc.powerscale.info: + onefs_host: "{{ onefs_host }}" + verify_ssl: "{{ verify_ssl }}" + api_user: "{{ api_user }}" + api_password: "{{ api_password }}" + gather_subset: + - writable_snapshot + + - name: To get the specific writable snapshot. + dellemc.powerscale.info: + onefs_host: "{{ onefs_host }}" + verify_ssl: "{{ verify_ssl }}" + api_user: "{{ api_user }}" + api_password: "{{ api_password }}" + gather_subset: + - writable_snapshot + query_parameters: + writable_snapshot: + wspath: "/ifs/test_mkdir" + + - name: To filter the writable snapshot in ascending order. + dellemc.powerscale.info: + onefs_host: "{{ onefs_host }}" + verify_ssl: "{{ verify_ssl }}" + api_user: "{{ api_user }}" + api_password: "{{ api_password }}" + gather_subset: + - writable_snapshot + query_parameters: + writable_snapshot: + dir: ASC + limit: 1 + + - name: To sort the writable snapshot in ascending order. + dellemc.powerscale.info: + onefs_host: "{{ onefs_host }}" + verify_ssl: "{{ verify_ssl }}" + api_user: "{{ api_user }}" + api_password: "{{ api_password }}" + gather_subset: + - writable_snapshot + query_parameters: + writable_snapshot: + sort: src_snap + state: active diff --git a/plugins/modules/info.py b/plugins/modules/info.py index 5ab49c6b..1d05b055 100644 --- a/plugins/modules/info.py +++ b/plugins/modules/info.py @@ -752,7 +752,7 @@ api_user: "{{ api_user }}" api_password: "{{ api_password }}" gather_subset: - - writable_snapshot + - writable_snapshot query_parameters: writable_snapshot: wspath: "/ifs/test_mkdir" @@ -764,7 +764,7 @@ api_user: "{{ api_user }}" api_password: "{{ api_password }}" gather_subset: - - writable_snapshot + - writable_snapshot query_parameters: writable_snapshot: dir: ASC @@ -777,7 +777,7 @@ api_user: "{{ api_user }}" api_password: "{{ api_password }}" gather_subset: - - writable_snapshot + - writable_snapshot query_parameters: writable_snapshot: sort: src_snap From 325ef15f4da754b4c3a1974cef83adc3c54d51d8 Mon Sep 17 00:00:00 2001 From: Kritika-Bhateja-03 Date: Mon, 5 Aug 2024 11:36:52 +0000 Subject: [PATCH 03/11] Updated module and playbook --- playbooks/modules/info.yml | 6 +- .../storage/dell/shared_library/snapshot.py | 32 ++++++++++ .../dell/shared_library/writable_snapshot.py | 58 ------------------- plugins/modules/info.py | 15 ++--- tests/unit/plugins/modules/test_info.py | 17 ++++++ 5 files changed, 57 insertions(+), 71 deletions(-) delete mode 100644 plugins/module_utils/storage/dell/shared_library/writable_snapshot.py diff --git a/playbooks/modules/info.yml b/playbooks/modules/info.yml index fc8e9207..f2667fd2 100644 --- a/playbooks/modules/info.yml +++ b/playbooks/modules/info.yml @@ -405,7 +405,7 @@ gather_subset: - writable_snapshot - - name: To get the specific writable snapshot. + - name: To get the specific writable snapshot dellemc.powerscale.info: onefs_host: "{{ onefs_host }}" verify_ssl: "{{ verify_ssl }}" @@ -417,7 +417,7 @@ writable_snapshot: wspath: "/ifs/test_mkdir" - - name: To filter the writable snapshot in ascending order. + - name: To filter the writable snapshot in ascending order dellemc.powerscale.info: onefs_host: "{{ onefs_host }}" verify_ssl: "{{ verify_ssl }}" @@ -430,7 +430,7 @@ dir: ASC limit: 1 - - name: To sort the writable snapshot in ascending order. + - name: To filter the writable snapshot using sort dellemc.powerscale.info: onefs_host: "{{ onefs_host }}" verify_ssl: "{{ verify_ssl }}" diff --git a/plugins/module_utils/storage/dell/shared_library/snapshot.py b/plugins/module_utils/storage/dell/shared_library/snapshot.py index 38198525..9967efd3 100644 --- a/plugins/module_utils/storage/dell/shared_library/snapshot.py +++ b/plugins/module_utils/storage/dell/shared_library/snapshot.py @@ -50,3 +50,35 @@ def get_filesystem_snapshots(self, effective_path): 'due to error {0}'.format((str(error_msg))) LOG.error(error_message) self.module.fail_json(msg=error_message) + + def list_writable_snapshots(self): + """ + List the writable snapshots. + + :param filter: The filter for the list. + :type filter: dict + :returns: The list of snapshots. + :rtype: list + """ + try: + query_params = self.module.params.get('query_parameters') + writable_snapshot_query_params = query_params.get('writable_snapshot', []) if query_params else [] + filter_params = {} + if writable_snapshot_query_params: + if "wspath" in writable_snapshot_query_params: + return self.snapshot_api.get_snapshot_writable_wspath( + snapshot_writable_wspath=writable_snapshot_query_params["wspath"] + ).to_dict().get("writable") + else: + filter_params = dict(writable_snapshot_query_params.items()) + writable_snapshots = [] + snapshot_list = \ + self.snapshot_api.list_snapshot_writable(**filter_params).to_dict() + writable_snapshots.extend(snapshot_list['writable']) + return writable_snapshots + except Exception as e: + error_msg = utils.determine_error(error_obj=e) + error_message = 'Failed to get writeable snapshots ' \ + 'due to error {0}'.format((str(error_msg))) + LOG.error(error_message) + self.module.fail_json(msg=error_message) diff --git a/plugins/module_utils/storage/dell/shared_library/writable_snapshot.py b/plugins/module_utils/storage/dell/shared_library/writable_snapshot.py deleted file mode 100644 index acf026af..00000000 --- a/plugins/module_utils/storage/dell/shared_library/writable_snapshot.py +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright: (c) 2024, Dell Technologies - -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -from __future__ import (absolute_import, division, print_function) - -__metaclass__ = type - -from ansible_collections.dellemc.powerscale.plugins.module_utils.storage.dell \ - import utils - -LOG = utils.get_logger('snapshot') - - -class WritableSnapshot: - - '''Class with shared snapshot operations''' - - def __init__(self, snapshot_api, module): - """ - Initialize the snapshot class - :param snapshot_api: The snapshot sdk instance - :param module: Ansible module object - """ - self.snapshot_api = snapshot_api - self.module = module - - def list_writable_snapshots(self): - """ - List the writable snapshots. - - :param filter: The filter for the list. - :type filter: dict - :returns: The list of snapshots. - :rtype: list - """ - try: - query_params = self.module.params.get('query_parameters') - writable_snapshot_query_params = query_params.get('writable_snapshot', []) if query_params else [] - filter_params = {} - if writable_snapshot_query_params: - if "wspath" in writable_snapshot_query_params: - return self.snapshot_api.get_snapshot_writable_wspath( - snapshot_writable_wspath=writable_snapshot_query_params["wspath"] - ).to_dict() - else: - filter_params = dict(writable_snapshot_query_params.items()) - writable_snapshots = [] - snapshot_list = \ - self.snapshot_api.list_snapshot_writable(**filter_params).to_dict() - writable_snapshots.extend(snapshot_list['writable']) - return writable_snapshots - except Exception as e: - error_msg = utils.determine_error(error_obj=e) - error_message = 'Failed to get writeable snapshots ' \ - 'due to error {0}'.format((str(error_msg))) - LOG.error(error_message) - self.module.fail_json(msg=error_message) diff --git a/plugins/modules/info.py b/plugins/modules/info.py index 1d05b055..ae55097f 100644 --- a/plugins/modules/info.py +++ b/plugins/modules/info.py @@ -3231,8 +3231,7 @@ import Quota from ansible_collections.dellemc.powerscale.plugins.module_utils.storage.dell.shared_library.snapshot \ import Snapshot -from ansible_collections.dellemc.powerscale.plugins.module_utils.storage.dell.shared_library.writable_snapshot \ - import WritableSnapshot + LOG = utils.get_logger('info') @@ -3829,7 +3828,7 @@ def get_smartquota_list(self): self.module.fail_json(msg=error_msg) def get_writable_snapshots(self): - writable_snapshots = WritableSnapshot(self.snapshot_api, self.module).list_writable_snapshots() + writable_snapshots = Snapshot(self.snapshot_api, self.module).list_writable_snapshots() filtered_writable_snapshots = [] filters = self.module.params.get('filters') filters_dict = self.get_filters(filters) @@ -3925,13 +3924,9 @@ def get_filters(self, filters=None): if not filters_items: self.module.fail_json(msg='filter_key, filter_operator, filter_value are expected.') for item in filters_items: - try: - f_key = item["filter_key"] - f_val = item["filter_value"] - f_op = item["filter_operator"] - except KeyError: - error_msg = "Provide input for filter sub-options." - self.module.fail_json(msg=error_msg) + f_key = item.get("filter_key") + f_val = item.get("filter_value") + f_op = item.get("filter_operator") if f_op != 'equal': error_msg = "The filter operator is not supported -- only 'equal' is supported." self.module.fail_json(msg=error_msg) diff --git a/tests/unit/plugins/modules/test_info.py b/tests/unit/plugins/modules/test_info.py index 141a3257..d5118c1a 100644 --- a/tests/unit/plugins/modules/test_info.py +++ b/tests/unit/plugins/modules/test_info.py @@ -738,6 +738,7 @@ def test_get_facts_writable_snapshot_api_module(self, gatherfacts_module_mock, i self.get_module_args.update({ 'gather_subset': ['writable_snapshot'], 'zone': "System", + "filters": [{"filter_key": "id", "filter_operator": "equal", "filter_value": 66258688}] }) gatherfacts_module_mock.module.params = self.get_module_args @@ -763,3 +764,19 @@ def test_get_facts_writable_snapshot_api_exception(self, gatherfacts_module_mock gatherfacts_module_mock.perform_module_operation() assert MockGatherfactsApi.get_gather_facts_error_response( gather_subset) in gatherfacts_module_mock.module.fail_json.call_args[1]['msg'] + + def test_get_filters_empty_case(self, gatherfacts_module_mock): + resp = gatherfacts_module_mock.get_filters() + assert resp == {} + + def test_get_filters_failure_case1(self, gatherfacts_module_mock): + filter_dict = [{"filter_key": "id", "filter_operator": "equal"}] + gatherfacts_module_mock.get_filters(filters=filter_dict) + assert gatherfacts_module_mock.module.fail_json.call_args[1]['msg'] \ + == 'filter_key, filter_operator, filter_value are expected.' + + def test_get_filters_failure_case2(self, gatherfacts_module_mock): + filter_dict = [{"filter_key": "id", "filter_operator": "less", "filter_value": 123}] + gatherfacts_module_mock.get_filters(filters=filter_dict) + assert gatherfacts_module_mock.module.fail_json.call_args[1]['msg'] \ + == "The filter operator is not supported -- only 'equal' is supported." From 0fe9664b2c47af5e2f517e51874aea73bbdf80eb Mon Sep 17 00:00:00 2001 From: Kritika-Bhateja-03 Date: Wed, 7 Aug 2024 08:15:59 +0000 Subject: [PATCH 04/11] Minor changes --- docs/modules/info.rst | 32 +++---------------- .../storage/dell/shared_library/snapshot.py | 18 +++++++++-- plugins/modules/info.py | 29 ++++------------- 3 files changed, 26 insertions(+), 53 deletions(-) diff --git a/docs/modules/info.rst b/docs/modules/info.rst index de2804bb..173179be 100644 --- a/docs/modules/info.rst +++ b/docs/modules/info.rst @@ -219,33 +219,11 @@ Parameters query_parameters (optional, dict, None) Contains dictionary of query parameters for specific \ :emphasis:`gather\_subset`\ . - Applicable to \ :literal:`alert\_rules`\ , \ :literal:`event\_group`\ , \ :literal:`event\_channels`\ and \ :literal:`filesystem`\ . + Applicable to \ :literal:`alert\_rules`\ , \ :literal:`event\_group`\ , \ :literal:`event\_channels`\ , \ :literal:`filesystem`\ and \ :literal:`writable\_snapshot`\ . If \ :literal:`writable\_snapshot`\ is passed as \ :emphasis:`gather\_subset`\ , if \ :emphasis:`wspath`\ is given, all other query parameters inside \ :emphasis:`writable\_snapshot`\ will be ignored. - - writable_snapshot (optional, dict, None) - The query parameters for \ :emphasis:`gather\_subset`\ 'writable\_snapshot'. - - Supports the following query parameters. - - - dir (optional, str, None) - The direction of the sort. - - - limit (optional, int, None) - The limit. - - - sort (optional, str, None) - The field that is used for sorting. - - - state (optional, str, None) - To list the writable snapshot matching this state. - - + To view the list of supported query parameters for \ :literal:`writable\_snapshot`\ , refer Query Parameters section from \ https://developer.dell.com/apis/4088/versions/9.5.0/9.5.0.0_ISLANDER_OAS2.json/%20paths/~1platform~114~1snapshot~1writable/get\ onefs_host (True, str, None) @@ -826,7 +804,7 @@ Examples api_user: "{{ api_user }}" api_password: "{{ api_password }}" gather_subset: - - writable_snapshot + - writable_snapshot query_parameters: writable_snapshot: wspath: "/ifs/test_mkdir" @@ -838,7 +816,7 @@ Examples api_user: "{{ api_user }}" api_password: "{{ api_password }}" gather_subset: - - writable_snapshot + - writable_snapshot query_parameters: writable_snapshot: dir: ASC @@ -851,7 +829,7 @@ Examples api_user: "{{ api_user }}" api_password: "{{ api_password }}" gather_subset: - - writable_snapshot + - writable_snapshot query_parameters: writable_snapshot: sort: src_snap diff --git a/plugins/module_utils/storage/dell/shared_library/snapshot.py b/plugins/module_utils/storage/dell/shared_library/snapshot.py index 9967efd3..cbc2d2e4 100644 --- a/plugins/module_utils/storage/dell/shared_library/snapshot.py +++ b/plugins/module_utils/storage/dell/shared_library/snapshot.py @@ -66,9 +66,7 @@ def list_writable_snapshots(self): filter_params = {} if writable_snapshot_query_params: if "wspath" in writable_snapshot_query_params: - return self.snapshot_api.get_snapshot_writable_wspath( - snapshot_writable_wspath=writable_snapshot_query_params["wspath"] - ).to_dict().get("writable") + return self.get_particular_writable_snapshot(wspath=writable_snapshot_query_params.get("wspath")) else: filter_params = dict(writable_snapshot_query_params.items()) writable_snapshots = [] @@ -82,3 +80,17 @@ def list_writable_snapshots(self): 'due to error {0}'.format((str(error_msg))) LOG.error(error_message) self.module.fail_json(msg=error_message) + + def get_particular_writable_snapshot(self, wspath): + try: + return self.snapshot_api.get_snapshot_writable_wspath( + snapshot_writable_wspath=wspath + ).to_dict().get("writable") + except utils.ApiException as e: + return {} + except Exception as e: + error_msg = utils.determine_error(error_obj=e) + error_message = 'Failed to get writeable snapshots ' \ + 'due to error {0}'.format((str(error_msg))) + LOG.error(error_message) + self.module.fail_json(msg=error_message) diff --git a/plugins/modules/info.py b/plugins/modules/info.py index ae55097f..12dd192e 100644 --- a/plugins/modules/info.py +++ b/plugins/modules/info.py @@ -184,31 +184,14 @@ query_parameters: description: - Contains dictionary of query parameters for specific I(gather_subset). - - Applicable to C(alert_rules), C(event_group), C(event_channels) and C(filesystem). + - Applicable to C(alert_rules), C(event_group), C(event_channels), C(filesystem) + and C(writable_snapshot). - If C(writable_snapshot) is passed as I(gather_subset), if I(wspath) is given, all other query parameters inside I(writable_snapshot) will be ignored. - suboptions: - writable_snapshot: - description: - - The query parameters for I(gather_subset) 'writable_snapshot'. - - Supports the following query parameters. - type: dict - suboptions: - dir: - description: The direction of the sort. - type: str - choices: [ASC, DESC] - limit: - description: The limit. - type: int - sort: - description: The field that is used for sorting. - type: str - choices: [created, src_path, phys_size, state, src_snap] - state: - description: To list the writable snapshot matching this state. - type: str - choices: [all, active, deleting] + - To view the list of supported query parameters for C(writable_snapshot), + refer Query Parameters section from + U(https://developer.dell.com/apis/4088/versions/9.5.0/9.5.0.0_ISLANDER_OAS2.json/ + paths/~1platform~114~1snapshot~1writable/get) type: dict version_added: '3.2.0' notes: From c00d1e850268f3c08410197c068cb888fdf06ca7 Mon Sep 17 00:00:00 2001 From: Kritika-Bhateja-03 Date: Wed, 7 Aug 2024 08:33:40 +0000 Subject: [PATCH 05/11] Sanity fix of synciqtargetreports module --- plugins/modules/synciqtargetreports.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/synciqtargetreports.py b/plugins/modules/synciqtargetreports.py index afff4352..342f05f2 100644 --- a/plugins/modules/synciqtargetreports.py +++ b/plugins/modules/synciqtargetreports.py @@ -557,6 +557,7 @@ def perform_module_operation(self): include_sub_reports = self.module.params['include_sub_reports'] synciq_target_report = None synciq_target_sub_report_details = None + synciq_target_sub_report_detail = None if not id and not name: error_message = 'Please provide a valid report id or valid report name' From 17d1deb12a98c98dae9b73a12873fd51c0fc1ce4 Mon Sep 17 00:00:00 2001 From: Kritika-Bhateja-03 Date: Wed, 7 Aug 2024 09:09:31 +0000 Subject: [PATCH 06/11] undo changes of synciqtargetreports module --- plugins/modules/synciqtargetreports.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/modules/synciqtargetreports.py b/plugins/modules/synciqtargetreports.py index 342f05f2..afff4352 100644 --- a/plugins/modules/synciqtargetreports.py +++ b/plugins/modules/synciqtargetreports.py @@ -557,7 +557,6 @@ def perform_module_operation(self): include_sub_reports = self.module.params['include_sub_reports'] synciq_target_report = None synciq_target_sub_report_details = None - synciq_target_sub_report_detail = None if not id and not name: error_message = 'Please provide a valid report id or valid report name' From 56d7afa7b9646c1339be03e25a0a7f6ecc9a787b Mon Sep 17 00:00:00 2001 From: Kritika-Bhateja-03 Date: Tue, 13 Aug 2024 13:35:58 +0000 Subject: [PATCH 07/11] Minor updates --- .../module_utils/storage/dell/shared_library/snapshot.py | 6 +++--- plugins/modules/info.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/module_utils/storage/dell/shared_library/snapshot.py b/plugins/module_utils/storage/dell/shared_library/snapshot.py index cbc2d2e4..5e022b6f 100644 --- a/plugins/module_utils/storage/dell/shared_library/snapshot.py +++ b/plugins/module_utils/storage/dell/shared_library/snapshot.py @@ -66,7 +66,7 @@ def list_writable_snapshots(self): filter_params = {} if writable_snapshot_query_params: if "wspath" in writable_snapshot_query_params: - return self.get_particular_writable_snapshot(wspath=writable_snapshot_query_params.get("wspath")) + return self.get_writable_snapshot_by_wspath(wspath=writable_snapshot_query_params.get("wspath")) else: filter_params = dict(writable_snapshot_query_params.items()) writable_snapshots = [] @@ -81,7 +81,7 @@ def list_writable_snapshots(self): LOG.error(error_message) self.module.fail_json(msg=error_message) - def get_particular_writable_snapshot(self, wspath): + def get_writable_snapshot_by_wspath(self, wspath): try: return self.snapshot_api.get_snapshot_writable_wspath( snapshot_writable_wspath=wspath @@ -90,7 +90,7 @@ def get_particular_writable_snapshot(self, wspath): return {} except Exception as e: error_msg = utils.determine_error(error_obj=e) - error_message = 'Failed to get writeable snapshots ' \ + error_message = 'Failed to get writeable snapshot ' \ 'due to error {0}'.format((str(error_msg))) LOG.error(error_message) self.module.fail_json(msg=error_message) diff --git a/plugins/modules/info.py b/plugins/modules/info.py index 12dd192e..d86dee87 100644 --- a/plugins/modules/info.py +++ b/plugins/modules/info.py @@ -753,7 +753,7 @@ dir: ASC limit: 1 -- name: To sort the writable snapshot in ascending order. +- name: To filter the writable snapshot using sort. dellemc.powerscale.info: onefs_host: "{{ onefs_host }}" verify_ssl: "{{ verify_ssl }}" From a714df2d1a3dd679c6feebfcc234a60712343bd1 Mon Sep 17 00:00:00 2001 From: Kritika-Bhateja-03 Date: Tue, 13 Aug 2024 13:39:21 +0000 Subject: [PATCH 08/11] Doc changes --- docs/modules/info.rst | 3 +-- plugins/modules/info.py | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/modules/info.rst b/docs/modules/info.rst index 173179be..8d930e49 100644 --- a/docs/modules/info.rst +++ b/docs/modules/info.rst @@ -258,7 +258,6 @@ Notes .. note:: - The parameters \ :emphasis:`access\_zone`\ and \ :emphasis:`include\_all\_access\_zones`\ are mutually exclusive. - - Listing of SyncIQ target cluster certificates is not supported by isi\_sdk\_8\_1\_1 version. - The \ :emphasis:`check\_mode`\ is supported. - Filter functionality is supported only for the following 'gather\_subset'- 'nfs', 'smartquota', 'filesystem' 'writable\_snapshot'. - The modules present in this collection named as 'dellemc.powerscale' are built to support the Dell PowerScale storage platform. @@ -822,7 +821,7 @@ Examples dir: ASC limit: 1 - - name: To sort the writable snapshot in ascending order. + - name: To filter the writable snapshot using sort. dellemc.powerscale.info: onefs_host: "{{ onefs_host }}" verify_ssl: "{{ verify_ssl }}" diff --git a/plugins/modules/info.py b/plugins/modules/info.py index d86dee87..b565f043 100644 --- a/plugins/modules/info.py +++ b/plugins/modules/info.py @@ -196,7 +196,6 @@ version_added: '3.2.0' notes: - The parameters I(access_zone) and I(include_all_access_zones) are mutually exclusive. -- Listing of SyncIQ target cluster certificates is not supported by isi_sdk_8_1_1 version. - The I(check_mode) is supported. - Filter functionality is supported only for the following 'gather_subset'- 'nfs', 'smartquota', 'filesystem' 'writable_snapshot'. From d60f5f9872d84605bf7a7b291dde60284a564e28 Mon Sep 17 00:00:00 2001 From: Kritika-Bhateja-03 Date: Wed, 14 Aug 2024 05:35:58 +0000 Subject: [PATCH 09/11] Renamed writeable snapshot to writeable_snapshots --- .../storage/dell/shared_library/snapshot.py | 2 +- plugins/modules/info.py | 36 +++++++++---------- .../plugins/module_utils/mock_info_api.py | 8 ++--- tests/unit/plugins/modules/test_info.py | 8 ++--- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/plugins/module_utils/storage/dell/shared_library/snapshot.py b/plugins/module_utils/storage/dell/shared_library/snapshot.py index 5e022b6f..6e76111e 100644 --- a/plugins/module_utils/storage/dell/shared_library/snapshot.py +++ b/plugins/module_utils/storage/dell/shared_library/snapshot.py @@ -62,7 +62,7 @@ def list_writable_snapshots(self): """ try: query_params = self.module.params.get('query_parameters') - writable_snapshot_query_params = query_params.get('writable_snapshot', []) if query_params else [] + writable_snapshot_query_params = query_params.get('writable_snapshots', []) if query_params else [] filter_params = {} if writable_snapshot_query_params: if "wspath" in writable_snapshot_query_params: diff --git a/plugins/modules/info.py b/plugins/modules/info.py index b565f043..8592d7a2 100644 --- a/plugins/modules/info.py +++ b/plugins/modules/info.py @@ -142,7 +142,7 @@ - Alert channels - C(alert_channels). - Alert categories - C(alert_categories). - Event groups - C(event_group). - - Writable snapshots - C(writable_snapshot). + - Writable snapshots - C(writable_snapshots). required: true choices: [attributes, access_zones, nodes, providers, users, groups, smb_shares, nfs_exports, nfs_aliases, clients, synciq_reports, synciq_target_reports, @@ -152,7 +152,7 @@ nfs_zone_settings, nfs_default_settings, nfs_global_settings, synciq_global_settings, s3_buckets, smb_global_settings, ntp_servers, email_settings, cluster_identity, cluster_owner, snmp_settings, server_certificate, roles, support_assist_settings, smartquota, filesystem, alert_settings, - alert_rules, alert_channels, alert_categories, event_group, writable_snapshot] + alert_rules, alert_channels, alert_categories, event_group, writable_snapshots] type: list elements: str filters: @@ -185,10 +185,10 @@ description: - Contains dictionary of query parameters for specific I(gather_subset). - Applicable to C(alert_rules), C(event_group), C(event_channels), C(filesystem) - and C(writable_snapshot). - - If C(writable_snapshot) is passed as I(gather_subset), if I(wspath) is given, - all other query parameters inside I(writable_snapshot) will be ignored. - - To view the list of supported query parameters for C(writable_snapshot), + and C(writable_snapshots). + - If C(writable_snapshots) is passed as I(gather_subset), if I(wspath) is given, + all other query parameters inside I(writable_snapshots) will be ignored. + - To view the list of supported query parameters for C(writable_snapshots), refer Query Parameters section from U(https://developer.dell.com/apis/4088/versions/9.5.0/9.5.0.0_ISLANDER_OAS2.json/ paths/~1platform~114~1snapshot~1writable/get) @@ -198,7 +198,7 @@ - The parameters I(access_zone) and I(include_all_access_zones) are mutually exclusive. - The I(check_mode) is supported. - Filter functionality is supported only for the following 'gather_subset'- 'nfs', 'smartquota', 'filesystem' - 'writable_snapshot'. + 'writable_snapshots'. ''' EXAMPLES = r''' @@ -725,7 +725,7 @@ api_user: "{{ api_user }}" api_password: "{{ api_password }}" gather_subset: - - writable_snapshot + - writable_snapshots - name: To get the specific writable snapshot. dellemc.powerscale.info: @@ -734,9 +734,9 @@ api_user: "{{ api_user }}" api_password: "{{ api_password }}" gather_subset: - - writable_snapshot + - writable_snapshots query_parameters: - writable_snapshot: + writable_snapshots: wspath: "/ifs/test_mkdir" - name: To filter the writable snapshot in ascending order. @@ -746,9 +746,9 @@ api_user: "{{ api_user }}" api_password: "{{ api_password }}" gather_subset: - - writable_snapshot + - writable_snapshots query_parameters: - writable_snapshot: + writable_snapshots: dir: ASC limit: 1 @@ -759,9 +759,9 @@ api_user: "{{ api_user }}" api_password: "{{ api_password }}" gather_subset: - - writable_snapshot + - writable_snapshots query_parameters: - writable_snapshot: + writable_snapshots: sort: src_snap state: active ''' @@ -4037,7 +4037,7 @@ def perform_module_operation(self): 'event_group': lambda: Events(self.event_api, self.module).get_event_groups(), 'smartquota': self.get_smartquota_list, 'filesystem': lambda: self.get_filesystem_list(path, query_params), - 'writable_snapshot': self.get_writable_snapshots + 'writable_snapshots': self.get_writable_snapshots } key_mapping = { @@ -4081,7 +4081,7 @@ def perform_module_operation(self): 'event_group': 'event_groups', 'smartquota': 'smart_quota', 'filesystem': 'file_system', - 'writable_snapshot': 'writable_snapshots' + 'writable_snapshots': 'writable_snapshots' } # Map the subset to the appropriate Key @@ -4093,7 +4093,7 @@ def perform_module_operation(self): 'nfs_default_settings', 'nfs_global_settings', 'synciq_global_settings', 's3_buckets', 'smb_global_settings', 'ntp_servers', 'email_settings', 'cluster_identity', 'cluster_owner', 'snmp_settings', 'server_certificate', 'event_group', 'smartquota', 'filesystem', - 'writable_snapshot'] + 'writable_snapshots'] for key in subset: if key not in subset_list: result[key] = subset_mapping[key]() @@ -4145,7 +4145,7 @@ def get_info_parameters(): 'snmp_settings', 'server_certificate', 'roles', 'support_assist_settings', 'alert_settings', 'alert_rules', 'alert_channels', 'alert_categories', 'event_group', - 'filesystem', 'smartquota', 'writable_snapshot']), + 'filesystem', 'smartquota', 'writable_snapshots']), filters=dict(type='list', required=False, elements='dict', diff --git a/tests/unit/plugins/module_utils/mock_info_api.py b/tests/unit/plugins/module_utils/mock_info_api.py index ed4e9dda..43c3e2ab 100644 --- a/tests/unit/plugins/module_utils/mock_info_api.py +++ b/tests/unit/plugins/module_utils/mock_info_api.py @@ -1715,7 +1715,7 @@ def get_gather_facts_module_response(gather_subset): "alert_settings": MockGatherfactsApi.get_event_maintenance(param), "filesystem": MockGatherfactsApi.get_filesystem_list(param), "smartquota": MockGatherfactsApi.get_smartquota_list(param), - "writable_snapshot": MockGatherfactsApi.get_writable_snapshot_list(param) + "writable_snapshots": MockGatherfactsApi.get_writable_snapshot_list(param) } return subset_error_dict.get(gather_subset) @@ -1762,7 +1762,7 @@ def get_gather_facts_api_response(gather_subset): "alert_settings": MockGatherfactsApi.get_event_maintenance(param), "filesystem": MockGatherfactsApi.get_filesystem_list(param), "smartquota": MockGatherfactsApi.get_smartquota_list(param), - "writable_snapshot": MockGatherfactsApi.get_writable_snapshot_list(param) + "writable_snapshots": MockGatherfactsApi.get_writable_snapshot_list(param) } return subset_error_dict.get(gather_subset) @@ -1811,7 +1811,7 @@ def get_gather_facts_error_response(gather_subset): "alert_settings": MockGatherfactsApi.get_event_maintenance(param), "filesystem": MockGatherfactsApi.get_filesystem_list(param), "smartquota": MockGatherfactsApi.get_smartquota_list(param), - "writable_snapshot": MockGatherfactsApi.get_writable_snapshot_list(param) + "writable_snapshots": MockGatherfactsApi.get_writable_snapshot_list(param) } return subset_error_dict.get(gather_subset) @@ -1864,6 +1864,6 @@ def get_gather_facts_error_method(gather_subset): "alert_settings": "get_event_maintenance", "smartquota": "list_quota_quotas", "filesystem": "get_directory_contents", - "writable_snapshot": "list_snapshot_writable", + "writable_snapshots": "list_snapshot_writable", } return subset_method_dict.get(gather_subset) diff --git a/tests/unit/plugins/modules/test_info.py b/tests/unit/plugins/modules/test_info.py index d5118c1a..0a7e9e8b 100644 --- a/tests/unit/plugins/modules/test_info.py +++ b/tests/unit/plugins/modules/test_info.py @@ -725,7 +725,7 @@ def test_get_facts_filesystem_api_exception(self, gatherfacts_module_mock, gathe gather_subset) in gatherfacts_module_mock.module.fail_json.call_args[1]['msg'] @pytest.mark.parametrize("input_params", [ - {"gather_subset": "writable_snapshot", "return_key": "writable_snapshots"} + {"gather_subset": "writable_snapshots", "return_key": "writable_snapshots"} ] ) def test_get_facts_writable_snapshot_api_module(self, gatherfacts_module_mock, input_params): @@ -736,7 +736,7 @@ def test_get_facts_writable_snapshot_api_module(self, gatherfacts_module_mock, i api_response = MockGatherfactsApi.get_gather_facts_api_response( gather_subset) self.get_module_args.update({ - 'gather_subset': ['writable_snapshot'], + 'gather_subset': ['writable_snapshots'], 'zone': "System", "filters": [{"filter_key": "id", "filter_operator": "equal", "filter_value": 66258688}] }) @@ -749,13 +749,13 @@ def test_get_facts_writable_snapshot_api_module(self, gatherfacts_module_mock, i gather_subset) == gatherfacts_module_mock.module.exit_json.call_args[1][return_key] @pytest.mark.parametrize("gather_subset", [ - "writable_snapshot" + "writable_snapshots" ] ) def test_get_facts_writable_snapshot_api_exception(self, gatherfacts_module_mock, gather_subset): """Test the get_facts that uses the writable snapshot api endpoint to get the exception""" self.get_module_args.update({ - 'gather_subset': ['writable_snapshot'], + 'gather_subset': ['writable_snapshots'], 'zone': "System", }) gatherfacts_module_mock.module.params = self.get_module_args From ce1e2a221f70324163ed27fdc6d5b63b8c30c12d Mon Sep 17 00:00:00 2001 From: Kritika-Bhateja-03 Date: Wed, 14 Aug 2024 07:22:26 +0000 Subject: [PATCH 10/11] Doc changes --- docs/modules/info.rst | 24 ++++++++++++------------ playbooks/modules/info.yml | 14 +++++++------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/docs/modules/info.rst b/docs/modules/info.rst index 8d930e49..5f3aed3d 100644 --- a/docs/modules/info.rst +++ b/docs/modules/info.rst @@ -192,7 +192,7 @@ Parameters Event groups - \ :literal:`event\_group`\ . - Writable snapshots - \ :literal:`writable\_snapshot`\ . + Writable snapshots - \ :literal:`writable\_snapshots`\ . filters (False, list, None) @@ -219,11 +219,11 @@ Parameters query_parameters (optional, dict, None) Contains dictionary of query parameters for specific \ :emphasis:`gather\_subset`\ . - Applicable to \ :literal:`alert\_rules`\ , \ :literal:`event\_group`\ , \ :literal:`event\_channels`\ , \ :literal:`filesystem`\ and \ :literal:`writable\_snapshot`\ . + Applicable to \ :literal:`alert\_rules`\ , \ :literal:`event\_group`\ , \ :literal:`event\_channels`\ , \ :literal:`filesystem`\ and \ :literal:`writable\_snapshots`\ . - If \ :literal:`writable\_snapshot`\ is passed as \ :emphasis:`gather\_subset`\ , if \ :emphasis:`wspath`\ is given, all other query parameters inside \ :emphasis:`writable\_snapshot`\ will be ignored. + If \ :literal:`writable\_snapshots`\ is passed as \ :emphasis:`gather\_subset`\ , if \ :emphasis:`wspath`\ is given, all other query parameters inside \ :emphasis:`writable\_snapshots`\ will be ignored. - To view the list of supported query parameters for \ :literal:`writable\_snapshot`\ , refer Query Parameters section from \ https://developer.dell.com/apis/4088/versions/9.5.0/9.5.0.0_ISLANDER_OAS2.json/%20paths/~1platform~114~1snapshot~1writable/get\ + To view the list of supported query parameters for \ :literal:`writable\_snapshots`\ , refer Query Parameters section from \ https://developer.dell.com/apis/4088/versions/9.5.0/9.5.0.0_ISLANDER_OAS2.json/%20paths/~1platform~114~1snapshot~1writable/get\ onefs_host (True, str, None) @@ -259,7 +259,7 @@ Notes .. note:: - The parameters \ :emphasis:`access\_zone`\ and \ :emphasis:`include\_all\_access\_zones`\ are mutually exclusive. - The \ :emphasis:`check\_mode`\ is supported. - - Filter functionality is supported only for the following 'gather\_subset'- 'nfs', 'smartquota', 'filesystem' 'writable\_snapshot'. + - Filter functionality is supported only for the following 'gather\_subset'- 'nfs', 'smartquota', 'filesystem' 'writable\_snapshots'. - The modules present in this collection named as 'dellemc.powerscale' are built to support the Dell PowerScale storage platform. @@ -794,7 +794,7 @@ Examples api_user: "{{ api_user }}" api_password: "{{ api_password }}" gather_subset: - - writable_snapshot + - writable_snapshots - name: To get the specific writable snapshot. dellemc.powerscale.info: @@ -803,9 +803,9 @@ Examples api_user: "{{ api_user }}" api_password: "{{ api_password }}" gather_subset: - - writable_snapshot + - writable_snapshots query_parameters: - writable_snapshot: + writable_snapshots: wspath: "/ifs/test_mkdir" - name: To filter the writable snapshot in ascending order. @@ -815,9 +815,9 @@ Examples api_user: "{{ api_user }}" api_password: "{{ api_password }}" gather_subset: - - writable_snapshot + - writable_snapshots query_parameters: - writable_snapshot: + writable_snapshots: dir: ASC limit: 1 @@ -828,9 +828,9 @@ Examples api_user: "{{ api_user }}" api_password: "{{ api_password }}" gather_subset: - - writable_snapshot + - writable_snapshots query_parameters: - writable_snapshot: + writable_snapshots: sort: src_snap state: active diff --git a/playbooks/modules/info.yml b/playbooks/modules/info.yml index f2667fd2..23ef6395 100644 --- a/playbooks/modules/info.yml +++ b/playbooks/modules/info.yml @@ -403,7 +403,7 @@ api_user: "{{ api_user }}" api_password: "{{ api_password }}" gather_subset: - - writable_snapshot + - writable_snapshots - name: To get the specific writable snapshot dellemc.powerscale.info: @@ -412,9 +412,9 @@ api_user: "{{ api_user }}" api_password: "{{ api_password }}" gather_subset: - - writable_snapshot + - writable_snapshots query_parameters: - writable_snapshot: + writable_snapshots: wspath: "/ifs/test_mkdir" - name: To filter the writable snapshot in ascending order @@ -424,9 +424,9 @@ api_user: "{{ api_user }}" api_password: "{{ api_password }}" gather_subset: - - writable_snapshot + - writable_snapshots query_parameters: - writable_snapshot: + writable_snapshots: dir: ASC limit: 1 @@ -437,8 +437,8 @@ api_user: "{{ api_user }}" api_password: "{{ api_password }}" gather_subset: - - writable_snapshot + - writable_snapshots query_parameters: - writable_snapshot: + writable_snapshots: sort: src_snap state: active From a2434580966e17769dd00a6dd8bca7494fc22057 Mon Sep 17 00:00:00 2001 From: Kritika-Bhateja-03 Date: Fri, 16 Aug 2024 08:58:36 +0000 Subject: [PATCH 11/11] Doc changes --- docs/modules/info.rst | 10 ++++++---- plugins/modules/info.py | 12 ++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/docs/modules/info.rst b/docs/modules/info.rst index 5f3aed3d..3d14ae97 100644 --- a/docs/modules/info.rst +++ b/docs/modules/info.rst @@ -223,7 +223,9 @@ Parameters If \ :literal:`writable\_snapshots`\ is passed as \ :emphasis:`gather\_subset`\ , if \ :emphasis:`wspath`\ is given, all other query parameters inside \ :emphasis:`writable\_snapshots`\ will be ignored. - To view the list of supported query parameters for \ :literal:`writable\_snapshots`\ , refer Query Parameters section from \ https://developer.dell.com/apis/4088/versions/9.5.0/9.5.0.0_ISLANDER_OAS2.json/%20paths/~1platform~114~1snapshot~1writable/get\ + To view the list of supported query parameters for \ :literal:`writable\_snapshots`\ . + + Refer Query Parameters section from \ https://developer.dell.com/apis/4088/versions/9.5.0/9.5.0.0_ISLANDER_OAS2.json/%20paths/~1platform~114~1snapshot~1writable/get\ . onefs_host (True, str, None) @@ -796,7 +798,7 @@ Examples gather_subset: - writable_snapshots - - name: To get the specific writable snapshot. + - name: To get the specific writable snapshot dellemc.powerscale.info: onefs_host: "{{ onefs_host }}" verify_ssl: "{{ verify_ssl }}" @@ -808,7 +810,7 @@ Examples writable_snapshots: wspath: "/ifs/test_mkdir" - - name: To filter the writable snapshot in ascending order. + - name: To filter the writable snapshot in ascending order dellemc.powerscale.info: onefs_host: "{{ onefs_host }}" verify_ssl: "{{ verify_ssl }}" @@ -821,7 +823,7 @@ Examples dir: ASC limit: 1 - - name: To filter the writable snapshot using sort. + - name: To filter the writable snapshot using sort dellemc.powerscale.info: onefs_host: "{{ onefs_host }}" verify_ssl: "{{ verify_ssl }}" diff --git a/plugins/modules/info.py b/plugins/modules/info.py index 8592d7a2..7185dad8 100644 --- a/plugins/modules/info.py +++ b/plugins/modules/info.py @@ -188,10 +188,10 @@ and C(writable_snapshots). - If C(writable_snapshots) is passed as I(gather_subset), if I(wspath) is given, all other query parameters inside I(writable_snapshots) will be ignored. - - To view the list of supported query parameters for C(writable_snapshots), - refer Query Parameters section from + - To view the list of supported query parameters for C(writable_snapshots). + - Refer Query Parameters section from U(https://developer.dell.com/apis/4088/versions/9.5.0/9.5.0.0_ISLANDER_OAS2.json/ - paths/~1platform~114~1snapshot~1writable/get) + paths/~1platform~114~1snapshot~1writable/get). type: dict version_added: '3.2.0' notes: @@ -727,7 +727,7 @@ gather_subset: - writable_snapshots -- name: To get the specific writable snapshot. +- name: To get the specific writable snapshot dellemc.powerscale.info: onefs_host: "{{ onefs_host }}" verify_ssl: "{{ verify_ssl }}" @@ -739,7 +739,7 @@ writable_snapshots: wspath: "/ifs/test_mkdir" -- name: To filter the writable snapshot in ascending order. +- name: To filter the writable snapshot in ascending order dellemc.powerscale.info: onefs_host: "{{ onefs_host }}" verify_ssl: "{{ verify_ssl }}" @@ -752,7 +752,7 @@ dir: ASC limit: 1 -- name: To filter the writable snapshot using sort. +- name: To filter the writable snapshot using sort dellemc.powerscale.info: onefs_host: "{{ onefs_host }}" verify_ssl: "{{ verify_ssl }}"