|
19 | 19 | import re |
20 | 20 | import tempfile |
21 | 21 | from tempfile import mkstemp |
| 22 | +import subprocess |
22 | 23 |
|
23 | 24 | __metaclass__ = type |
24 | 25 |
|
@@ -2841,3 +2842,40 @@ def test_copy_uss_file_to_existing_sequential_data_set_twice_with_tmphlq_option( |
2841 | 2842 | assert v_cp.get("rc") == 0 |
2842 | 2843 | finally: |
2843 | 2844 | 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") |
0 commit comments