|
16 | 16 | __metaclass__ = type
|
17 | 17 |
|
18 | 18 | import pytest
|
| 19 | +import yaml |
| 20 | +import os |
| 21 | +from shellescape import quote |
19 | 22 |
|
20 | 23 | from ansible_collections.ibm.ibm_zos_core.plugins.module_utils import (
|
21 | 24 | zoau_version_checker,
|
|
24 | 27 |
|
25 | 28 | __metaclass__ = type
|
26 | 29 |
|
| 30 | +PARALLEL_RUNNING = """- hosts : zvm |
| 31 | + collections : |
| 32 | + - ibm.ibm_zos_core |
| 33 | + gather_facts: False |
| 34 | + vars: |
| 35 | + ZOAU: "{0}" |
| 36 | + PYZ: "{1}" |
| 37 | + environment: |
| 38 | + _BPXK_AUTOCVT: "ON" |
| 39 | + ZOAU_HOME: "{0}" |
| 40 | + PYTHONPATH: "{0}/lib" |
| 41 | + LIBPATH: "{0}/lib:{1}/lib:/lib:/usr/lib:." |
| 42 | + PATH: "{0}/bin:/bin:/usr/lpp/rsusr/ported/bin:/var/bin:/usr/lpp/rsusr/ported/bin:/usr/lpp/java/java180/J8.0_64/bin:{1}/bin:" |
| 43 | + _CEE_RUNOPTS: "FILETAG(AUTOCVT,AUTOTAG) POSIX(ON)" |
| 44 | + _TAG_REDIR_ERR: "txt" |
| 45 | + _TAG_REDIR_IN: "txt" |
| 46 | + _TAG_REDIR_OUT: "txt" |
| 47 | + LANG: "C" |
| 48 | + tasks: |
| 49 | + - name: zos_operator |
| 50 | + zos_operator: |
| 51 | + cmd: 'd a,all' |
| 52 | + wait_time_s: 3 |
| 53 | + verbose: true |
| 54 | + register: output |
| 55 | +
|
| 56 | + - name: print output |
| 57 | + debug: |
| 58 | + var: output""" |
| 59 | + |
| 60 | +INVENTORY = """all: |
| 61 | + hosts: |
| 62 | + zvm: |
| 63 | + ansible_host: {0} |
| 64 | + ansible_ssh_private_key_file: {1} |
| 65 | + ansible_user: {2} |
| 66 | + ansible_python_interpreter: /allpython/3.9/usr/lpp/IBM/cyp/v3r9/pyz/bin/python3.9""" |
| 67 | + |
27 | 68 |
|
28 | 69 | def test_zos_operator_various_command(ansible_zos_module):
|
29 | 70 | test_data = [
|
@@ -141,3 +182,34 @@ def test_response_come_back_complete(ansible_zos_module):
|
141 | 182 | # HASP646 Only appears in the last line that before did not appears
|
142 | 183 | last_line = len(stdout)
|
143 | 184 | assert "HASP646" in stdout[last_line - 1]
|
| 185 | + |
| 186 | + |
| 187 | +def test_zos_operator_parallel_terminal(get_config): |
| 188 | + path = get_config |
| 189 | + with open(path, 'r') as file: |
| 190 | + enviroment = yaml.safe_load(file) |
| 191 | + ssh_key = enviroment["ssh_key"] |
| 192 | + hosts = enviroment["host"].upper() |
| 193 | + user = enviroment["user"].upper() |
| 194 | + python_path = enviroment["python_path"] |
| 195 | + cut_python_path = python_path[:python_path.find('/bin')].strip() |
| 196 | + zoau = enviroment["environment"]["ZOAU_ROOT"] |
| 197 | + try: |
| 198 | + playbook = "playbook.yml" |
| 199 | + inventory = "inventory.yml" |
| 200 | + os.system("echo {0} > {1}".format(quote(PARALLEL_RUNNING.format( |
| 201 | + zoau, |
| 202 | + cut_python_path, |
| 203 | + )), playbook)) |
| 204 | + os.system("echo {0} > {1}".format(quote(INVENTORY.format( |
| 205 | + hosts, |
| 206 | + ssh_key, |
| 207 | + user, |
| 208 | + )), inventory)) |
| 209 | + command = "(ansible-playbook -i {0} {1}) & (ansible-playbook -i {0} {1})".format(inventory, playbook) |
| 210 | + stdout = os.system(command) |
| 211 | + assert stdout == 0 |
| 212 | + finally: |
| 213 | + os.remove("inventory.yml") |
| 214 | + os.remove("playbook.yml") |
| 215 | + |
0 commit comments