From 13826f1d07781c311d138b51ad12ecec93530698 Mon Sep 17 00:00:00 2001 From: James Page Date: Wed, 3 Jul 2013 12:46:27 +0100 Subject: [PATCH] Resync with configure_source supporting proposed --- charm-helpers-sync.yaml | 2 +- hooks/charmhelpers/core/host.py | 22 ++++++++++++++++------ hooks/charmhelpers/fetch/__init__.py | 10 +++++++++- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/charm-helpers-sync.yaml b/charm-helpers-sync.yaml index 21c0bc63..45b8a15a 100644 --- a/charm-helpers-sync.yaml +++ b/charm-helpers-sync.yaml @@ -1,4 +1,4 @@ -branch: lp:charm-helpers +branch: lp:~james-page/charm-helpers/configure_source_proposed destination: hooks/charmhelpers include: - core diff --git a/hooks/charmhelpers/core/host.py b/hooks/charmhelpers/core/host.py index 19951ed2..d60d982d 100644 --- a/hooks/charmhelpers/core/host.py +++ b/hooks/charmhelpers/core/host.py @@ -48,13 +48,13 @@ def adduser(username, password=None, shell='/bin/bash', system_user=False): log('creating user {0}'.format(username)) cmd = ['useradd'] if system_user or password is None: - cmd.append('--system') + cmd.append('--system') else: - cmd.extend([ - '--create-home', - '--shell', shell, - '--password', password, - ]) + cmd.extend([ + '--create-home', + '--shell', shell, + '--password', password, + ]) cmd.append(username) subprocess.check_call(cmd) user_info = pwd.getpwnam(username) @@ -261,3 +261,13 @@ def restart_on_change(restart_map): service('restart', service_name) return wrapped_f return wrap + + +def lsb_release(): + '''Return /etc/lsb-release in a dict''' + d = {} + with open('/etc/lsb-release', 'r') as lsb: + for l in lsb: + k, v = l.split('=') + d[k.strip()] = v.strip() + return d diff --git a/hooks/charmhelpers/fetch/__init__.py b/hooks/charmhelpers/fetch/__init__.py index e3c42424..5a306257 100644 --- a/hooks/charmhelpers/fetch/__init__.py +++ b/hooks/charmhelpers/fetch/__init__.py @@ -3,7 +3,8 @@ from yaml import safe_load from charmhelpers.core.host import ( apt_install, apt_update, - filter_installed_packages + filter_installed_packages, + lsb_release ) from urlparse import ( urlparse, @@ -18,6 +19,9 @@ from charmhelpers.core.hookenv import ( CLOUD_ARCHIVE = """# Ubuntu Cloud Archive deb http://ubuntu-cloud.archive.canonical.com/ubuntu {} main """ +PROPOSED_POCKET = """# Proposed +deb http://archive.ubuntu.com/ubuntu {}-proposed main universe multiverse restricted +""" def add_source(source, key=None): @@ -30,6 +34,10 @@ def add_source(source, key=None): pocket = source.split(':')[-1] with open('/etc/apt/sources.list.d/cloud-archive.list', 'w') as apt: apt.write(CLOUD_ARCHIVE.format(pocket)) + elif source == 'proposed': + release = lsb_release()['DISTRIB_CODENAME'] + with open('/etc/apt/sources.list.d/proposed.list', 'w') as apt: + apt.write(PROPOSED_POCKET.format(release)) if key: subprocess.check_call(['apt-key', 'import', key])