25
25
username = 'Administrator@vsphere.local' ,
26
26
password = 'Esxi@123$%' ,
27
27
hostname = False ,
28
+ port = 443 ,
28
29
validate_certs = False ,
30
+ proxy_host = None ,
31
+ proxy_port = None ,
29
32
),
30
33
"Hostname parameter is missing. Please specify this parameter in task or"
31
34
" export environment variable like 'export VMWARE_HOST=ESXI_HOSTNAME'"
35
38
username = False ,
36
39
password = 'Esxi@123$%' ,
37
40
hostname = 'esxi1' ,
41
+ port = 443 ,
38
42
validate_certs = False ,
39
43
),
40
44
"Username parameter is missing. Please specify this parameter in task or"
45
49
username = 'Administrator@vsphere.local' ,
46
50
password = False ,
47
51
hostname = 'esxi1' ,
52
+ port = 443 ,
48
53
validate_certs = False ,
49
54
),
50
55
"Password parameter is missing. Please specify this parameter in task or"
64
69
username = 'Administrator@vsphere.local' ,
65
70
password = 'Esxi@123$%' ,
66
71
hostname = 'esxi1' ,
72
+ port = 443 ,
67
73
proxy_host = 'myproxyserver.com' ,
68
74
proxy_port = 80 ,
69
75
validate_certs = False ,
@@ -126,20 +132,6 @@ def test_required_params(request, params, msg, fake_ansible_module):
126
132
# TODO: assert msg in fake_ansible_module.fail_json.call_args[1]['msg']
127
133
128
134
129
- def test_validate_certs (monkeypatch , fake_ansible_module ):
130
- """ Test if SSL is required or not"""
131
- fake_ansible_module .params = test_data [3 ][0 ]
132
-
133
- monkeypatch .setattr (vmware_module_utils , 'ssl' , mock .Mock ())
134
- del vmware_module_utils .ssl .SSLContext
135
- with pytest .raises (FailJsonException ):
136
- vmware_module_utils .PyVmomi (fake_ansible_module )
137
- msg = 'pyVim does not support changing verification mode with python < 2.7.9.' \
138
- ' Either update python or use validate_certs=false.'
139
- fake_ansible_module .fail_json .assert_called_once ()
140
- assert msg == fake_ansible_module .fail_json .call_args [1 ]['msg' ]
141
-
142
-
143
135
def test_vmdk_disk_path_split (monkeypatch , fake_ansible_module ):
144
136
""" Test vmdk_disk_path_split function"""
145
137
fake_ansible_module .params = test_data [0 ][0 ]
@@ -162,75 +154,6 @@ def test_vmdk_disk_path_split_negative(monkeypatch, fake_ansible_module):
162
154
assert 'Bad path' in fake_ansible_module .fail_json .call_args [1 ]['msg' ]
163
155
164
156
165
- @pytest .mark .skipif (sys .version_info < (2 , 7 ), reason = "requires python2.7 and greater" )
166
- def test_connect_to_api_validate_certs (monkeypatch , fake_ansible_module ):
167
- monkeypatch .setattr (vmware_module_utils , 'connect' , mock .Mock ())
168
-
169
- def MockSSLContext (proto ):
170
- ssl_context .proto = proto
171
- return ssl_context
172
-
173
- # New Python with SSLContext + validate_certs=True
174
- vmware_module_utils .connect .reset_mock ()
175
- ssl_context = mock .Mock ()
176
- monkeypatch .setattr (vmware_module_utils .ssl , 'SSLContext' , MockSSLContext )
177
- fake_ansible_module .params ['validate_certs' ] = True
178
- vmware_module_utils .connect_to_api (fake_ansible_module )
179
- assert ssl_context .proto == ssl .PROTOCOL_SSLv23
180
- assert ssl_context .verify_mode == ssl .CERT_REQUIRED
181
- assert ssl_context .check_hostname is True
182
- vmware_module_utils .connect .SmartConnect .assert_called_once_with (
183
- host = 'esxi1' ,
184
- port = 443 ,
185
- pwd = 'Esxi@123$%' ,
186
- user = 'Administrator@vsphere.local' ,
187
- sslContext = ssl_context )
188
-
189
- # New Python with SSLContext + validate_certs=False
190
- vmware_module_utils .connect .reset_mock ()
191
- ssl_context = mock .Mock ()
192
- monkeypatch .setattr (vmware_module_utils .ssl , 'SSLContext' , MockSSLContext )
193
- fake_ansible_module .params ['validate_certs' ] = False
194
- vmware_module_utils .connect_to_api (fake_ansible_module )
195
- assert ssl_context .proto == ssl .PROTOCOL_SSLv23
196
- assert ssl_context .verify_mode == ssl .CERT_NONE
197
- assert ssl_context .check_hostname is False
198
- vmware_module_utils .connect .SmartConnect .assert_called_once_with (
199
- host = 'esxi1' ,
200
- port = 443 ,
201
- pwd = 'Esxi@123$%' ,
202
- user = 'Administrator@vsphere.local' ,
203
- sslContext = ssl_context )
204
-
205
- # Old Python with no SSLContext + validate_certs=True
206
- vmware_module_utils .connect .reset_mock ()
207
- ssl_context = mock .Mock ()
208
- ssl_context .proto = None
209
- monkeypatch .delattr (vmware_module_utils .ssl , 'SSLContext' )
210
- fake_ansible_module .params ['validate_certs' ] = True
211
- with pytest .raises (FailJsonException ):
212
- vmware_module_utils .connect_to_api (fake_ansible_module )
213
- assert ssl_context .proto is None
214
- fake_ansible_module .fail_json .assert_called_once_with (msg = (
215
- 'pyVim does not support changing verification mode with python '
216
- '< 2.7.9. Either update python or use validate_certs=false.' ))
217
- assert not vmware_module_utils .connect .SmartConnect .called
218
-
219
- # Old Python with no SSLContext + validate_certs=False
220
- vmware_module_utils .connect .reset_mock ()
221
- ssl_context = mock .Mock ()
222
- ssl_context .proto = None
223
- monkeypatch .delattr (vmware_module_utils .ssl , 'SSLContext' , raising = False )
224
- fake_ansible_module .params ['validate_certs' ] = False
225
- vmware_module_utils .connect_to_api (fake_ansible_module )
226
- assert ssl_context .proto is None
227
- vmware_module_utils .connect .SmartConnect .assert_called_once_with (
228
- host = 'esxi1' ,
229
- port = 443 ,
230
- pwd = 'Esxi@123$%' ,
231
- user = 'Administrator@vsphere.local' )
232
-
233
-
234
157
@pytest .mark .parametrize ("test_options, test_current_options, test_truthy_strings_as_bool" , [
235
158
({"data" : True }, [], True ),
236
159
({"data" : 1 }, [], True ),
0 commit comments