Skip to content

Commit 30f6519

Browse files
rexeminddimatos
andauthored
[1.5.0-beta.1] [Bug] [zos_copy] Accented characters break is_empty (#634)
* Changed is_empty for sequential datasets * Added changelog fragment * Added test case for dataset with accented chars --------- Co-authored-by: ddimatos <[email protected]>
1 parent ded7a01 commit 30f6519

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bugfixes:
2+
- zos_copy - fixes a bug where if a destination has accented characters in
3+
its content, the module would fail when trying to determine if it is empty.
4+
(https://github.com/ansible-collections/ibm_zos_core/pull/634)

plugins/module_utils/data_set.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,9 @@ def is_empty(name, volume=None):
655655
if ds_type in DataSet.MVS_PARTITIONED:
656656
return DataSet._pds_empty(name)
657657
elif ds_type in DataSet.MVS_SEQ:
658-
return len(datasets.read(name, tail=10)) == 0
658+
module = AnsibleModuleHelper(argument_spec={})
659+
rc, stdout, stderr = module.run_command("head \"//'{0}'\"".format(name))
660+
return rc == 0 and len(stdout.strip()) == 0
659661
elif ds_type in DataSet.MVS_VSAM:
660662
return DataSet._vsam_empty(name)
661663

tests/functional/modules/test_zos_copy_func.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@
3232
DUMMY DATA ---- LINE 007 ------
3333
"""
3434

35+
DUMMY_DATA_SPECIAL_CHARS = """DUMMY DATA ---- LINE 001 ------
36+
DUMMY DATA ---- LINE ÁÁÁ------
37+
DUMMY DATA ---- LINE ÈÈÈ ------
38+
DUMMY DATA ---- LINE 004 ------
39+
DUMMY DATA ---- LINE 005 ------
40+
DUMMY DATA ---- LINE 006 ------
41+
DUMMY DATA ---- LINE 007 ------
42+
"""
43+
3544
VSAM_RECORDS = """00000001A record
3645
00000002A record
3746
00000003A record
@@ -1167,6 +1176,37 @@ def test_copy_ps_to_non_empty_ps(ansible_zos_module, force):
11671176
hosts.all.zos_data_set(name=dest, state="absent")
11681177

11691178

1179+
@pytest.mark.seq
1180+
@pytest.mark.parametrize("force", [False, True])
1181+
def test_copy_ps_to_non_empty_ps_with_special_chars(ansible_zos_module, force):
1182+
hosts = ansible_zos_module
1183+
src_ds = TEST_PS
1184+
dest = "USER.TEST.SEQ.FUNCTEST"
1185+
1186+
try:
1187+
hosts.all.zos_data_set(name=dest, type="seq", state="absent")
1188+
hosts.all.zos_copy(content=DUMMY_DATA_SPECIAL_CHARS, dest=dest)
1189+
1190+
copy_res = hosts.all.zos_copy(src=src_ds, dest=dest, remote_src=True, force=force)
1191+
verify_copy = hosts.all.shell(
1192+
cmd="cat \"//'{0}'\"".format(dest), executable=SHELL_EXECUTABLE
1193+
)
1194+
1195+
for result in copy_res.contacted.values():
1196+
if force:
1197+
assert result.get("msg") is None
1198+
assert result.get("changed") is True
1199+
assert result.get("dest") == dest
1200+
else:
1201+
assert result.get("msg") is not None
1202+
assert result.get("changed") is False
1203+
for result in verify_copy.contacted.values():
1204+
assert result.get("rc") == 0
1205+
assert result.get("stdout") != ""
1206+
finally:
1207+
hosts.all.zos_data_set(name=dest, state="absent")
1208+
1209+
11701210
@pytest.mark.seq
11711211
@pytest.mark.parametrize("backup", [None, "USER.TEST.SEQ.FUNCTEST.BACK"])
11721212
def test_backup_sequential_data_set(ansible_zos_module, backup):

0 commit comments

Comments
 (0)