Skip to content

Commit 1c64254

Browse files
[zos_mvs_raw] Find VSAM cluster when DISP=OLD and find data and index resource types (#1822)
* Added fix for zos_find * Added tests for fix * Updated changelog
1 parent cb6d498 commit 1c64254

File tree

3 files changed

+68
-4
lines changed

3 files changed

+68
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bugfixes:
2+
- zos_find - Module would not find a VSAM cluster resource type if it was in use with DISP=OLD. Fix now finds the VSAM cluster.
3+
(https://github.com/ansible-collections/ibm_zos_core/pull/1822).
4+
- zos_find - Module would not find VSAM data and index resource types. Fix now finds the data and index resource types.
5+
(https://github.com/ansible-collections/ibm_zos_core/pull/1822).

plugins/modules/zos_find.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,8 @@ def vsam_filter(module, patterns, resource_type, age=None):
503503
filtered_data_sets = set()
504504
now = time.time()
505505
for pattern in patterns:
506-
rc, out, err = _vls_wrapper(pattern, details=True)
506+
request_details = age is not None
507+
rc, out, err = _vls_wrapper(pattern, details=request_details)
507508
if rc > 4:
508509
module.fail_json(
509510
msg="Non-zero return code received while executing ZOAU shell command 'vls'",
@@ -1069,7 +1070,6 @@ def run_module(module):
10691070
size = int(m.group(1)) * bytes_per_unit.get(m.group(2), 1)
10701071
else:
10711072
module.fail_json(size=size, msg="failed to process size")
1072-
10731073
if resource_type == "NONVSAM":
10741074
if contains:
10751075
init_filtered_data_sets = content_filter(
@@ -1104,7 +1104,7 @@ def run_module(module):
11041104

11051105
res_args['examined'] = init_filtered_data_sets.get("searched")
11061106

1107-
elif resource_type == "CLUSTER":
1107+
elif resource_type in ["CLUSTER", "DATA", "INDEX"]:
11081108
filtered_data_sets = vsam_filter(module, patterns, resource_type, age=age)
11091109
res_args['examined'] = len(filtered_data_sets)
11101110
elif resource_type == "GDG":

tests/functional/modules/test_zos_find_func.py

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@
4242

4343
DATASET_TYPES = ['seq', 'pds', 'pdse']
4444

45+
LOCK_VSAM_JCL = """//SLEEP JOB (T043JM,JM00,1,0,0,0),'SLEEP - JRM',CLASS=R,
46+
// MSGCLASS=X,MSGLEVEL=1,NOTIFY=S0JM
47+
//STEP1 EXEC PGM=BPXBATCH,PARM='SH sleep 60'
48+
//VSAM1 DD DISP=OLD,DSN={0}
49+
//STDOUT DD SYSOUT=*
50+
//STDERR DD SYSOUT=*
51+
"""
4552

4653
def create_vsam_ksds(ds_name, ansible_zos_module, volume):
4754
hosts = ansible_zos_module
@@ -391,7 +398,6 @@ def test_find_data_sets_in_volume(ansible_zos_module, volumes_on_systems):
391398
hosts.all.zos_data_set(name=data_set_name, state="absent")
392399

393400

394-
395401
def test_find_vsam_pattern(ansible_zos_module, volumes_on_systems):
396402
hosts = ansible_zos_module
397403
try:
@@ -401,13 +407,34 @@ def test_find_vsam_pattern(ansible_zos_module, volumes_on_systems):
401407
volume = volumes.get_available_vol()
402408
create_vsam_ksds(vsam, hosts, volume)
403409

410+
# A KSDS VSAM has 3 different components, cluster, data and index
411+
# This test should find all three
404412
find_res = hosts.all.zos_find(
405413
patterns=[f'{TEST_SUITE_HLQ}.FIND.VSAM.FUNCTEST.*'],
406414
resource_type='cluster'
407415
)
408416
for val in find_res.contacted.values():
409417
assert len(val.get('data_sets')) == 1
410418
assert val.get('matched') == len(val.get('data_sets'))
419+
assert val.get('data_sets')[0].get("name", None) == VSAM_NAMES[0]
420+
421+
find_res = hosts.all.zos_find(
422+
patterns=[f'{TEST_SUITE_HLQ}.FIND.VSAM.FUNCTEST.*'],
423+
resource_type='data'
424+
)
425+
for val in find_res.contacted.values():
426+
assert len(val.get('data_sets')) == 1
427+
assert val.get('matched') == len(val.get('data_sets'))
428+
assert val.get('data_sets')[0].get("name", None) == f"{VSAM_NAMES[0]}.DATA"
429+
430+
find_res = hosts.all.zos_find(
431+
patterns=[f'{TEST_SUITE_HLQ}.FIND.VSAM.FUNCTEST.*'],
432+
resource_type='index'
433+
)
434+
for val in find_res.contacted.values():
435+
assert len(val.get('data_sets')) == 1
436+
assert val.get('matched') == len(val.get('data_sets'))
437+
assert val.get('data_sets')[0].get("name", None) == f"{VSAM_NAMES[0]}.INDEX"
411438
finally:
412439
hosts.all.zos_data_set(
413440
batch=[
@@ -419,6 +446,38 @@ def test_find_vsam_pattern(ansible_zos_module, volumes_on_systems):
419446
)
420447

421448

449+
def test_find_vsam_pattern_disp_old(ansible_zos_module, volumes_on_systems):
450+
"""
451+
Creates a VSAM cluster and runs a JCL to lock the data set with DISP=OLD.
452+
Then make sure that we can query the VSAM. Currently, if using age + cluster
453+
resource_type the module will not find the vsam.
454+
"""
455+
hosts = ansible_zos_module
456+
try:
457+
volumes = Volume_Handler(volumes_on_systems)
458+
jcl_ds = get_tmp_ds_name()
459+
for vsam in VSAM_NAMES:
460+
volume = volumes.get_available_vol()
461+
create_vsam_ksds(vsam, hosts, volume)
462+
463+
hosts.all.shell(cmd=f"decho \"{LOCK_VSAM_JCL.format(VSAM_NAMES[0])}\" '{jcl_ds}'; jsub '{jcl_ds}'")
464+
find_res = hosts.all.zos_find(
465+
patterns=[f'{TEST_SUITE_HLQ}.FIND.VSAM.FUNCTEST.*'],
466+
resource_type='cluster'
467+
)
468+
for val in find_res.contacted.values():
469+
assert len(val.get('data_sets')) == 1
470+
assert val.get('matched') == len(val.get('data_sets'))
471+
finally:
472+
hosts.all.zos_data_set(
473+
batch=[
474+
{
475+
"name":i,
476+
"state":'absent'
477+
} for i in VSAM_NAMES
478+
]
479+
)
480+
422481
def test_find_vsam_in_volume(ansible_zos_module, volumes_on_systems):
423482
hosts = ansible_zos_module
424483
volumes = Volume_Handler(volumes_on_systems)

0 commit comments

Comments
 (0)