Skip to content

Commit 410925d

Browse files
[v1.10.0][zos_lineinfile] Remove zos encode from zos lineinfile (#1179)
* Started removing encoding from tests * WIP * WIP * Added conversion * Removed zos_encode * Added changelog * Removed unused code
1 parent 066e76b commit 410925d

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trivial:
2+
- zos_lineinfile - Remove zos_encode dependency from zos_lineinfile test cases.
3+
(https://github.com/ansible-collections/ibm_zos_core/pull/1179).

tests/functional/modules/test_zos_lineinfile_func.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ def remove_ds_environment(ansible_zos_module, DS_NAME):
242242
# not supported data set types
243243
NS_DS_TYPE = ['ESDS', 'RRDS', 'LDS']
244244
# The encoding will be only use on a few test
245-
ENCODING = ['IBM-1047', 'ISO8859-1', 'UTF-8']
245+
ENCODING = [ 'ISO8859-1', 'UTF-8']
246246

247247
#########################
248248
# USS test cases
@@ -1005,20 +1005,19 @@ def test_ds_line_does_not_insert_repeated(ansible_zos_module, dstype):
10051005
def test_uss_encoding(ansible_zos_module, encoding):
10061006
hosts = ansible_zos_module
10071007
insert_data = "Insert this string"
1008-
params = dict(insertafter="SIMPLE", line=insert_data, state="present")
1008+
params = dict(insertafter="SIMPLE", line=insert_data, state="present", encoding={"from":"IBM-1047", "to":encoding})
10091009
params["encoding"] = encoding
10101010
full_path = TEST_FOLDER_LINEINFILE + inspect.stack()[0][3]
10111011
content = "SIMPLE LINE TO VERIFY"
10121012
try:
10131013
hosts.all.shell(cmd="mkdir -p {0}".format(TEST_FOLDER_LINEINFILE))
10141014
hosts.all.file(path=full_path, state="touch")
10151015
hosts.all.shell(cmd="echo \"{0}\" > {1}".format(content, full_path))
1016-
hosts.all.zos_encode(src=full_path, dest=full_path, from_encoding="IBM-1047", to_encoding=params["encoding"])
10171016
params["path"] = full_path
10181017
results = hosts.all.zos_lineinfile(**params)
10191018
for result in results.contacted.values():
10201019
assert result.get("changed") == 1
1021-
results = hosts.all.shell(cmd="cat {0}".format(params["path"]))
1020+
results = hosts.all.shell(cmd=f"iconv -f IBM-1047 -t {encoding} {full_path}")
10221021
for result in results.contacted.values():
10231022
assert result.get("stdout") == EXPECTED_ENCODING
10241023
finally:
@@ -1032,15 +1031,15 @@ def test_ds_encoding(ansible_zos_module, encoding, dstype):
10321031
hosts = ansible_zos_module
10331032
ds_type = dstype
10341033
insert_data = "Insert this string"
1035-
params = dict(insertafter="SIMPLE", line=insert_data, state="present")
1034+
params = dict(insertafter="SIMPLE", line=insert_data, state="present", encoding={"from":"IBM-1047", "to":encoding})
10361035
params["encoding"] = encoding
10371036
test_name = "DST13"
10381037
temp_file = "/tmp/{0}".format(test_name)
10391038
ds_name = test_name.upper() + "." + ds_type
10401039
content = "SIMPLE LINE TO VERIFY"
10411040
try:
10421041
hosts.all.shell(cmd="echo \"{0}\" > {1}".format(content, temp_file))
1043-
hosts.all.zos_encode(src=temp_file, dest=temp_file, from_encoding="IBM-1047", to_encoding=params["encoding"])
1042+
hosts.all.shell(cmd=f"iconv -f IBM-1047 -t {params['encoding']} temp_file > temp_file ")
10441043
hosts.all.zos_data_set(name=ds_name, type=ds_type)
10451044
if ds_type in ["PDS", "PDSE"]:
10461045
ds_full_name = ds_name + "(MEM)"
@@ -1055,9 +1054,10 @@ def test_ds_encoding(ansible_zos_module, encoding, dstype):
10551054
results = hosts.all.zos_lineinfile(**params)
10561055
for result in results.contacted.values():
10571056
assert result.get("changed") == 1
1058-
hosts.all.zos_encode(src=ds_full_name, dest=ds_full_name, from_encoding=params["encoding"], to_encoding="IBM-1047")
1059-
results = hosts.all.shell(cmd="cat \"//'{0}'\" ".format(params["path"]))
1057+
hosts.all.shell(cmd=f"iconv -f {encoding} -t IBM-1047 \"{ds_full_name}\" > \"{ds_full_name}\" ")
1058+
results = hosts.all.shell(cmd="cat \"//'{0}'\" ".format(ds_full_name))
10601059
for result in results.contacted.values():
1060+
10611061
assert result.get("stdout") == EXPECTED_ENCODING
10621062
finally:
10631063
remove_ds_environment(ansible_zos_module, ds_name)

0 commit comments

Comments
 (0)