Skip to content

Commit 43c7272

Browse files
Enabler/1379/zos tso command gdg support (#1563)
* Add test case and support for gds * Add functional test cases and gds suport for 0 and - notation * modified check for data sets function * Documented tso_command functions * Simplified the data set name find * Removed unused fullmatch import * Added changelog * Adding profile noprefix to zos_tso_command tests * Added changelog fragment * Fixed test about GDS * Modified tests * Fixed pep issue * Added gds relative name check --------- Co-authored-by: André Marcel Gutiérrez Benítez <[email protected]>
1 parent 0d9faa6 commit 43c7272

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
minor_changes:
2+
- zos_mvs_raw - Added support for GDG and GDS relative name notation to use a data set name.
3+
Added support for data set names with special characters like $, /#, /- and @.
4+
(https://github.com/ansible-collections/ibm_zos_core/pull/1563).

plugins/modules/zos_tso_command.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@
126126
"""
127127

128128
from ansible.module_utils.basic import AnsibleModule
129+
from ansible_collections.ibm.ibm_zos_core.plugins.module_utils import data_set
129130
from os import chmod
131+
import re
130132
from tempfile import NamedTemporaryFile
131133
from stat import S_IEXEC, S_IREAD, S_IWRITE
132134
from ansible_collections.ibm.ibm_zos_core.plugins.module_utils.better_arg_parser import (
@@ -253,6 +255,31 @@ def list_or_str_type(contents, dependencies):
253255
return contents
254256

255257

258+
def preprocess_data_set_names(command):
259+
"""
260+
Applies necessary preprocessing to the data set names, such as converting
261+
a GDS relative name into an absolute one.
262+
263+
Parameters
264+
----------
265+
command : str
266+
command in which to look for a data set name.
267+
268+
Returns
269+
-------
270+
str
271+
The command with the modified data set names if any.
272+
273+
"""
274+
pattern = r"(?:(?:[A-Z$#@]{1}[A-Z0-9$#@-]{0,7})(?:[.]{1})){1,21}[A-Z$#@]{1}[A-Z0-9$#@-]{0,7}(?:\([A-Z$#@]{1}[A-Z0-9$#@]{0,7}\)|\((?:[-+]?[0-9]+)\)){0,1}"
275+
data_set_list = re.findall(pattern, command)
276+
for name in data_set_list:
277+
if data_set.DataSet.is_gds_relative_name(name):
278+
dataset_name = data_set.DataSet.resolve_gds_absolute_name(name)
279+
command = command.replace(name, dataset_name)
280+
return command
281+
282+
256283
def run_module():
257284
"""Initialize module.
258285
@@ -287,6 +314,7 @@ def run_module():
287314
module.fail_json(msg=repr(e), **result)
288315

289316
commands = parsed_args.get("commands")
317+
commands = list(map(preprocess_data_set_names, commands))
290318
max_rc = parsed_args.get("max_rc")
291319
if max_rc is None:
292320
max_rc = 0

tests/functional/modules/test_zos_tso_command_func.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,36 @@ def test_zos_tso_command_maxrc(ansible_zos_module):
141141
for item in result.get("output"):
142142
assert item.get("rc") < 5
143143
assert result.get("changed") is True
144+
145+
146+
def test_zos_tso_command_gds(ansible_zos_module):
147+
try:
148+
hosts = ansible_zos_module
149+
default_data_set = get_tmp_ds_name(3, 3, symbols=True)
150+
hosts.all.shell(cmd="dtouch -tGDG -L2 '{0}'".format(default_data_set))
151+
hosts.all.shell(cmd="dtouch -tseq '{0}(+1)' ".format(default_data_set))
152+
hosts.all.shell(cmd="dtouch -tseq '{0}(+1)' ".format(default_data_set))
153+
print(f"data set name {default_data_set}")
154+
hosts = ansible_zos_module
155+
results = hosts.all.zos_tso_command(
156+
commands=["""LISTDSD DATASET('{0}(0)') ALL GENERIC""".format(default_data_set)],
157+
max_rc=4
158+
)
159+
for result in results.contacted.values():
160+
for item in result.get("output"):
161+
assert result.get("changed") is True
162+
results = hosts.all.zos_tso_command(
163+
commands=["""LISTDSD DATASET('{0}(-1)') ALL GENERIC""".format(default_data_set)],
164+
max_rc=4
165+
)
166+
for result in results.contacted.values():
167+
for item in result.get("output"):
168+
assert result.get("changed") is True
169+
results = hosts.all.zos_tso_command(
170+
commands=["""LISTDS '{0}(-1)'""".format(default_data_set)]
171+
)
172+
for result in results.contacted.values():
173+
assert result.get("changed") is True
174+
finally:
175+
None
176+
# hosts.all.shell(cmd="drm ANSIBLE.*".format(default_data_set))

0 commit comments

Comments
 (0)