20
20
import pytest
21
21
import string
22
22
import random
23
+ import yaml
24
+ import subprocess
23
25
import tempfile
24
26
25
27
from hashlib import sha256
26
28
from ansible .utils .hashing import checksum
27
29
from datetime import datetime
30
+ from shellescape import quote
28
31
29
32
from shellescape import quote
30
33
87
90
00000003A record
88
91
"""
89
92
93
+ INVENTORY = """all:
94
+ hosts:
95
+ zvm:
96
+ ansible_host: {0}
97
+ ansible_ssh_private_key_file: {1}
98
+ ansible_user: {2}
99
+ ansible_python_interpreter: {3}"""
100
+
101
+ BECOME_USER = """- hosts: zvm
102
+ collections :
103
+ - ibm.ibm_zos_core
104
+ gather_facts: False
105
+ ignore_errors: True
106
+ vars:
107
+ ZOAU: "{0}"
108
+ PYZ: "{1}"
109
+ ansible_become_user: {2}
110
+ ansible_become_method: {3}
111
+ ansible_su_prompt_l10n: {4}
112
+ environment:
113
+ _BPXK_AUTOCVT: "ALL"
114
+ ZOAU_HOME: "{0}"
115
+ PYTHONPATH: "{0}/lib/{5}"
116
+ LIBPATH: "{0}/lib:{1}/lib:/lib:/usr/lib:."
117
+ 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:"
118
+ _CEE_RUNOPTS: "FILETAG(AUTOCVT,AUTOTAG) POSIX(ON)"
119
+ _TAG_REDIR_ERR: "txt"
120
+ _TAG_REDIR_IN: "txt"
121
+ _TAG_REDIR_OUT: "txt"
122
+ LANG: "C"
123
+ PYTHONSTDINENCODING: "cp1047"
124
+ tasks:
125
+ - name: Fetch PDSE member while escalating privileges.
126
+ ibm.ibm_zos_core.zos_fetch:
127
+ src: {6}
128
+ dest: /tmp/
129
+ flat: true
130
+ become: true
131
+ """
132
+
90
133
91
134
def extract_member_name (data_set ):
92
135
start = data_set .find ("(" )
@@ -985,3 +1028,63 @@ def test_fetch_uss_file_relative_path_not_present_on_local_machine(ansible_zos_m
985
1028
finally :
986
1029
if os .path .exists (dest ):
987
1030
os .remove (dest )
1031
+
1032
+
1033
+ def test_extra_parameters (get_config_for_become , get_config , capsys ):
1034
+ with capsys .disabled ():
1035
+ adm_user , method , promp , ansible_us = get_config_for_become
1036
+ promp = promp + f" { adm_user } "
1037
+
1038
+ ds_name = get_tmp_ds_name ()
1039
+ ds_name = ds_name + "(MEMBER)"
1040
+
1041
+ path = get_config
1042
+ with open (path , 'r' ) as file :
1043
+ enviroment = yaml .safe_load (file )
1044
+
1045
+ ssh_key = enviroment ["ssh_key" ]
1046
+ hosts = enviroment ["host" ].upper ()
1047
+ user = enviroment ["user" ].upper ()
1048
+ python_path = enviroment ["python_path" ]
1049
+ cut_python_path = python_path [:python_path .find ('/bin' )].strip ()
1050
+ zoau = enviroment ["environment" ]["ZOAU_ROOT" ]
1051
+ python_version = cut_python_path .split ('/' )[2 ]
1052
+
1053
+ try :
1054
+ playbook = "playbook.yml"
1055
+ inventory = "inventory.yml"
1056
+
1057
+ os .system ("echo {0} > {1}" .format (quote (BECOME_USER .format (
1058
+ zoau ,
1059
+ cut_python_path ,
1060
+ adm_user ,
1061
+ method ,
1062
+ promp ,
1063
+ python_version ,
1064
+ ds_name ,
1065
+ )), playbook ))
1066
+
1067
+ os .system ("echo {0} > {1}" .format (quote (INVENTORY .format (
1068
+ hosts ,
1069
+ ssh_key ,
1070
+ user ,
1071
+ python_path
1072
+ )), inventory ))
1073
+
1074
+ command = "ansible-playbook -i -vvv {0} {1}" .format (
1075
+ inventory ,
1076
+ playbook
1077
+ )
1078
+
1079
+ result = subprocess .run (
1080
+ command ,
1081
+ capture_output = True ,
1082
+ shell = True ,
1083
+ timeout = 120 ,
1084
+ encoding = 'utf-8'
1085
+ )
1086
+
1087
+ assert result .returncode == 0
1088
+ finally :
1089
+ os .remove ("inventory.yml" )
1090
+ os .remove ("playbook.yml" )
0 commit comments