Skip to content
12 changes: 6 additions & 6 deletions plugins/modules/snapshot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python
# Copyright: (c) 2019-2024, Dell Technologies
# Copyright: (c) 2019-2025, Dell Technologies

# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

Expand Down Expand Up @@ -336,7 +336,9 @@ def validate_expiration_timestamp(self, expiration_timestamp):
def get_filesystem_snapshot_details(self, snapshot_name):
"""Returns details of a filesystem Snapshot"""
try:
return self.snapshot_api.get_snapshot_snapshot(snapshot_name)
snapshot_details = self.snapshot_api.get_snapshot_snapshot(snapshot_name)
if snapshot_details:
return snapshot_details.to_dict()
except utils.ApiException as e:
if str(e.status) == "404":
log_msg = "Snapshot {0} status is " \
Expand Down Expand Up @@ -459,8 +461,6 @@ def rename_filesystem_snapshot(self, snapshot, new_name):
if snapshot is None:
self.module.fail_json(msg="Snapshot not found.")

snapshot = snapshot.to_dict()

if snapshot['snapshots'][0]['name'] == new_name:
return False
try:
Expand Down Expand Up @@ -517,7 +517,7 @@ def check_snapshot_modified(self, snapshot, alias,
snapshot_modification_details['is_timestamp_modified'] = False
snapshot_modification_details['new_expiration_timestamp_value'] = None

snap_details = snapshot.to_dict()
snap_details = snapshot

if effective_path is not None:
if self.module.params['path'] and \
Expand Down Expand Up @@ -820,7 +820,7 @@ def perform_module_operation(self):
'{0} details'.format(snapshot_name)
LOG.info(info_message)
result['snapshot_details'] = \
self.get_filesystem_snapshot_details(snapshot_name).to_dict()
self.get_filesystem_snapshot_details(snapshot_name)

# Finally update the module result!
self.module.exit_json(**result)
Expand Down
112 changes: 112 additions & 0 deletions tests/unit/plugins/module_utils/mock_snapshot_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Copyright: (c) 2025, Dell Technologies

# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

"""Mock API responses for PowerScale Snapshot module"""

from __future__ import (absolute_import, division, print_function)

__metaclass__ = type

MODULE_UTILS_PATH = 'ansible_collections.dellemc.powerscale.plugins.modules.snapshot.utils'

SNAPSHOT = {
"snapshots": [
{
"alias": "alias_name_1",
"created": 1628155527,
"expires": 10,
"has_locks": False,
"id": 936,
"name": "ansible_test_snapshot",
"path": "/ifs/ansible_test_snapshot",
"pct_filesystem": 2.435778242215747e-06,
"pct_reserve": 0.0,
"schedule": None,
"shadow_bytes": 0,
"size": 4096,
"state": "active",
"target_id": None,
"target_name": None
}
]
}

ALIAS = {
"snapshots": [
{
"target_name": "ansible_test_snapshot",
"name": "alias_name_1"
}
]
}

CREATE_SNAPSHOT_PARAMS = {
"name": "ansible_test_snapshot",
"path": "/ifs/ansible_test_snapshot",
"alias": "snap_alias_1",
"expires": 60}

MODIFY_SNAPSHOT_PARAMS = {"expires": 60}

RENAME_SNAPSHOT_PARAMS = {"name": "renamed_snapshot_name_1"}


def create_snapshot_failed_msg():
return 'Failed to create snapshot'


def modify_snapshot_failed_msg():
return 'Failed to modify snapshot'


def rename_snapshot_failed_msg():
return 'Failed to rename snapshot'


def invalid_access_zone_failed_msg():
return 'Unable to fetch base path of Access Zone invalid_zone ,failed with error: SDK Error message'


def get_snapshot_wo_name_failed_msg():
return 'Please provide a valid snapshot name'


def modify_snapshot_wo_desired_retention_failed_msg():
return 'Specify desired retention along with retention unit.'


def delete_snapshot_exception_failed_msg():
return 'Failed to delete snapshot'


def get_snapshot_alias_failed_msg():
return 'Failed to get alias for snapshot'


def create_snapshot_wo_retention_failed_msg():
return 'Please provide either desired_retention or expiration_timestamp for creating a snapshot'


def create_snapshot_with_new_name_failed_msg():
return 'Invalid param: new_name while creating a new snapshot.'


def create_snapshot_without_path_failed_msg():
return 'Please provide a valid path for snapshot creation'


def create_snapshot_wo_desired_retention_failed_msg():
return 'Desired retention is set to'


def create_snapshot_invalid_desired_retention_failed_msg():
return 'Please provide a valid integer as the desired retention.'


def modify_non_existing_path_failed_msg():
return 'specified in the playbook does not match the path of the snapshot'


def get_snapshot_failed_msg():
return 'Failed to get details of Snapshot'
Loading
Loading