Skip to content

Commit

Permalink
Merge c1fc377 into 1fd759b
Browse files Browse the repository at this point in the history
  • Loading branch information
dannf committed Mar 15, 2019
2 parents 1fd759b + c1fc377 commit bacc7cc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/charms/layer/jenkins/packages.py
Expand Up @@ -20,6 +20,16 @@
APT_SOURCE = "deb http://pkg.jenkins-ci.org/%s binary/"


def _juju_proxy_env():
proxy_env = {}
for protocol in ['FTP', 'HTTP', 'HTTPS', 'NO']:
envvar = '%s_PROXY' % (protocol)
juju_envvar = 'JUJU_CHARM_%s' % (envvar)
if juju_envvar in os.environ:
proxy_env[envvar.lower()] = os.environ[juju_envvar]
return proxy_env


class Packages(object):
"""Manage Jenkins package dependencies."""

Expand Down Expand Up @@ -85,7 +95,15 @@ def _install_from_remote_deb(self, url):
hookenv.log("Getting remote jenkins package: %s" % url)
tempdir = tempfile.mkdtemp()
target = os.path.join(tempdir, 'jenkins.deb')
subprocess.check_call(("wget", "-q", "-O", target, url))

proxy_env = _juju_proxy_env()
try:
subprocess.check_call(("wget", "-q", "-O", target, url),
env={**os.environ, **proxy_env})
except subprocess.CalledProcessError: # pragma: no cover
if len(proxy_env) == 0:
raise
subprocess.check_call(("wget", "-q", "-O", target, url))
self._install_local_deb(target)
shutil.rmtree(tempdir)

Expand Down
12 changes: 12 additions & 0 deletions unit_tests/test_packages.py
Expand Up @@ -112,6 +112,18 @@ def test_install_jenkins_remote(self):
finally:
hookenv.config()["release"] = orig_release

def test_install_jenkins_remote_with_proxy(self):
"""
If the 'release' config is set to a remote URL, then Jenkins will be
installed from the deb files pointed by that url.
"""
env_backup = os.environ.copy()
try:
os.environ['JUJU_CHARM_HTTP_PROXY'] = "http://pr.oxy:1234"
self.test_install_jenkins_remote()
finally:
os.environ = env_backup

def test_install_jenkins_lts_release(self):
"""
If the 'release' config is set to 'lts', an APT source entry will be
Expand Down

0 comments on commit bacc7cc

Please sign in to comment.