From 31baab85f9ca6520b076641e83a059f3098970dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Wed, 19 Jun 2019 09:12:14 -0400 Subject: [PATCH] ansible-test: vcenter through a HTTP proxy Give the ansible-test user the ability to target a lab behind a HTTP proxy. --- test/runner/lib/cloud/vcenter.py | 7 ++++++- test/runner/lib/http.py | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/test/runner/lib/cloud/vcenter.py b/test/runner/lib/cloud/vcenter.py index b25c65e4357..8b6adb11f9f 100644 --- a/test/runner/lib/cloud/vcenter.py +++ b/test/runner/lib/cloud/vcenter.py @@ -63,6 +63,7 @@ class VcenterProvider(CloudProvider): self.endpoint = '' self.hostname = '' self.port = 443 + self.proxy = None def filter(self, targets, exclude): """Filter out the cloud tests when the necessary config and resources are not available. @@ -222,6 +223,10 @@ class VcenterProvider(CloudProvider): if parser.get('DEFAULT', 'vmware_validate_certs').lower() in ('no', 'false'): self.insecure = True + proxy_host = parser.get('DEFAULT', 'vmware_proxy_host') + proxy_port = int(parser.get('DEFAULT', 'vmware_proxy_port')) + if proxy_host and proxy_port: + self.proxy = 'http://%s:%d' % (proxy_host, proxy_port) self._wait_for_service() @@ -230,7 +235,7 @@ class VcenterProvider(CloudProvider): if self.args.explain: return - client = HttpClient(self.args, always=True, insecure=self.insecure) + client = HttpClient(self.args, always=True, insecure=self.insecure, proxy=self.proxy) endpoint = 'https://%s:%s' % (self.endpoint, self.port) for i in range(1, 30): diff --git a/test/runner/lib/http.py b/test/runner/lib/http.py index 64581871337..c0f2a1ebb7b 100644 --- a/test/runner/lib/http.py +++ b/test/runner/lib/http.py @@ -35,7 +35,7 @@ from lib.util_common import ( class HttpClient(object): """Make HTTP requests via curl.""" - def __init__(self, args, always=False, insecure=False): + def __init__(self, args, always=False, insecure=False, proxy=None): """ :type args: CommonConfig :type always: bool @@ -44,6 +44,7 @@ class HttpClient(object): self.args = args self.always = always self.insecure = insecure + self.proxy = proxy self.username = None self.password = None @@ -102,6 +103,9 @@ class HttpClient(object): if data is not None: cmd += ['-d', data] + if self.proxy: + cmd += ['-x', self.proxy] + cmd += [url] attempts = 0