Skip to content

Commit 811082d

Browse files
richp405fernandofloresgrexemin
authored
Add symbol support to zos_apf (#1493)
* modified DatasetCreatedError message * Added gdg functions * Created unit test for validating gds relative name * Updated to fail when future gen * Update arg parser * Add escaping function for data set names * Add unit tests for name escaping * Remove calls to escape_data_set_name * renamed tests * Added MVSDataset class * Updated escaped symbols * Updated tests * Added utils * Add changelog * Uncommented test * Updated exception * Updated mvsdataset class * Updated class * initial branch save with escaping added, changelog fragment rough-in Also changed dataset to have a bool indicating if symbols can be included in get_tmp_ds_name * corrected changelog fragment to include PR number in link added import to zos_apf to get staticmethod loaded. * added output to a failing test * fixing pprint statement * added escape function to get_tmp_dataset * corrected staticmethod declaration * change in volume finder to add all volume lists to the base value * changing volume lister to handle potentially blank sub-lists * adding protection in get_volumes for a short line of input * added object definition to get_temp_ds_name * added detail into test that is failing (finally back to test) * removing potential import loop * pulled from dev, then removed unneeded arg value. * tweaking the get_volumes logic to handle partial lists. * putting dataset reference back into tests/helpers * re-commenting to see if that impacts loading of backup module * added detail to make sure (looks like some commands actually break with escaping) * sorting out the error details. Will need to table what can't shouldn't be escaped: something@something works, something \@something works, something\\@something fails * temporarily disabled escaping in main zos_apf call * fixed missing declaration issue * cleanup of comments and trace notes * changed fragment to minor_changes * corrected get_tmp_ds for symbols=false removed several print statements from test case. * removed extra line between import statments - unneeded change. * updated symbols generation for better distribution updated credits for both developers involved. * changed test of batch_add_del to not use symbols * remove first ds name (library) symbol option in test_batch_add_del * added prettyprint into failing assertion, re-activating symbols on first get_ds * included output for test print * removed escape of dsn in zos_apf/554 * removed print/pprint from testing re-enabled symbol usage in second test wave * removed a previously commented out line (removing escaping from batch call) --------- Co-authored-by: Fernando Flores <[email protected]> Co-authored-by: Ivan Moreno <[email protected]>
1 parent cac9810 commit 811082d

File tree

5 files changed

+32
-24
lines changed

5 files changed

+32
-24
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
minor_changes:
2+
- zos_apf - Change input to auto-escape 'library' names containing symbols
3+
(https://github.com/ansible-collections/ibm_zos_core/pull/1493).

plugins/modules/zos_apf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
version_added: '1.3.0'
2323
author:
2424
- "Behnam (@balkajbaf)"
25+
- "Rich Parker (@richp405)"
26+
- "Fernando Flores (@fernandofloresg))"
2527
short_description: Add or remove libraries to Authorized Program Facility (APF)
2628
description:
2729
- Adds or removes libraries to Authorized Program Facility (APF).
@@ -508,7 +510,8 @@ def main():
508510
except ValueError as err:
509511
module.fail_json(msg="Parameter verification failed", stderr=str(err))
510512

511-
library = parsed_args.get('library')
513+
library = parsed_args.get("library")
514+
512515
state = parsed_args.get('state')
513516
force_dynamic = parsed_args.get('force_dynamic')
514517
volume = parsed_args.get('volume')

tests/functional/modules/test_zos_apf_func.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
from __future__ import absolute_import, division, print_function
1515
from ibm_zos_core.tests.helpers.dataset import get_tmp_ds_name
1616
from ibm_zos_core.tests.helpers.volumes import Volume_Handler
17-
from shellescape import quote
18-
from pprint import pprint
17+
from shlex import quote
1918

2019
__metaclass__ = type
2120

@@ -56,7 +55,7 @@ def test_add_del(ansible_zos_module, volumes_with_vvds):
5655
VolumeHandler = Volume_Handler(volumes_with_vvds)
5756
volume = VolumeHandler.get_available_vol()
5857
test_info = dict(library="", state="present", force_dynamic=True)
59-
ds = get_tmp_ds_name(3,2)
58+
ds = get_tmp_ds_name(3,2,True)
6059
hosts.all.shell(f"dtouch -tseq -V{volume} {ds} ")
6160
test_info['library'] = ds
6261
if test_info.get('volume') is not None:
@@ -93,7 +92,7 @@ def test_add_del_with_tmp_hlq_option(ansible_zos_module, volumes_with_vvds):
9392
tmphlq = "TMPHLQ"
9493
test_info = dict(library="", state="present", force_dynamic=True, tmp_hlq="", persistent=dict(data_set_name="", backup=True))
9594
test_info['tmp_hlq'] = tmphlq
96-
ds = get_tmp_ds_name(3,2)
95+
ds = get_tmp_ds_name(3,2,True)
9796
hosts.all.shell(cmd=f"dtouch -tseq -V{volume} {ds} ")
9897
test_info['library'] = ds
9998
if test_info.get('volume') is not None:
@@ -129,7 +128,7 @@ def test_add_del_volume(ansible_zos_module, volumes_with_vvds):
129128
VolumeHandler = Volume_Handler(volumes_with_vvds)
130129
volume = VolumeHandler.get_available_vol()
131130
test_info = dict(library="", volume="", state="present", force_dynamic=True)
132-
ds = get_tmp_ds_name(1,1)
131+
ds = get_tmp_ds_name(1,1,True)
133132
hosts.all.shell(cmd=f"dtouch -tseq -V{volume} {ds} ")
134133
test_info['library'] = ds
135134
if test_info.get('volume') is not None:
@@ -148,6 +147,7 @@ def test_add_del_volume(ansible_zos_module, volumes_with_vvds):
148147
hosts.all.shell(cmd=cmdStr)
149148
test_info['persistent']['data_set_name'] = prstds
150149
results = hosts.all.zos_apf(**test_info)
150+
151151
for result in results.contacted.values():
152152
assert result.get("rc") == 0
153153
test_info['state'] = 'absent'
@@ -192,7 +192,7 @@ def test_add_del_volume_persist(ansible_zos_module, volumes_with_vvds):
192192
VolumeHandler = Volume_Handler(volumes_with_vvds)
193193
volume = VolumeHandler.get_available_vol()
194194
test_info = dict(library="", volume="", persistent=dict(data_set_name="", marker="/* {mark} BLOCK */"), state="present", force_dynamic=True)
195-
ds = get_tmp_ds_name(1,1)
195+
ds = get_tmp_ds_name(1,1,True)
196196
hosts.all.shell(cmd=f"dtouch -tseq -V{volume} {ds} ")
197197
test_info['library'] = ds
198198
if test_info.get('volume') is not None:
@@ -251,20 +251,19 @@ def test_batch_add_del(ansible_zos_module, volumes_with_vvds):
251251
persistent=dict(data_set_name="", marker="/* {mark} BLOCK */"), state="present", force_dynamic=True
252252
)
253253
for item in test_info['batch']:
254-
ds = get_tmp_ds_name(1,1)
254+
ds = get_tmp_ds_name(1,1,True)
255255
hosts.all.shell(cmd=f"dtouch -tseq -V{volume} {ds} ")
256256
item['library'] = ds
257257
cmdStr = "dls -l " + ds + " | awk '{print $5}' "
258258
results = hosts.all.shell(cmd=cmdStr)
259259
for result in results.contacted.values():
260260
vol = result.get("stdout")
261261
item['volume'] = vol
262-
prstds = get_tmp_ds_name(5,5)
262+
prstds = get_tmp_ds_name(5,5,True)
263263
cmdStr = "dtouch -tseq {0}".format(prstds)
264264
hosts.all.shell(cmd=cmdStr)
265265
test_info['persistent']['data_set_name'] = prstds
266266
results = hosts.all.zos_apf(**test_info)
267-
pprint(vars(results))
268267
for result in results.contacted.values():
269268
assert result.get("rc") == 0
270269
add_exptd = add_batch_expected.format(test_info['batch'][0]['library'], test_info['batch'][0]['volume'],
@@ -279,7 +278,6 @@ def test_batch_add_del(ansible_zos_module, volumes_with_vvds):
279278
assert actual == add_exptd
280279
test_info['state'] = 'absent'
281280
results = hosts.all.zos_apf(**test_info)
282-
pprint(vars(results))
283281
for result in results.contacted.values():
284282
assert result.get("rc") == 0
285283
del_exptd = del_expected.replace(" ", "")
@@ -315,7 +313,7 @@ def test_operation_list_with_filter(ansible_zos_module, volumes_with_vvds):
315313
volume = VolumeHandler.get_available_vol()
316314
test_info = dict(library="", state="present", force_dynamic=True)
317315
test_info['state'] = 'present'
318-
ds = get_tmp_ds_name(3,2)
316+
ds = get_tmp_ds_name(3,2,True)
319317
hosts.all.shell(cmd=f"dtouch -tseq -V{volume} {ds} ")
320318
test_info['library'] = ds
321319
if test_info.get('volume') is not None:
@@ -357,7 +355,7 @@ def test_add_already_present(ansible_zos_module, volumes_with_vvds):
357355
volume = VolumeHandler.get_available_vol()
358356
test_info = dict(library="", state="present", force_dynamic=True)
359357
test_info['state'] = 'present'
360-
ds = get_tmp_ds_name(3,2)
358+
ds = get_tmp_ds_name(3,2,True)
361359
hosts.all.shell(cmd=f"dtouch -tseq -V{volume} {ds} ")
362360
test_info['library'] = ds
363361
if test_info.get('volume') is not None:
@@ -394,7 +392,7 @@ def test_del_not_present(ansible_zos_module, volumes_with_vvds):
394392
VolumeHandler = Volume_Handler(volumes_with_vvds)
395393
volume = VolumeHandler.get_available_vol()
396394
test_info = dict(library="", state="present", force_dynamic=True)
397-
ds = get_tmp_ds_name(1,1)
395+
ds = get_tmp_ds_name(1,1,True)
398396
hosts.all.shell(cmd=f"dtouch -tseq -V{volume} {ds} ")
399397
test_info['library'] = ds
400398
if test_info.get('volume') is not None:
@@ -438,7 +436,7 @@ def test_add_with_wrong_volume(ansible_zos_module, volumes_with_vvds):
438436
volume = VolumeHandler.get_available_vol()
439437
test_info = dict(library="", volume="", state="present", force_dynamic=True)
440438
test_info['state'] = 'present'
441-
ds = get_tmp_ds_name(3,2)
439+
ds = get_tmp_ds_name(3,2,True)
442440
hosts.all.shell(cmd=f"dtouch -tseq -V{volume} {ds} ")
443441
test_info['library'] = ds
444442
if test_info.get('volume') is not None:
@@ -472,7 +470,7 @@ def test_persist_invalid_ds_format(ansible_zos_module, volumes_with_vvds):
472470
volume = VolumeHandler.get_available_vol()
473471
test_info = dict(library="", persistent=dict(data_set_name="", marker="/* {mark} BLOCK */"), state="present", force_dynamic=True)
474472
test_info['state'] = 'present'
475-
ds = get_tmp_ds_name(3,2)
473+
ds = get_tmp_ds_name(3,2,True)
476474
hosts.all.shell(cmd=f"dtouch -tseq -V{volume} {ds} ")
477475
test_info['library'] = ds
478476
if test_info.get('volume') is not None:
@@ -506,7 +504,7 @@ def test_persist_invalid_marker(ansible_zos_module, volumes_with_vvds):
506504
volume = VolumeHandler.get_available_vol()
507505
test_info = dict(library="", persistent=dict(data_set_name="", marker="/* {mark} BLOCK */"), state="present", force_dynamic=True)
508506
test_info['state'] = 'present'
509-
ds = get_tmp_ds_name(3,2)
507+
ds = get_tmp_ds_name(3,2,True)
510508
hosts.all.shell(cmd=f"dtouch -tseq -V{volume} {ds} ")
511509
test_info['library'] = ds
512510
if test_info.get('volume') is not None:
@@ -539,7 +537,7 @@ def test_persist_invalid_marker_len(ansible_zos_module, volumes_with_vvds):
539537
volume = VolumeHandler.get_available_vol()
540538
test_info = dict(library="", persistent=dict(data_set_name="", marker="/* {mark} BLOCK */"), state="present", force_dynamic=True)
541539
test_info['state'] = 'present'
542-
ds = get_tmp_ds_name(3,2)
540+
ds = get_tmp_ds_name(3,2,True)
543541
hosts.all.shell(cmd=f"dtouch -tseq -V{volume} {ds} ")
544542
test_info['library'] = ds
545543
if test_info.get('volume') is not None:

tests/helpers/dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,4 @@ def get_random_qs(size=7):
7575
random_char = random_q[random.choice(range(0, size))]
7676
random_q = random_q.replace(random_char, random.choice(special_chars))
7777
count += 1
78-
return random_q
78+
return random_q

tests/helpers/volumes.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def get_volumes(ansible_zos_module, path):
7777
# is a instance of a class to manage the use.
7878
hosts = ansible_zos_module
7979
list_volumes = []
80+
all_volumes_list = []
8081
storage_online = []
8182
flag = False
8283
iteration = 5
@@ -88,16 +89,19 @@ def get_volumes(ansible_zos_module, path):
8889
time.sleep(1)
8990
if all_volumes is not None:
9091
for volume in all_volumes.contacted.values():
91-
all_volumes = volume.get('content')
92-
flag = True if len(all_volumes) > 5 else False
92+
temp = volume.get('content')
93+
if temp is not None:
94+
all_volumes_list += temp
95+
flag = True if len(all_volumes_list) > 5 else False
9396
iteration -= 1
9497
# Check if the volume is of storage and is active on prefer but also online as a correct option
95-
for info in all_volumes:
98+
for info in all_volumes_list:
9699
if "ACTIVATED" in info or "-D U," in info or "UNIT" in info:
97100
continue
98101
vol_w_info = info.split()
99-
if vol_w_info[2] == 'O' and vol_w_info[4] == "STRG/RSDNT":
100-
storage_online.append(vol_w_info[3])
102+
if len(vol_w_info)>3:
103+
if vol_w_info[2] == 'O' and vol_w_info[4] == "STRG/RSDNT":
104+
storage_online.append(vol_w_info[3])
101105
# Insert a volumes for the class ls_Volumes to give flag of in_use and correct manage
102106
for vol in storage_online:
103107
list_volumes.append(vol)

0 commit comments

Comments
 (0)