Skip to content

Commit b7a1b1b

Browse files
authored
[Bugfix] [zos_copy] Copy from file to member when dest is just PDS/E name (#1570)
* Compute member name for implicit copies * Add test for implicit member copy * Update module doc * Add changelog fragment
1 parent 43c7272 commit b7a1b1b

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
bugfixes:
2+
- zos_copy - a regression in version 1.4.0 made the module stop automatically
3+
computing member names when copying a single file into a PDS/E. Fix now
4+
lets a user copy a single file into a PDS/E without adding a member in the
5+
dest option.
6+
(https://github.com/ansible-collections/ibm_zos_core/pull/1570).

plugins/modules/zos_copy.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@
109109
attributes will be computed. If I(executable=true),C(dest) will have an Undefined (U) record
110110
format with a record length of 0, block size of 32760, and the remaining attributes will be
111111
computed.
112+
- If C(src) is a file and C(dest) a partitioned data set, C(dest) does not need to include
113+
a member in its value, the module can automatically compute the resulting member name from
114+
C(src).
112115
- When C(dest) is a data set, precedence rules apply. If C(dest_data_set)
113116
is set, this will take precedence over an existing data set. If C(dest)
114117
is an empty data set, the empty data set will be written with the
@@ -3429,6 +3432,13 @@ def run_module(module, arg_def):
34293432
dest_has_asa_chars = True
34303433

34313434
if dest_ds_type in data_set.DataSet.MVS_PARTITIONED:
3435+
# Checking if we need to copy a member when the user requests it implicitly.
3436+
# src is a file and dest was just the PDS/E dataset name.
3437+
if not copy_member and src_ds_type == "USS" and os.path.isfile(src):
3438+
copy_member = True
3439+
dest_member = data_set.DataSet.get_member_name_from_file(os.path.basename(src))
3440+
dest = f"{dest_name}({dest_member})"
3441+
34323442
# Checking if the members that would be created from the directory files
34333443
# are already present on the system.
34343444
if copy_member:

tests/functional/modules/test_zos_copy_func.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2595,6 +2595,46 @@ def test_copy_file_to_non_existing_member(ansible_zos_module, src):
25952595
hosts.all.zos_data_set(name=data_set, state="absent")
25962596

25972597

2598+
# Test related to issue #774: https://github.com/ansible-collections/ibm_zos_core/issues/774.
2599+
@pytest.mark.uss
2600+
@pytest.mark.pdse
2601+
def test_copy_file_to_non_existing_member_implicit(ansible_zos_module):
2602+
hosts = ansible_zos_module
2603+
dest_data_set = get_tmp_ds_name()
2604+
dest_member = f"{dest_data_set}(PROFILE)"
2605+
2606+
try:
2607+
hosts.all.zos_data_set(
2608+
name=dest_data_set,
2609+
type="pdse",
2610+
space_primary=5,
2611+
space_type="m",
2612+
record_format="fba",
2613+
record_length=80,
2614+
replace=True
2615+
)
2616+
2617+
copy_result = hosts.all.zos_copy(
2618+
src="/etc/profile",
2619+
dest=dest_data_set,
2620+
remote_src=True
2621+
)
2622+
2623+
verify_copy = hosts.all.shell(
2624+
cmd="cat \"//'{0}'\" > /dev/null 2>/dev/null".format(dest_member),
2625+
executable=SHELL_EXECUTABLE,
2626+
)
2627+
2628+
for cp_res in copy_result.contacted.values():
2629+
assert cp_res.get("msg") is None
2630+
assert cp_res.get("changed") is True
2631+
assert cp_res.get("dest") == dest_member
2632+
for v_cp in verify_copy.contacted.values():
2633+
assert v_cp.get("rc") == 0
2634+
finally:
2635+
hosts.all.zos_data_set(name=dest_data_set, state="absent")
2636+
2637+
25982638
@pytest.mark.uss
25992639
@pytest.mark.pdse
26002640
@pytest.mark.parametrize("src", [

0 commit comments

Comments
 (0)