Skip to content

Commit 7230f37

Browse files
[zos_data_set] GDG creation failing when using replace option (#1964)
* Adding Bug fix #1958 and testcase * Create 1964-zos_data_test-fixing-gdg-replace-issue * Removing print statements * fixing PR comments
1 parent 553881e commit 7230f37

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bugfixes:
2+
- zos_data_set - Module would fail with TypeError when trying to replace an existing GDG. Fix now allows to replacing a GDG.
3+
https://github.com/ansible-collections/ibm_zos_core/pull/1964

plugins/module_utils/data_set.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2433,7 +2433,7 @@ def ensure_present(self, replace):
24332433
else:
24342434
if not replace:
24352435
return changed
2436-
changed = self.ensure_absent()
2436+
changed = self.ensure_absent(True)
24372437
gdg = gdgs.create(**arguments)
24382438
if isinstance(gdg, gdgs.GenerationDataGroupView):
24392439
changed = True

tests/functional/modules/test_zos_data_set_func.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,3 +1103,22 @@ def test_create_member_special_chars(ansible_zos_module):
11031103
finally:
11041104
hosts.all.zos_data_set(name=data_set_name, state="absent")
11051105

1106+
1107+
def test_gdg_create_and_replace(ansible_zos_module):
1108+
try:
1109+
hosts = ansible_zos_module
1110+
data_set_name = get_tmp_ds_name()
1111+
results = hosts.all.zos_data_set(name=data_set_name, empty=False, force=True, record_format="u",
1112+
record_length=0, replace=True, space_primary=5, space_secondary=3,
1113+
space_type="cyl", state="present", type="gdg", limit=3)
1114+
for result in results.contacted.values():
1115+
assert result.get("changed") is True
1116+
assert result.get("module_stderr") is None
1117+
results = hosts.all.zos_data_set(name=data_set_name, empty=False, force=True, record_format="u",
1118+
record_length=0, replace=True, space_primary=5, space_secondary=3,
1119+
space_type="cyl", state="present", type="gdg", limit=3)
1120+
for result in results.contacted.values():
1121+
assert result.get("changed") is True
1122+
assert result.get("module_stderr") is None
1123+
finally:
1124+
hosts.all.zos_data_set(name=data_set_name, state="absent", force=True, type="gdg")

0 commit comments

Comments
 (0)