Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enabler] [zos_copy] Remove zos_fetch call in loadlib test #1184

Merged
merged 11 commits into from
Jan 31, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
trivial:
- zos_copy - Remove zos_fetch dependency from zos_copy test cases.
(https://github.com/ansible-collections/ibm_zos_core/pull/1184).
34 changes: 28 additions & 6 deletions tests/functional/modules/test_zos_copy_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -3434,7 +3434,6 @@ def test_copy_pds_loadlib_to_pds_loadlib(ansible_zos_module, is_created):
@pytest.mark.aliases
@pytest.mark.parametrize("is_created", [False, True])
def test_copy_local_pds_loadlib_to_pds_loadlib(ansible_zos_module, is_created):

hosts = ansible_zos_module

cobol_src_pds = "USER.COBOL.SRC"
Expand All @@ -3444,6 +3443,7 @@ def test_copy_local_pds_loadlib_to_pds_loadlib(ansible_zos_module, is_created):
dest_lib = "USER.LOAD.DEST"
pgm_mem = "HELLO"
pgm2_mem = "HELLO2"
uss_location = "/tmp/loadlib"


try:
Expand Down Expand Up @@ -3487,11 +3487,32 @@ def test_copy_local_pds_loadlib_to_pds_loadlib(ansible_zos_module, is_created):
validate_loadlib_pgm(hosts, steplib=src_lib, pgm_name=pgm_mem, expected_output_str=COBOL_PRINT_STR)

# fetch loadlib into local
tmp_folder = tempfile.TemporaryDirectory(prefix="tmpfetch")
# fetch loadlib to local
fetch_result = hosts.all.zos_fetch(src=src_lib, dest=tmp_folder.name, is_binary=True)
for res in fetch_result.contacted.values():
source_path = res.get("dest")
# Copying the loadlib to USS.
hosts.all.file(name=uss_location, state='directory')
hosts.all.shell(
cmd=f"dcp -X -I \"{src_lib}\" {uss_location}",
executable=SHELL_EXECUTABLE
)

# Copying the remote loadlibs in USS to a local dir.
# This section ONLY handles ONE host, so if we ever use multiple hosts to
# test, we will need to update this code.
remote_user = hosts["options"]["user"]
# Removing a trailing comma because the framework saves the hosts list as a
# string instead of a list.
remote_host = hosts["options"]["inventory"].replace(",", "")

tmp_folder = tempfile.TemporaryDirectory(prefix="tmpfetch")
cmd = [
"sftp",
"-r",
f"{remote_user}@{remote_host}:{uss_location}",
f"{tmp_folder.name}"
]
with subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE) as sftp_proc:
result = sftp_proc.stdout.read()

source_path = os.path.join(tmp_folder.name, os.path.basename(uss_location))

if not is_created:
# ensure dest data sets absent for this variation of the test case.
Expand Down Expand Up @@ -3562,6 +3583,7 @@ def test_copy_local_pds_loadlib_to_pds_loadlib(ansible_zos_module, is_created):
hosts.all.zos_data_set(name=cobol_src_pds, state="absent")
hosts.all.zos_data_set(name=src_lib, state="absent")
hosts.all.zos_data_set(name=dest_lib, state="absent")
hosts.all.file(name=uss_location, state="absent")


@pytest.mark.pdse
Expand Down