Skip to content

Commit 83bcfc6

Browse files
[Bug] Failure when trying to delete dataset with type 'gdg' (#1971)
* Adding if condition to check whether GDG exists or not before trying to delete * Adding change logs * Update year in license * Updating impacted testcase * Updating changelog * Update changelogs/fragments/1971-zos_data_set-fixing-gdg-delete-issue.yml Co-authored-by: Alex Moreno <[email protected]> * updating testcase --------- Co-authored-by: Alex Moreno <[email protected]>
1 parent 349cd05 commit 83bcfc6

File tree

6 files changed

+33
-15
lines changed

6 files changed

+33
-15
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bugfixes:
2+
- zos_data_set - Module would fail when trying to delete a non-existent Generation Data Group.
3+
Fix now provides a successful response with `changed=false`.
4+
(https://github.com/ansible-collections/ibm_zos_core/pull/1971)

plugins/module_utils/data_set.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) IBM Corporation 2020, 2024
1+
# Copyright (c) IBM Corporation 2020, 2025
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -2453,17 +2453,21 @@ def ensure_absent(self, force):
24532453
int
24542454
Indicates if changes were made.
24552455
"""
2456-
# Try to delete
2457-
rc = datasets.delete(self.name)
2458-
if rc > 0:
2459-
if force:
2460-
if isinstance(self.gdg, gdgs.GenerationDataGroupView):
2461-
self.gdg.delete()
2456+
# Check whether GDG exists or not
2457+
if gdgs.exists(name=self.name):
2458+
# Try to delete
2459+
rc = datasets.delete(self.name)
2460+
if rc > 0:
2461+
if force:
2462+
if isinstance(self.gdg, gdgs.GenerationDataGroupView):
2463+
self.gdg.delete()
2464+
else:
2465+
gdg_view = gdgs.GenerationDataGroupView(name=self.name)
2466+
gdg_view.delete()
24622467
else:
2463-
gdg_view = gdgs.GenerationDataGroupView(name=self.name)
2464-
gdg_view.delete()
2465-
else:
2466-
raise DatasetDeleteError(self.raw_name, rc)
2468+
raise DatasetDeleteError(self.raw_name, rc)
2469+
else:
2470+
return False
24672471
return True
24682472

24692473
def clear(self):

plugins/modules/zos_data_set.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/python
22
# -*- coding: utf-8 -*-
33

4-
# Copyright (c) IBM Corporation 2019, 2024
4+
# Copyright (c) IBM Corporation 2019, 2025
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
77
# You may obtain a copy of the License at

tests/functional/modules/test_zos_data_set_func.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,4 +1121,14 @@ def test_gdg_create_and_replace(ansible_zos_module):
11211121
assert result.get("changed") is True
11221122
assert result.get("module_stderr") is None
11231123
finally:
1124-
hosts.all.zos_data_set(name=data_set_name, state="absent", force=True, type="gdg")
1124+
hosts.all.zos_data_set(name=data_set_name, state="absent", force=True, type="gdg")
1125+
1126+
def test_gdg_deletion_when_absent(ansible_zos_module):
1127+
hosts = ansible_zos_module
1128+
data_set_name = get_tmp_ds_name()
1129+
results = hosts.all.zos_data_set(name=data_set_name, force=False, record_format="fb", replace=False,
1130+
space_primary=5, space_secondary=3, space_type="m", state="absent", type="gdg")
1131+
for result in results.contacted.values():
1132+
assert result.get("changed") is False
1133+
assert result.get("module_stderr") is None
1134+
assert result.get("failed") is None

tests/functional/modules/test_zos_unarchive_func.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,8 +1164,8 @@ def test_gdg_unarchive(ansible_zos_module, dstype, format):
11641164

11651165
hosts.all.zos_data_set(
11661166
batch=[
1167-
{"name": f"{data_set_name}(-1)", "state": "absent", "type": "gdg"},
1168-
{"name": f"{data_set_name}(0)", "state": "absent", "type": "gdg"},
1167+
{"name": f"{data_set_name}(-1)", "state": "absent"},
1168+
{"name": f"{data_set_name}(0)", "state": "absent"},
11691169
]
11701170
)
11711171
unarchive_result = hosts.all.zos_unarchive(

0 commit comments

Comments
 (0)