Skip to content

Commit c9063a1

Browse files
authored
[Enhancement] [zos_stat] Extra return values for automation (#2137)
* Add new boolean fields * Update test cases with new boolean fields * Update module RST file * Add `exists` return field * Update tests with new field * Update zos_stat's RST file * Add changelog fragment
1 parent 40fa23f commit c9063a1

File tree

4 files changed

+199
-7
lines changed

4 files changed

+199
-7
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
minor_changes:
2+
- zos_stat - Adds new fields that describe the type of the resource
3+
that was queried. These new fields are `isfile`, `isdataset`,
4+
`isaggregate` and `isgdg`.
5+
(https://github.com/ansible-collections/ibm_zos_core/pull/2137)
6+
- zos_stat - Module now returns whether the resource queried exists
7+
on the managed node with the `exists` field inside `stat`.
8+
(https://github.com/ansible-collections/ibm_zos_core/pull/2137)

docs/source/modules/zos_stat.rst

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,61 @@ stat
264264
| **type**: str
265265
| **sample**: data_set
266266
267+
exists
268+
Whether name was found on the managed node.
269+
270+
| **returned**: success
271+
| **type**: bool
272+
| **sample**:
273+
274+
.. code-block:: json
275+
276+
true
277+
278+
isfile
279+
Whether name is a Unix System Services file.
280+
281+
| **returned**: success
282+
| **type**: bool
283+
| **sample**:
284+
285+
.. code-block:: json
286+
287+
true
288+
289+
isdataset
290+
Whether name is a data set.
291+
292+
| **returned**: success
293+
| **type**: bool
294+
| **sample**:
295+
296+
.. code-block:: json
297+
298+
true
299+
300+
isaggregate
301+
Whether name is an aggregate.
302+
303+
| **returned**: success
304+
| **type**: bool
305+
| **sample**:
306+
307+
.. code-block:: json
308+
309+
true
310+
311+
isgdg
312+
Whether name is a Generation Data Group.
313+
314+
| **returned**: success
315+
| **type**: bool
316+
| **sample**:
317+
318+
.. code-block:: json
319+
320+
true
321+
267322
attributes
268323
Dictionary containing all the stat data.
269324

plugins/modules/zos_stat.py

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,31 @@
242242
returned: success
243243
type: str
244244
sample: data_set
245+
exists:
246+
description: Whether name was found on the managed node.
247+
returned: success
248+
type: bool
249+
sample: true
250+
isfile:
251+
description: Whether name is a Unix System Services file.
252+
returned: success
253+
type: bool
254+
sample: true
255+
isdataset:
256+
description: Whether name is a data set.
257+
returned: success
258+
type: bool
259+
sample: true
260+
isaggregate:
261+
description: Whether name is an aggregate.
262+
returned: success
263+
type: bool
264+
sample: true
265+
isgdg:
266+
description: Whether name is a Generation Data Group.
267+
returned: success
268+
type: bool
269+
sample: true
245270
attributes:
246271
description: Dictionary containing all the stat data.
247272
returned: success
@@ -1131,6 +1156,10 @@ def query(self):
11311156
attributes = {
11321157
'name': self.name,
11331158
'resource_type': 'aggregate',
1159+
'isfile': False,
1160+
'isdataset': False,
1161+
'isaggregate': True,
1162+
'isgdg': False,
11341163
'attributes': {
11351164
'total_size': int(size_search.group(3)),
11361165
'free': int(size_search.group(1)),
@@ -1253,6 +1282,10 @@ def query(self):
12531282
attributes = {
12541283
'name': self.name,
12551284
'resource_type': 'file',
1285+
'isfile': True,
1286+
'isdataset': False,
1287+
'isaggregate': False,
1288+
'isgdg': False,
12561289
'attributes': {
12571290
'mode': "%04o" % stat.S_IMODE(mode),
12581291
'atime': raw_attributes.st_atime,
@@ -1456,6 +1489,10 @@ def query(self):
14561489
"""
14571490
data = {
14581491
'resource_type': 'data_set',
1492+
'isfile': False,
1493+
'isdataset': True,
1494+
'isaggregate': False,
1495+
'isgdg': False,
14591496
'name': self.alias if self.alias else self.name
14601497
}
14611498
return data
@@ -2181,7 +2218,11 @@ def query(self):
21812218
a GDG's attributes and current active generations."""
21822219
data = {
21832220
'resource_type': 'gdg',
2184-
'name': self.name
2221+
'name': self.name,
2222+
'isfile': False,
2223+
'isdataset': False,
2224+
'isaggregate': False,
2225+
'isgdg': True
21852226
}
21862227

21872228
attributes = {
@@ -2612,8 +2653,13 @@ def run_module():
26122653
result = {}
26132654

26142655
if not facts_handler.exists():
2615-
result['msg'] = f'{name} could not be found on the system.'
2616-
module.fail_json(**result)
2656+
result['stat'] = {
2657+
'name': name,
2658+
'resource_type': resource_type,
2659+
'exists': False
2660+
}
2661+
result['changed'] = False
2662+
module.exit_json(**result)
26172663

26182664
try:
26192665
data = facts_handler.query()
@@ -2632,6 +2678,7 @@ def run_module():
26322678

26332679
result['stat'] = fill_return_json(data)
26342680
result['changed'] = True
2681+
result['stat']['exists'] = True
26352682
if notes:
26362683
result['notes'] = notes
26372684

tests/functional/modules/test_zos_stat_func.py

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ def test_query_data_set_seq_no_volume(ansible_zos_module, volumes_on_systems):
195195
stat = result['stat']
196196
assert stat.get('resource_type') == 'data_set'
197197
assert stat.get('name') == name
198+
assert stat.get('exists') is True
199+
assert stat.get('isfile') is False
200+
assert stat.get('isdataset') is True
201+
assert stat.get('isaggregate') is False
202+
assert stat.get('isgdg') is False
198203
assert stat.get('attributes') is not None
199204

200205
assert stat['attributes'].get('dsorg') == 'ps'
@@ -262,6 +267,11 @@ def test_query_data_set_pds_no_volume(ansible_zos_module, volumes_on_systems):
262267
stat = result['stat']
263268
assert stat.get('resource_type') == 'data_set'
264269
assert stat.get('name') == name
270+
assert stat.get('exists') is True
271+
assert stat.get('isfile') is False
272+
assert stat.get('isdataset') is True
273+
assert stat.get('isaggregate') is False
274+
assert stat.get('isgdg') is False
265275
assert stat.get('attributes') is not None
266276

267277
assert stat['attributes'].get('dsorg') == 'po'
@@ -330,6 +340,11 @@ def test_query_data_set_pdse_no_volume(ansible_zos_module, volumes_on_systems):
330340
stat = result['stat']
331341
assert stat.get('resource_type') == 'data_set'
332342
assert stat.get('name') == name
343+
assert stat.get('exists') is True
344+
assert stat.get('isfile') is False
345+
assert stat.get('isdataset') is True
346+
assert stat.get('isaggregate') is False
347+
assert stat.get('isgdg') is False
333348
assert stat.get('attributes') is not None
334349

335350
assert stat['attributes'].get('dsorg') == 'po'
@@ -394,6 +409,11 @@ def test_query_data_set_vsam_ksds(ansible_zos_module):
394409
stat = result['stat']
395410
assert stat.get('resource_type') == 'data_set'
396411
assert stat.get('name') == name
412+
assert stat.get('exists') is True
413+
assert stat.get('isfile') is False
414+
assert stat.get('isdataset') is True
415+
assert stat.get('isaggregate') is False
416+
assert stat.get('isgdg') is False
397417
assert stat.get('attributes') is not None
398418

399419
assert stat['attributes'].get('dsorg') == 'vsam'
@@ -477,6 +497,11 @@ def test_query_data_set_gds(ansible_zos_module, volumes_on_systems):
477497
stat = result['stat']
478498
assert stat.get('resource_type') == 'data_set'
479499
assert name in stat.get('name')
500+
assert stat.get('exists') is True
501+
assert stat.get('isfile') is False
502+
assert stat.get('isdataset') is True
503+
assert stat.get('isaggregate') is False
504+
assert stat.get('isgdg') is False
480505
assert stat.get('attributes') is not None
481506

482507
assert stat['attributes'].get('dsorg') == 'ps'
@@ -548,6 +573,11 @@ def test_query_data_set_seq_with_correct_volume(ansible_zos_module, volumes_on_s
548573
stat = result['stat']
549574
assert stat.get('resource_type') == 'data_set'
550575
assert stat.get('name') == name
576+
assert stat.get('exists') is True
577+
assert stat.get('isfile') is False
578+
assert stat.get('isdataset') is True
579+
assert stat.get('isaggregate') is False
580+
assert stat.get('isgdg') is False
551581
assert stat.get('attributes') is not None
552582

553583
assert stat['attributes'].get('dsorg') == 'ps'
@@ -609,8 +639,9 @@ def test_query_data_set_seq_with_wrong_volume(ansible_zos_module, volumes_on_sys
609639

610640
for result in zos_stat_result.contacted.values():
611641
assert result.get('changed', False) is False
612-
assert result.get('failed') is True
613-
assert 'could not be found' in result.get('msg', '')
642+
assert result.get('failed', False) is False
643+
assert result.get('stat') is not None
644+
assert result.get('stat').get('exists') is False
614645
finally:
615646
hosts.all.shell(
616647
cmd=f'drm {escaped_name}'
@@ -659,6 +690,11 @@ def test_query_data_set_seq_multi_volume(ansible_zos_module, volumes_on_systems)
659690
stat = result['stat']
660691
assert stat.get('resource_type') == 'data_set'
661692
assert stat.get('name') == name
693+
assert stat.get('exists') is True
694+
assert stat.get('isfile') is False
695+
assert stat.get('isdataset') is True
696+
assert stat.get('isaggregate') is False
697+
assert stat.get('isgdg') is False
662698
assert stat.get('attributes') is not None
663699

664700
assert stat['attributes'].get('dsorg') == 'ps'
@@ -733,6 +769,11 @@ def test_query_data_set_seq_multi_volume_missing_one(ansible_zos_module, volumes
733769
stat = result['stat']
734770
assert stat.get('resource_type') == 'data_set'
735771
assert stat.get('name') == name
772+
assert stat.get('exists') is True
773+
assert stat.get('isfile') is False
774+
assert stat.get('isdataset') is True
775+
assert stat.get('isaggregate') is False
776+
assert stat.get('isgdg') is False
736777
assert stat.get('attributes') is not None
737778

738779
assert stat['attributes'].get('dsorg') == 'ps'
@@ -789,6 +830,11 @@ def test_query_gdg(ansible_zos_module):
789830
stat = result['stat']
790831
assert stat.get('resource_type') == 'gdg'
791832
assert stat.get('name') == name
833+
assert stat.get('exists') is True
834+
assert stat.get('isfile') is False
835+
assert stat.get('isdataset') is False
836+
assert stat.get('isaggregate') is False
837+
assert stat.get('isgdg') is True
792838
assert stat.get('attributes') is not None
793839

794840
assert stat['attributes'].get('limit') == limit
@@ -833,6 +879,11 @@ def test_query_aggregate(ansible_zos_module):
833879
stat = result['stat']
834880
assert stat.get('resource_type') == 'aggregate'
835881
assert stat.get('name') == aggregate_name
882+
assert stat.get('exists') is True
883+
assert stat.get('isfile') is False
884+
assert stat.get('isdataset') is False
885+
assert stat.get('isaggregate') is True
886+
assert stat.get('isgdg') is False
836887
assert stat.get('attributes') is not None
837888

838889
assert stat['attributes'].get('total_size') is not None
@@ -871,6 +922,11 @@ def test_query_file_no_symlink(ansible_zos_module):
871922
stat = result['stat']
872923
assert stat.get('resource_type') == 'file'
873924
assert stat.get('name') == test_file
925+
assert stat.get('exists') is True
926+
assert stat.get('isfile') is True
927+
assert stat.get('isdataset') is False
928+
assert stat.get('isaggregate') is False
929+
assert stat.get('isgdg') is False
874930
assert stat.get('attributes') is not None
875931

876932
for attr in EXPECTED_ATTRS['file']['flat']:
@@ -902,6 +958,11 @@ def test_query_file_no_checksum_no_mime(ansible_zos_module):
902958
stat = result['stat']
903959
assert stat.get('resource_type') == 'file'
904960
assert stat.get('name') == test_file
961+
assert stat.get('exists') is True
962+
assert stat.get('isfile') is True
963+
assert stat.get('isdataset') is False
964+
assert stat.get('isaggregate') is False
965+
assert stat.get('isgdg') is False
905966
assert stat.get('attributes') is not None
906967

907968
for attr in EXPECTED_ATTRS['file']['flat']:
@@ -949,6 +1010,11 @@ def test_query_file_symlink_follow_on(ansible_zos_module):
9491010
stat = result['stat']
9501011
assert stat.get('resource_type') == 'file'
9511012
assert stat.get('name') == test_file
1013+
assert stat.get('exists') is True
1014+
assert stat.get('isfile') is True
1015+
assert stat.get('isdataset') is False
1016+
assert stat.get('isaggregate') is False
1017+
assert stat.get('isgdg') is False
9521018
assert stat.get('attributes') is not None
9531019

9541020
# When following links, these two attributes should be None.
@@ -998,6 +1064,11 @@ def test_query_file_symlink_follow_off(ansible_zos_module):
9981064
stat = result['stat']
9991065
assert stat.get('resource_type') == 'file'
10001066
assert stat.get('name') == test_file
1067+
assert stat.get('exists') is True
1068+
assert stat.get('isfile') is True
1069+
assert stat.get('isdataset') is False
1070+
assert stat.get('isaggregate') is False
1071+
assert stat.get('isgdg') is False
10011072
assert stat.get('attributes') is not None
10021073

10031074
for attr in EXPECTED_ATTRS['file']['flat']:
@@ -1026,8 +1097,9 @@ def test_query_data_set_non_existent(ansible_zos_module, resource_type):
10261097

10271098
for result in zos_stat_result.contacted.values():
10281099
assert result.get('changed', False) is False
1029-
assert result.get('failed') is True
1030-
assert 'could not be found' in result.get('msg', '')
1100+
assert result.get('failed', False) is False
1101+
assert result.get('stat') is not None
1102+
assert result.get('stat').get('exists') is False
10311103

10321104

10331105
def test_query_data_set_tmp_hlq(ansible_zos_module, volumes_on_systems):
@@ -1062,6 +1134,11 @@ def test_query_data_set_tmp_hlq(ansible_zos_module, volumes_on_systems):
10621134
stat = result['stat']
10631135
assert stat.get('resource_type') == 'data_set'
10641136
assert stat.get('name') == name
1137+
assert stat.get('exists') is True
1138+
assert stat.get('isfile') is False
1139+
assert stat.get('isdataset') is True
1140+
assert stat.get('isaggregate') is False
1141+
assert stat.get('isgdg') is False
10651142
assert stat.get('attributes') is not None
10661143
finally:
10671144
hosts.all.shell(cmd=f'drm {name}')
@@ -1119,6 +1196,11 @@ def test_query_data_set_seq_with_alias(ansible_zos_module, volumes_on_systems):
11191196
stat = result['stat']
11201197
assert stat.get('resource_type') == 'data_set'
11211198
assert stat.get('name') == alias
1199+
assert stat.get('exists') is True
1200+
assert stat.get('isfile') is False
1201+
assert stat.get('isdataset') is True
1202+
assert stat.get('isaggregate') is False
1203+
assert stat.get('isgdg') is False
11221204
assert stat.get('attributes') is not None
11231205

11241206
assert stat['attributes'].get('dsorg') == 'ps'

0 commit comments

Comments
 (0)