Skip to content

Commit 9538504

Browse files
[v1.13.1][Bugfixes] [zos_data_set] Fixing GDG replace and empty GDG removal issues (#2035)
* Fixing #2003 and #2004 issues * Create 2035-zos_data_set-fixing-gdg-replace-and-empty-gdg-removal-issues.yaml * Update 2035-zos_data_set-fixing-gdg-replace-and-empty-gdg-removal-issues.yaml * Updating code to select volumes * Update test_zos_mount_func.py * Update 2035-zos_data_set-fixing-gdg-replace-and-empty-gdg-removal-issues.yaml
1 parent e7ffe6d commit 9538504

File tree

8 files changed

+295
-180
lines changed

8 files changed

+295
-180
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
bugfixes:
2+
- zos_data_set - Module would fail with TypeError when trying to replace an existing GDG.
3+
Fix now allows the replacement of an existing GDG.
4+
(https://github.com/ansible-collections/ibm_zos_core/pull/2035)
5+
6+
- zos_data_set - Module would fail when trying to delete a non-existent Generation Data Group.
7+
Fix now provides a successful response with `changed=false`.
8+
(https://github.com/ansible-collections/ibm_zos_core/pull/2035)
9+
10+
trivial:
11+
- test_zos_volume_init.py - Adds support of dynamic volumes and allocations for testing.
12+
(https://github.com/ansible-collections/ibm_zos_core/pull/2035).

plugins/module_utils/data_set.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,7 +2414,7 @@ def ensure_present(self, replace):
24142414
else:
24152415
if not replace:
24162416
return changed
2417-
changed = self.ensure_absent()
2417+
changed = self.ensure_absent(True)
24182418
gdg = gdgs.create(**arguments)
24192419
if isinstance(gdg, gdgs.GenerationDataGroupView):
24202420
changed = True
@@ -2434,17 +2434,21 @@ def ensure_absent(self, force):
24342434
int
24352435
Indicates if changes were made.
24362436
"""
2437-
# Try to delete
2438-
rc = datasets.delete(self.name)
2439-
if rc > 0:
2440-
if force:
2441-
if isinstance(self.gdg, gdgs.GenerationDataGroupView):
2442-
self.gdg.delete()
2437+
# Check whether GDG exists or not
2438+
if gdgs.exists(name=self.name):
2439+
# Try to delete
2440+
rc = datasets.delete(self.name)
2441+
if rc > 0:
2442+
if force:
2443+
if isinstance(self.gdg, gdgs.GenerationDataGroupView):
2444+
self.gdg.delete()
2445+
else:
2446+
gdg_view = gdgs.GenerationDataGroupView(name=self.name)
2447+
gdg_view.delete()
24432448
else:
2444-
gdg_view = gdgs.GenerationDataGroupView(name=self.name)
2445-
gdg_view.delete()
2446-
else:
2447-
raise DatasetDeleteError(self.raw_name, rc)
2449+
raise DatasetDeleteError(self.raw_name, rc)
2450+
else:
2451+
return False
24482452
return True
24492453

24502454
def clear(self):

tests/conftest.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
__metaclass__ = type
1515
import pytest
1616
from ibm_zos_core.tests.helpers.ztest import ZTestHelper
17-
from ibm_zos_core.tests.helpers.volumes import get_volumes, get_volumes_with_vvds
17+
from ibm_zos_core.tests.helpers.volumes import get_volumes, get_volumes_with_vvds, get_volume_and_unit
1818
from ansible.plugins.action import ActionBase
1919
import sys
2020
from mock import MagicMock
@@ -194,3 +194,19 @@ def get_config(request):
194194
""" Call the pytest-ansible plugin to check volumes on the system and work properly a list by session."""
195195
path = request.config.getoption("--zinventory")
196196
yield path
197+
198+
199+
@pytest.fixture(scope="session")
200+
def volumes_unit_on_systems(ansible_zos_module, request):
201+
""" Call the pytest-ansible plugin to check volumes on the system and work properly a list by session."""
202+
path = request.config.getoption("--zinventory")
203+
list_volumes = None
204+
205+
if path is None:
206+
src = request.config.getoption("--zinventory-raw")
207+
helper = ZTestHelper.from_args(src)
208+
list_volumes = helper.get_volume_and_unit()
209+
else:
210+
list_volumes = get_volume_and_unit(ansible_zos_module, path)
211+
212+
yield list_volumes

tests/functional/modules/test_zos_data_set_func.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,3 +1103,33 @@ 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")
1125+
1126+
1127+
def test_gdg_deletion_when_absent(ansible_zos_module):
1128+
hosts = ansible_zos_module
1129+
data_set_name = get_tmp_ds_name()
1130+
results = hosts.all.zos_data_set(name=data_set_name, force=False, record_format="fb", replace=False,
1131+
space_primary=5, space_secondary=3, space_type="m", state="absent", type="gdg")
1132+
for result in results.contacted.values():
1133+
assert result.get("changed") is False
1134+
assert result.get("module_stderr") is None
1135+
assert result.get("failed") is None

tests/functional/modules/test_zos_mount_func.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def create_sourcefile(hosts, volume):
7474
mount_result = hosts.all.shell(
7575
cmd="zfsadm define -aggregate "
7676
+ thisfile
77-
+ " -volumes {0} -cylinders 200 1".format(volume),
77+
+ " -volumes {0} -cylinders 10 1".format(volume),
7878
executable=SHELL_EXECUTABLE,
7979
stdin="",
8080
)

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)