TEST - Use proxy for tar chart sources

Change-Id: I6f90d056fa46f596b1fb248b6c596c58b6513d64
This commit is contained in:
Sphicas, Phil (ps3910) 2019-09-17 01:24:02 -07:00
parent fd45cff385
commit 42656bbc17
2 changed files with 17 additions and 9 deletions

View File

@ -122,6 +122,7 @@ class Armada(object):
location = chart_source.get('location') location = chart_source.get('location')
ct_type = chart_source.get('type') ct_type = chart_source.get('type')
subpath = chart_source.get('subpath', '.') subpath = chart_source.get('subpath', '.')
proxy_server = chart_source.get('proxy_server')
if ct_type == 'local': if ct_type == 'local':
chart['source_dir'] = (location, subpath) chart['source_dir'] = (location, subpath)
@ -129,15 +130,19 @@ class Armada(object):
source_key = (ct_type, location) source_key = (ct_type, location)
if source_key not in self.chart_cache: if source_key not in self.chart_cache:
LOG.info('Downloading tarball from: %s', location) logstr = 'Downloading tarball from: {}'.format(location)
if proxy_server:
logstr += ' proxy: {}'.format(proxy_server)
LOG.info(logstr)
if not CONF.certs: if not CONF.certs:
LOG.warn( LOG.warn(
'Disabling server validation certs to extract charts') 'Disabling server validation certs to extract charts')
tarball_dir = source.get_tarball(location, verify=False) tarball_dir = source.get_tarball(location, verify=False,
proxy_server=proxy_server)
else: else:
tarball_dir = source.get_tarball( tarball_dir = source.get_tarball(
location, verify=CONF.certs) location, verify=CONF.certs, proxy_server=proxy_server)
self.chart_cache[source_key] = tarball_dir self.chart_cache[source_key] = tarball_dir
chart['source_dir'] = (self.chart_cache.get(source_key), subpath) chart['source_dir'] = (self.chart_cache.get(source_key), subpath)
elif ct_type == 'git': elif ct_type == 'git':
@ -146,7 +151,6 @@ class Armada(object):
if source_key not in self.chart_cache: if source_key not in self.chart_cache:
auth_method = chart_source.get('auth_method') auth_method = chart_source.get('auth_method')
proxy_server = chart_source.get('proxy_server')
logstr = 'Cloning repo: {} from branch: {}'.format( logstr = 'Cloning repo: {} from branch: {}'.format(
location, reference) location, reference)

View File

@ -113,21 +113,25 @@ def git_clone(repo_url, ref='master', proxy_server=None, auth_method=None):
return temp_dir return temp_dir
def get_tarball(tarball_url, verify=False): def get_tarball(tarball_url, verify=False, proxy_server=None):
tarball_path = download_tarball(tarball_url, verify=verify) tarball_path = download_tarball(tarball_url, verify=verify,
proxy_server=proxy_server)
return extract_tarball(tarball_path) return extract_tarball(tarball_path)
def download_tarball(tarball_url, verify=False): def download_tarball(tarball_url, verify=False, proxy_server=None):
''' '''
Downloads a tarball to /tmp and returns the path Downloads a tarball to /tmp and returns the path
''' '''
try: try:
if not verify: if not verify:
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
kwargs = {}
if proxy_server:
kwargs['proxies'] = { 'http': proxy_server, 'https': proxy_server,
'ftp': proxy_server }
tarball_filename = tempfile.mkstemp(prefix='armada')[1] tarball_filename = tempfile.mkstemp(prefix='armada')[1]
response = requests.get(tarball_url, verify=verify) response = requests.get(tarball_url, verify=verify, **kwargs)
with open(tarball_filename, 'wb') as f: with open(tarball_filename, 'wb') as f:
f.write(response.content) f.write(response.content)