Skip to content

Commit 0d40615

Browse files
Merge remote-tracking branch 'origin/dev' into bugfix/1776/zos_mvs_raw-stdout-replaced-by-stderr
2 parents 0a671c7 + a8b78d7 commit 0d40615

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
bugfixes:
2+
- zos_fetch - Some relative paths were not accepted as a parameter e.g. C(files/fetched_file).
3+
Change now allows the user to use different types of relative paths as a parameter.
4+
(https://github.com/ansible-collections/ibm_zos_core/pull/1769).

plugins/action/zos_fetch.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,19 @@ def run(self, tmp=None, task_vars=None):
157157
src = self._connection._shell.join_path(src)
158158
src = self._remote_expand_user(src)
159159

160+
# To manage relative paths we verify and add the current directory
161+
# Required to be cast to str
162+
if not (dest.startswith("/")):
163+
if dest.startswith("~"):
164+
dest = os.path.expanduser(dest)
165+
dest = os.path.realpath(dest)
166+
dest = os.path.join(os.getcwd(), dest)
167+
dest = f"{dest}/" if os.path.isdir(dest) else str(dest)
160168
# ********************************************************** #
161169
# Execute module on remote host #
162170
# ********************************************************** #
163171
new_module_args = self._task.args.copy()
172+
new_module_args.update(dest=dest)
164173
encoding_to = None
165174
if encoding:
166175
encoding_to = encoding.get("to", None)

tests/functional/modules/test_zos_fetch_func.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,3 +939,47 @@ def test_fetch_gdg(ansible_zos_module):
939939

940940
if os.path.exists(dest_path):
941941
shutil.rmtree(dest_path)
942+
943+
944+
@pytest.mark.parametrize("relative_path", ["tmp/", ".", "../tmp/", "~/tmp/"])
945+
def test_fetch_uss_file_relative_path_not_present_on_local_machine(ansible_zos_module, relative_path):
946+
hosts = ansible_zos_module
947+
current_working_directory = os.getcwd()
948+
src = "/etc/profile"
949+
950+
# If the test suite is running on root to avoid an issue we check the current directory
951+
# Also, user can run the tests from ibm_zos_core or tests folder, so this will give us the absolute path of our working dir.
952+
if relative_path == "../tmp/":
953+
aux = os.path.basename(os.path.normpath(current_working_directory))
954+
relative_path = "../" + aux + "/tmp/"
955+
956+
params = {
957+
"src": src,
958+
"dest": relative_path,
959+
"flat":True
960+
}
961+
962+
# Case to create the dest path to verify allow running on any path.
963+
# There are some relative paths for which we need to change our cwd to be able to validate that
964+
# the path returned by the module is correct.
965+
if relative_path == "~/tmp/":
966+
dest = os.path.expanduser("~")
967+
dest = dest + "/tmp"
968+
elif relative_path == ".":
969+
dest = current_working_directory + "/profile"
970+
else:
971+
dest = current_working_directory + "/tmp"
972+
973+
try:
974+
results = hosts.all.zos_fetch(**params)
975+
976+
for result in results.contacted.values():
977+
assert result.get("changed") is True
978+
assert result.get("data_set_type") == "USS"
979+
assert result.get("module_stderr") is None
980+
assert dest == result.get("dest")
981+
dest = result.get("dest")
982+
983+
finally:
984+
if os.path.exists(dest):
985+
os.remove(dest)

0 commit comments

Comments
 (0)