Skip to content

Commit cc108c7

Browse files
Fix lineinfile (#1545)
* Fix lineinfile * Fix typos * Add lineinfile solution * Updated force fail test cases * modified quotes * Updated test --------- Co-authored-by: Fernando Flores <[email protected]>
1 parent 46c4f28 commit cc108c7

File tree

1 file changed

+40
-41
lines changed

1 file changed

+40
-41
lines changed

tests/functional/modules/test_zos_lineinfile_func.py

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
{
3232
char dsname[ strlen(argv[1]) + 4];
3333
sprintf(dsname, \\\"//'%s'\\\", argv[1]);
34-
file* member;
34+
FILE* member;
3535
member = fopen(dsname, \\\"rb,type=record\\\");
3636
sleep(300);
3737
fclose(member);
@@ -267,7 +267,7 @@ def test_uss_line_replace(ansible_zos_module):
267267
results = hosts.all.zos_lineinfile(**params)
268268
for result in results.contacted.values():
269269
assert result.get("changed") == 1
270-
results = hosts.all.shell(cmd=f"cat {params["path"]}")
270+
results = hosts.all.shell(cmd="cat {0}".format(params["path"]))
271271
for result in results.contacted.values():
272272
assert result.get("stdout") == EXPECTED_REPLACE
273273
finally:
@@ -290,7 +290,7 @@ def test_uss_line_insertafter_regex(ansible_zos_module):
290290
results = hosts.all.zos_lineinfile(**params)
291291
for result in results.contacted.values():
292292
assert result.get("changed") == 1
293-
results = hosts.all.shell(cmd=f"cat {params["path"]}")
293+
results = hosts.all.shell(cmd="cat {0}".format(params["path"]))
294294
for result in results.contacted.values():
295295
assert result.get("stdout") == EXPECTED_INSERTAFTER_REGEX
296296
finally:
@@ -313,7 +313,7 @@ def test_uss_line_insertbefore_regex(ansible_zos_module):
313313
results = hosts.all.zos_lineinfile(**params)
314314
for result in results.contacted.values():
315315
assert result.get("changed") == 1
316-
results = hosts.all.shell(cmd=f"cat {params["path"]}")
316+
results = hosts.all.shell(cmd="cat {0}".format(params["path"]))
317317
for result in results.contacted.values():
318318
assert result.get("stdout") == EXPECTED_INSERTBEFORE_REGEX
319319
finally:
@@ -336,7 +336,7 @@ def test_uss_line_insertafter_eof(ansible_zos_module):
336336
results = hosts.all.zos_lineinfile(**params)
337337
for result in results.contacted.values():
338338
assert result.get("changed") == 1
339-
results = hosts.all.shell(cmd=f"cat {params["path"]}")
339+
results = hosts.all.shell(cmd="cat {0}".format(params["path"]))
340340
for result in results.contacted.values():
341341
assert result.get("stdout") == EXPECTED_INSERTAFTER_EOF
342342
finally:
@@ -359,7 +359,7 @@ def test_uss_line_insertbefore_bof(ansible_zos_module):
359359
results = hosts.all.zos_lineinfile(**params)
360360
for result in results.contacted.values():
361361
assert result.get("changed") == 1
362-
results = hosts.all.shell(cmd=f"cat {params["path"]}")
362+
results = hosts.all.shell(cmd="cat {0}".format(params["path"]))
363363
for result in results.contacted.values():
364364
assert result.get("stdout") == EXPECTED_INSERTBEFORE_BOF
365365
finally:
@@ -383,7 +383,7 @@ def test_uss_line_replace_match_insertafter_ignore(ansible_zos_module):
383383
results = hosts.all.zos_lineinfile(**params)
384384
for result in results.contacted.values():
385385
assert result.get("changed") == 1
386-
results = hosts.all.shell(cmd=f"cat {params["path"]}")
386+
results = hosts.all.shell(cmd="cat {0}".format(params["path"]))
387387
for result in results.contacted.values():
388388
assert result.get("stdout") == EXPECTED_REPLACE_INSERTAFTER_IGNORE
389389
finally:
@@ -407,7 +407,7 @@ def test_uss_line_replace_match_insertbefore_ignore(ansible_zos_module):
407407
results = hosts.all.zos_lineinfile(**params)
408408
for result in results.contacted.values():
409409
assert result.get("changed") == 1
410-
results = hosts.all.shell(cmd=f"cat {params["path"]}")
410+
results = hosts.all.shell(cmd="cat {0}".format(params["path"]))
411411
for result in results.contacted.values():
412412
assert result.get("stdout") == EXPECTED_REPLACE_INSERTBEFORE_IGNORE
413413
finally:
@@ -431,7 +431,7 @@ def test_uss_line_replace_nomatch_insertafter_match(ansible_zos_module):
431431
results = hosts.all.zos_lineinfile(**params)
432432
for result in results.contacted.values():
433433
assert result.get("changed") == 1
434-
results = hosts.all.shell(cmd=f"cat {params["path"]}")
434+
results = hosts.all.shell(cmd="cat {0}".format(params["path"]))
435435
for result in results.contacted.values():
436436
assert result.get("stdout") == EXPECTED_REPLACE_NOMATCH_INSERTAFTER
437437
finally:
@@ -455,7 +455,7 @@ def test_uss_line_replace_nomatch_insertbefore_match(ansible_zos_module):
455455
results = hosts.all.zos_lineinfile(**params)
456456
for result in results.contacted.values():
457457
assert result.get("changed") == 1
458-
results = hosts.all.shell(cmd=f"cat {params["path"]}")
458+
results = hosts.all.shell(cmd="cat {0}".format(params["path"]))
459459
for result in results.contacted.values():
460460
assert result.get("stdout") == EXPECTED_REPLACE_NOMATCH_INSERTBEFORE
461461
finally:
@@ -479,7 +479,7 @@ def test_uss_line_replace_nomatch_insertafter_nomatch(ansible_zos_module):
479479
results = hosts.all.zos_lineinfile(**params)
480480
for result in results.contacted.values():
481481
assert result.get("changed") == 1
482-
results = hosts.all.shell(cmd=f"cat {params["path"]}")
482+
results = hosts.all.shell(cmd="cat {0}".format(params["path"]))
483483
for result in results.contacted.values():
484484
assert result.get("stdout") == EXPECTED_REPLACE_NOMATCH_INSERTAFTER_NOMATCH
485485
finally:
@@ -503,7 +503,7 @@ def test_uss_line_replace_nomatch_insertbefore_nomatch(ansible_zos_module):
503503
results = hosts.all.zos_lineinfile(**params)
504504
for result in results.contacted.values():
505505
assert result.get("changed") == 1
506-
results = hosts.all.shell(cmd=f"cat {params["path"]}")
506+
results = hosts.all.shell(cmd="cat {0}".format(params["path"]))
507507
for result in results.contacted.values():
508508
assert result.get("stdout") == EXPECTED_REPLACE_NOMATCH_INSERTBEFORE_NOMATCH
509509
finally:
@@ -527,7 +527,7 @@ def test_uss_line_absent(ansible_zos_module):
527527
for result in results.contacted.values():
528528
print(result)
529529
assert result.get("changed") == 1
530-
results = hosts.all.shell(cmd=f"cat {params["path"]}")
530+
results = hosts.all.shell(cmd="cat {0}".format(params["path"]))
531531
for result in results.contacted.values():
532532
assert result.get("stdout") == EXPECTED_ABSENT
533533
finally:
@@ -551,7 +551,7 @@ def test_uss_line_replace_quoted_escaped(ansible_zos_module):
551551
results = hosts.all.zos_lineinfile(**params)
552552
for result in results.contacted.values():
553553
assert result.get("changed") == 1
554-
results = hosts.all.shell(cmd=f"cat {params["path"]}")
554+
results = hosts.all.shell(cmd="cat {0}".format(params["path"]))
555555
for result in results.contacted.values():
556556
assert result.get("stdout") == EXPECTED_QUOTED
557557
finally:
@@ -575,7 +575,7 @@ def test_uss_line_replace_quoted_not_escaped(ansible_zos_module):
575575
results = hosts.all.zos_lineinfile(**params)
576576
for result in results.contacted.values():
577577
assert result.get("changed") == 1
578-
results = hosts.all.shell(cmd=f"cat {params["path"]}")
578+
results = hosts.all.shell(cmd="cat {0}".format(params["path"]))
579579
for result in results.contacted.values():
580580
assert result.get("stdout") == EXPECTED_QUOTED
581581
finally:
@@ -597,12 +597,12 @@ def test_uss_line_does_not_insert_repeated(ansible_zos_module):
597597
results = hosts.all.zos_lineinfile(**params)
598598
for result in results.contacted.values():
599599
assert result.get("changed") == 1
600-
results = hosts.all.shell(cmd=f"cat {params["path"]}")
600+
results = hosts.all.shell(cmd="cat {0}".format(params["path"]))
601601
for result in results.contacted.values():
602602
assert result.get("stdout") == TEST_CONTENT
603603
# Run lineinfle module with same params again, ensure duplicate entry is not made into file
604604
hosts.all.zos_lineinfile(**params)
605-
results = hosts.all.shell(cmd=f"grep -c 'ZOAU_ROOT=/usr/lpp/zoautil/v10' {params["path"]} ")
605+
results = hosts.all.shell(cmd="grep -c 'ZOAU_ROOT=/usr/lpp/zoautil/v10' {0} ".format(params["path"]))
606606
for result in results.contacted.values():
607607
assert result.get("stdout") == '1'
608608
finally:
@@ -635,7 +635,7 @@ def test_ds_line_insertafter_regex(ansible_zos_module, dstype):
635635
results = hosts.all.zos_lineinfile(**params)
636636
for result in results.contacted.values():
637637
assert result.get("changed") == 1
638-
results = hosts.all.shell(cmd=f"cat \"//'{params["path"]}'\" ")
638+
results = hosts.all.shell(cmd="cat \"//'{0}'\" ".format(params["path"]))
639639
for result in results.contacted.values():
640640
assert result.get("stdout") == EXPECTED_INSERTAFTER_REGEX
641641
finally:
@@ -661,7 +661,7 @@ def test_ds_line_insertbefore_regex(ansible_zos_module, dstype):
661661
results = hosts.all.zos_lineinfile(**params)
662662
for result in results.contacted.values():
663663
assert result.get("changed") == 1
664-
results = hosts.all.shell(cmd=f"cat \"//'{params["path"]}'\" ")
664+
results = hosts.all.shell(cmd="cat \"//'{0}'\" ".format(params["path"]))
665665
for result in results.contacted.values():
666666
assert result.get("stdout") == EXPECTED_INSERTBEFORE_REGEX
667667
finally:
@@ -687,7 +687,7 @@ def test_ds_line_insertafter_eof(ansible_zos_module, dstype):
687687
results = hosts.all.zos_lineinfile(**params)
688688
for result in results.contacted.values():
689689
assert result.get("changed") == 1
690-
results = hosts.all.shell(cmd=f"cat \"//'{params["path"]}'\" ")
690+
results = hosts.all.shell(cmd="cat \"//'{0}'\" ".format(params["path"]))
691691
for result in results.contacted.values():
692692
assert result.get("stdout") == EXPECTED_INSERTAFTER_EOF
693693
finally:
@@ -712,7 +712,7 @@ def test_ds_line_insertbefore_bof(ansible_zos_module, dstype):
712712
results = hosts.all.zos_lineinfile(**params)
713713
for result in results.contacted.values():
714714
assert result.get("changed") == 1
715-
results = hosts.all.shell(cmd=f"cat \"//'{params["path"]}'\" ")
715+
results = hosts.all.shell(cmd="cat \"//'{0}'\" ".format(params["path"]))
716716
for result in results.contacted.values():
717717
assert result.get("stdout") == EXPECTED_INSERTBEFORE_BOF
718718
finally:
@@ -739,7 +739,7 @@ def test_ds_line_replace_match_insertafter_ignore(ansible_zos_module, dstype):
739739
results = hosts.all.zos_lineinfile(**params)
740740
for result in results.contacted.values():
741741
assert result.get("changed") == 1
742-
results = hosts.all.shell(cmd=f"cat \"//'{params["path"]}'\" ")
742+
results = hosts.all.shell(cmd="cat \"//'{0}'\" ".format(params["path"]))
743743
for result in results.contacted.values():
744744
assert result.get("stdout") == EXPECTED_REPLACE_INSERTAFTER_IGNORE
745745
finally:
@@ -766,7 +766,7 @@ def test_ds_line_replace_match_insertbefore_ignore(ansible_zos_module, dstype):
766766
results = hosts.all.zos_lineinfile(**params)
767767
for result in results.contacted.values():
768768
assert result.get("changed") == 1
769-
results = hosts.all.shell(cmd=f"cat \"//'{params["path"]}'\" ")
769+
results = hosts.all.shell(cmd="cat \"//'{0}'\" ".format(params["path"]))
770770
for result in results.contacted.values():
771771
assert result.get("stdout") == EXPECTED_REPLACE_INSERTBEFORE_IGNORE
772772
finally:
@@ -978,7 +978,7 @@ def test_ds_line_absent(ansible_zos_module, dstype):
978978
results = hosts.all.zos_lineinfile(**params)
979979
for result in results.contacted.values():
980980
assert result.get("changed") == 1
981-
results = hosts.all.shell(cmd=f"cat \"//'{params["path"]}'\" ")
981+
results = hosts.all.shell(cmd="cat \"//'{0}'\" ".format(params["path"]))
982982
for result in results.contacted.values():
983983
assert result.get("stdout") == EXPECTED_ABSENT
984984
finally:
@@ -1086,18 +1086,18 @@ def test_ds_line_force(ansible_zos_module, dstype):
10861086
)
10871087
# write memeber to verify cases
10881088
if ds_type in ["pds", "pdse"]:
1089-
cmd_str = f"cp -CM {quote(temp_file)} \"//'{params["path"]}'\""
1089+
cmd_str = "cp -CM {0} \"//'{1}'\"".format(quote(temp_file), params["path"])
10901090
else:
1091-
cmd_str = f"cp {quote(temp_file)} \"//'{params["path"]}'\" "
1091+
cmd_str = "cp {0} \"//'{1}'\" ".format(quote(temp_file), params["path"])
10921092
hosts.all.shell(cmd=cmd_str)
1093-
results = hosts.all.shell(cmd=f"cat \"//'{params["path"]}'\" | wc -l ")
1093+
results = hosts.all.shell(cmd="cat \"//'{0}'\" | wc -l ".format(params["path"]))
10941094
for result in results.contacted.values():
10951095
assert int(result.get("stdout")) != 0
10961096
# copy/compile c program and copy jcl to hold data set lock for n seconds in background(&)
10971097
hosts.all.shell(cmd=f"echo \"{c_pgm}\" > /tmp/disp_shr/pdse-lock.c")
1098-
hosts.all.shell(cmd=f"echo \"{call_c_jcl.format(
1099-
default_data_set_name,member_1
1100-
)}\" > /tmp/disp_shr/call_c_pgm.jcl")
1098+
hosts.all.shell(cmd="echo \"{0}\" > /tmp/disp_shr/call_c_pgm.jcl".format(call_c_jcl.format(
1099+
default_data_set_name,member_1))
1100+
)
11011101
hosts.all.shell(cmd="xlc -o pdse-lock pdse-lock.c", chdir="/tmp/disp_shr/")
11021102
hosts.all.shell(cmd="submit call_c_pgm.jcl", chdir="/tmp/disp_shr/")
11031103
time.sleep(5)
@@ -1128,7 +1128,7 @@ def test_ds_line_force_fail(ansible_zos_module, dstype):
11281128
"regexp":"ZOAU_ROOT=",
11291129
"line":"ZOAU_ROOT=/mvsutil-develop_dsed",
11301130
"state":"present",
1131-
"force":"False"
1131+
"force":False
11321132
}
11331133
member_1, member_2 = "MEM1", "MEM2"
11341134
temp_file = f"/tmp/{member_2}"
@@ -1151,17 +1151,16 @@ def test_ds_line_force_fail(ansible_zos_module, dstype):
11511151
"state": "present", "replace": True, },
11521152
]
11531153
)
1154-
cmd_str = f"cp -CM {quote(temp_file)} \"//'{params["path"]}'\""
1154+
cmd_str = "cp -CM {0} \"//'{1}'\"".format(quote(temp_file), params["path"])
11551155
hosts.all.shell(cmd=cmd_str)
1156-
results = hosts.all.shell(cmd=f"cat \"//'{params["path"]}'\" | wc -l ")
1156+
results = hosts.all.shell(cmd="cat \"//'{0}'\" | wc -l ".format(params["path"]))
11571157
for result in results.contacted.values():
11581158
assert int(result.get("stdout")) != 0
11591159
# copy/compile c program and copy jcl to hold data set lock for n seconds in background(&)
1160-
hosts.all.file(path="/tmp/disp_shr", state='directory')
1161-
hosts.all.shell(cmd=f"echo \"{c_pgm}\" > /tmp/disp_shr/pdse-lock.c")
1162-
hosts.all.shell(cmd=f"echo \"{call_c_jcl.format(
1163-
default_data_set_name,
1164-
member_1)}\" > /tmp/disp_shr/call_c_pgm.jcl"
1160+
results = hosts.all.file(path="/tmp/disp_shr", state='directory')
1161+
hosts.all.shell(cmd=f"echo \"{c_pgm}\" > /tmp/disp_shr/pdse-lock.c")
1162+
hosts.all.shell(cmd="echo \"{0}\" > /tmp/disp_shr/call_c_pgm.jcl".format(call_c_jcl.format(
1163+
default_data_set_name,member_1))
11651164
)
11661165
hosts.all.shell(cmd="xlc -o pdse-lock pdse-lock.c", chdir="/tmp/disp_shr/")
11671166
hosts.all.shell(cmd="submit call_c_pgm.jcl", chdir="/tmp/disp_shr/")
@@ -1197,14 +1196,14 @@ def test_ds_line_does_not_insert_repeated(ansible_zos_module, dstype):
11971196
results = hosts.all.zos_lineinfile(**params)
11981197
for result in results.contacted.values():
11991198
assert result.get("changed") == 1
1200-
results = hosts.all.shell(cmd=f"cat \"//'{params["path"]}'\" ")
1199+
results = hosts.all.shell(cmd="cat \"//'{0}'\" ".format(params["path"]))
12011200
for result in results.contacted.values():
12021201
assert result.get("stdout") == TEST_CONTENT
12031202
# Run lineinfle module with same params again, ensure duplicate entry is not made into file
12041203
hosts.all.zos_lineinfile(**params)
12051204
results = hosts.all.shell(
1206-
cmd=f"dgrep -c 'ZOAU_ROOT=/usr/lpp/zoautil/v10' '{params["path"]}' "
1207-
)
1205+
cmd="dgrep -c 'ZOAU_ROOT=/usr/lpp/zoautil/v10' '{0}' ".format(params["path"])
1206+
)
12081207
response = params["path"] + " " + "1"
12091208
for result in results.contacted.values():
12101209
assert result.get("stdout") == response

0 commit comments

Comments
 (0)