Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try JUJU_CHARM_*_PROXY settings when fetching jenkins deb #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion lib/charms/layer/jenkins/packages.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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