Skip to content

Commit 417ef1b

Browse files
[BGYSC0822E][1308][Zos_Operator]Console_parallel (#1553)
* Probe solution * Add fragment * Fix comment * Update conftest.py Delete imports * Test all times * Avoid uses of users * Add fix * Update test_zos_operator_func.py
1 parent 7c94c05 commit 417ef1b

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trivial:
2+
- zos_operator - Validate the use of two terminals with a parallel call of zos_operator.
3+
(https://github.com/ansible-collections/ibm_zos_core/pull/1553).

tests/conftest.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,11 @@ def perform_imports(imports):
128128
newimp = [importlib.import_module(x) for x in imports]
129129
return newimp
130130

131-
yield (mocker, perform_imports)
131+
yield (mocker, perform_imports)
132+
133+
134+
@pytest.fixture(scope="function")
135+
def get_config(request):
136+
""" Call the pytest-ansible plugin to check volumes on the system and work properly a list by session."""
137+
path = request.config.getoption("--zinventory")
138+
yield path

tests/functional/modules/test_zos_operator_func.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
__metaclass__ = type
1717

1818
import pytest
19+
import yaml
20+
import os
21+
from shellescape import quote
1922

2023
from ansible_collections.ibm.ibm_zos_core.plugins.module_utils import (
2124
zoau_version_checker,
@@ -24,6 +27,44 @@
2427

2528
__metaclass__ = type
2629

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+
2768

2869
def test_zos_operator_various_command(ansible_zos_module):
2970
test_data = [
@@ -141,3 +182,34 @@ def test_response_come_back_complete(ansible_zos_module):
141182
# HASP646 Only appears in the last line that before did not appears
142183
last_line = len(stdout)
143184
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

Comments
 (0)