Skip to content

Commit 9b8c279

Browse files
authored
Bugfix: Fixes zos_copy and zos_fetch deprecation msg for using _play_context.verbosity (#814)
* Add new test case for verbosity check Signed-off-by: ddimatos <dimatos@gmail.com> * Update zos_copy tests to support display.verbosity and nested encoding Signed-off-by: ddimatos <dimatos@gmail.com> Conflicts: tests/functional/modules/test_zos_copy_func.py Changes to be committed: deleted: tests/functional/modules/test_module_display.py modified: tests/functional/modules/test_zos_copy_func.py * Update test framewor to provide support for adhoc module calls Signed-off-by: ddimatos <dimatos@gmail.com> * Update zos_fetch plugin to use the display.verbosity Signed-off-by: ddimatos <dimatos@gmail.com> * Lint correction Signed-off-by: ddimatos <dimatos@gmail.com> * Update test with verbosity Signed-off-by: ddimatos <dimatos@gmail.com> Conflicts: tests/functional/modules/test_zos_copy_func.py Changes to be committed: modified: tests/functional/modules/test_zos_copy_func.py * Change from shell to raw module usage Signed-off-by: ddimatos <dimatos@gmail.com> Conflicts: tests/functional/modules/test_zos_copy_func.py Changes to be committed: modified: tests/functional/modules/test_zos_copy_func.py * changelog fragment Signed-off-by: ddimatos <dimatos@gmail.com> * Changelog fragment change Signed-off-by: ddimatos <dimatos@gmail.com> --------- Signed-off-by: ddimatos <dimatos@gmail.com>
1 parent a732337 commit 9b8c279

File tree

6 files changed

+71
-9
lines changed

6 files changed

+71
-9
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bugfixes:
2+
- zos_copy - Reported a warning about the use of _play_context.verbosity.This
3+
change corrects the module action to prevent the warning message.
4+
(https://github.com/ansible-collections/ibm_zos_core/pull/814).
5+
- zos_fetch - Reported a warning about the use of _play_context.verbosity.This
6+
change corrects the module action to prevent the warning message.
7+
(https://github.com/ansible-collections/ibm_zos_core/pull/814).

plugins/action/zos_copy.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,10 @@ def _copy_to_remote(self, src, is_dir=False, ignore_stderr=False):
258258
display.vvv(u"ibm_zos_copy return code: {0}".format(returncode), host=self._play_context.remote_addr)
259259
display.vvv(u"ibm_zos_copy stdout: {0}".format(stdout), host=self._play_context.remote_addr)
260260
display.vvv(u"ibm_zos_copy stderr: {0}".format(stderr), host=self._play_context.remote_addr)
261-
display.vvv(u"play context verbosity: {0}".format(self._play_context.verbosity), host=self._play_context.remote_addr)
262261

263-
err = _detect_sftp_errors(stderr)
262+
ansible_verbosity = None
263+
ansible_verbosity = display.verbosity
264+
display.vvv(u"play context verbosity: {0}".format(ansible_verbosity), host=self._play_context.remote_addr)
264265

265266
# ************************************************************************* #
266267
# When plugin shh connection member _build_command(..) detects verbosity #
@@ -275,7 +276,9 @@ def _copy_to_remote(self, src, is_dir=False, ignore_stderr=False):
275276
# the verbosity is returned as 'stderr'. #
276277
# ************************************************************************* #
277278

278-
if self._play_context.verbosity > 3:
279+
err = _detect_sftp_errors(stderr)
280+
281+
if ansible_verbosity > 3:
279282
ignore_stderr = True
280283

281284
if returncode != 0 or (err and not ignore_stderr):

plugins/action/zos_fetch.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,10 @@ def _transfer_remote_content(
343343
display.vvv(u"ibm_zos_fetch return code: {0}".format(returncode), host=self._play_context.remote_addr)
344344
display.vvv(u"ibm_zos_fetch stdout: {0}".format(stdout), host=self._play_context.remote_addr)
345345
display.vvv(u"ibm_zos_fetch stderr: {0}".format(stderr), host=self._play_context.remote_addr)
346-
display.vvv(u"play context verbosity: {0}".format(self._play_context.verbosity), host=self._play_context.remote_addr)
347346

348-
err = _detect_sftp_errors(stderr)
347+
ansible_verbosity = None
348+
ansible_verbosity = display.verbosity
349+
display.vvv(u"play context verbosity: {0}".format(ansible_verbosity), host=self._play_context.remote_addr)
349350

350351
# ************************************************************************* #
351352
# When plugin shh connection member _build_command(..) detects verbosity #
@@ -360,7 +361,9 @@ def _transfer_remote_content(
360361
# the verbosity is returned as 'stderr'. #
361362
# ************************************************************************* #
362363

363-
if self._play_context.verbosity > 3:
364+
err = _detect_sftp_errors(stderr)
365+
366+
if ansible_verbosity > 3:
364367
ignore_stderr = True
365368

366369
if re.findall(r"Permission denied", err):

tests/conftest.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ def z_python_interpreter(request):
3838
helper = ZTestHelper.from_yaml_file(path)
3939
interpreter_str = helper.build_interpreter_string()
4040
inventory = helper.get_inventory_info()
41-
yield (interpreter_str, inventory)
41+
python_path = helper.get_python_path()
42+
yield (interpreter_str, inventory, python_path)
4243

4344

4445
def clean_logs(adhoc):
@@ -62,12 +63,18 @@ def clean_logs(adhoc):
6263
def ansible_zos_module(request, z_python_interpreter):
6364
""" Initialize pytest-ansible plugin with values from
6465
our YAML config and inject interpreter path into inventory. """
65-
interpreter, inventory = z_python_interpreter
66+
interpreter, inventory, python_path = z_python_interpreter
67+
6668
# next two lines perform similar action to ansible_adhoc fixture
6769
plugin = request.config.pluginmanager.getplugin("ansible")
6870
adhoc = plugin.initialize(request.config, request, **inventory)
69-
# * Inject our environment
71+
72+
# Inject our environment
7073
hosts = adhoc["options"]["inventory_manager"]._inventory.hosts
74+
75+
# Courtesy, pass along the python_path for some test cases need this information
76+
adhoc["options"]["ansible_python_path"] = python_path
77+
7178
for host in hosts.values():
7279
host.vars["ansible_python_interpreter"] = interpreter
7380
# host.vars["ansible_connection"] = "zos_ssh"

tests/functional/modules/test_zos_copy_func.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import re
2020
import tempfile
2121
from tempfile import mkstemp
22+
import subprocess
2223

2324
__metaclass__ = type
2425

@@ -2841,3 +2842,40 @@ def test_copy_uss_file_to_existing_sequential_data_set_twice_with_tmphlq_option(
28412842
assert v_cp.get("rc") == 0
28422843
finally:
28432844
hosts.all.zos_data_set(name=dest, state="absent")
2845+
2846+
2847+
@pytest.mark.parametrize("options", [
2848+
dict(src="/etc/profile", dest="/tmp/zos_copy_test_profile",
2849+
force=True, is_remote=False, verbosity="-vvvvv", verbosity_level=5),
2850+
dict(src="/etc/profile", dest="/mp/zos_copy_test_profile", force=True,
2851+
is_remote=False, verbosity="-vvvv", verbosity_level=4),
2852+
dict(src="/etc/profile", dest="/tmp/zos_copy_test_profile",
2853+
force=True, is_remote=False, verbosity="", verbosity_level=0),
2854+
])
2855+
def test_display_verbosity_in_zos_copy_plugin(ansible_zos_module, options):
2856+
"""Test the display verbosity, ensure it matches the verbosity_level.
2857+
This test requires access to verbosity and pytest-ansbile provides no
2858+
reasonable handle for this so for now subprocess is used. This test
2859+
results in no actual copy happening, the interest is in the verbosity"""
2860+
2861+
try:
2862+
hosts = ansible_zos_module
2863+
user = hosts["options"]["user"]
2864+
# Optionally hosts["options"]["inventory_manager"].list_hosts()[0]
2865+
node = hosts["options"]["inventory"].rstrip(',')
2866+
python_path = hosts["options"]["ansible_python_path"]
2867+
2868+
# This is an adhoc command, because there was no
2869+
cmd = "ansible all -i " + str(node) + ", -u " + user + " -m ibm.ibm_zos_core.zos_copy -a \"src=" + options["src"] + " dest=" + options["dest"] + " is_remote=" + str(
2870+
options["is_remote"]) + " encoding={{enc}} \" -e '{\"enc\":{\"from\": \"ISO8859-1\", \"to\": \"IBM-1047\"}}' -e \"ansible_python_interpreter=" + python_path + "\" " + options["verbosity"] + ""
2871+
2872+
result = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout
2873+
output = result.read().decode()
2874+
2875+
if options["verbosity_level"] != 0:
2876+
assert ("play context verbosity: "+ str(options["verbosity_level"])+"" in output)
2877+
else:
2878+
assert ("play context verbosity:" not in output)
2879+
2880+
finally:
2881+
hosts.all.file(path=options["dest"], state="absent")

tests/helpers/ztest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,7 @@ def build_interpreter_string(self):
6464
interpreter_string += "export {0}={1} ; ".format(key, value)
6565
interpreter_string += self._python_path
6666
return interpreter_string
67+
68+
def get_python_path(self):
69+
""" Returns python path """
70+
return self._python_path

0 commit comments

Comments
 (0)