Fixup config_changed altering install source

This commit is contained in:
James Page 2014-03-25 10:44:27 +00:00
commit 533b19cbe5
5 changed files with 42 additions and 62 deletions

View File

@ -4,3 +4,4 @@ include:
- core
- contrib.charmsupport
- contrib.openstack
- fetch

View File

@ -83,3 +83,20 @@ options:
description: |
If True, services that support it will log to syslog instead of their normal
log location.
key:
type: string
description: |
Key ID to import to the apt keyring to support use with arbitary source
configuration from outside of Launchpad archives or PPA's.
source:
type: string
description: |
Optional configuration to support use of additional sources such as:
.
- ppa:myteam/ppa
- cloud:precise-proposed/folsom
- http://my.archive.com/ubuntu main
.
The last option should be used in conjunction with the key configuration
option.

View File

@ -58,59 +58,6 @@ def render_template(template_name, context, template_dir=TEMPLATES_DIR):
template = templates.get_template(template_name)
return template.render(context)
CLOUD_ARCHIVE = """
# Ubuntu Cloud Archive
deb http://ubuntu-cloud.archive.canonical.com/ubuntu {} main
"""
CLOUD_ARCHIVE_POCKETS = {
'folsom': 'precise-updates/folsom',
'folsom/updates': 'precise-updates/folsom',
'folsom/proposed': 'precise-proposed/folsom',
'grizzly': 'precise-updates/grizzly',
'grizzly/updates': 'precise-updates/grizzly',
'grizzly/proposed': 'precise-proposed/grizzly',
'havana': 'precise-updates/havana',
'havana/updates': 'precise-updates/havana',
'havana/proposed': 'precise-proposed/havana'}
def configure_source():
source = str(config_get('openstack-origin'))
if not source:
return
if source.startswith('ppa:'):
cmd = [
'add-apt-repository',
source]
subprocess.check_call(cmd)
if source.startswith('cloud:'):
# CA values should be formatted as cloud:ubuntu-openstack/pocket, eg:
# cloud:precise-folsom/updates or cloud:precise-folsom/proposed
install('ubuntu-cloud-keyring')
pocket = source.split(':')[1]
pocket = pocket.split('-')[1]
with open('/etc/apt/sources.list.d/cloud-archive.list', 'w') as apt:
apt.write(CLOUD_ARCHIVE.format(CLOUD_ARCHIVE_POCKETS[pocket]))
if source.startswith('deb'):
l = len(source.split('|'))
if l == 2:
(apt_line, key) = source.split('|')
cmd = [
'apt-key',
'adv', '--keyserver keyserver.ubuntu.com',
'--recv-keys', key]
subprocess.check_call(cmd)
elif l == 1:
apt_line = source
with open('/etc/apt/sources.list.d/quantum.list', 'w') as apt:
apt.write(apt_line + "\n")
cmd = [
'apt-get',
'update']
subprocess.check_call(cmd)
# Protocols
TCP = 'TCP'
UDP = 'UDP'

View File

@ -20,6 +20,10 @@ _ = _pythonpath
from charmhelpers.core import hookenv
from charmhelpers.core.host import rsync
from charmhelpers.contrib.charmsupport.nrpe import NRPE
from charmhelpers.fetch import (
apt_update,
add_source
)
SERVICE_NAME = os.getenv('JUJU_UNIT_NAME').split('/')[0]
@ -35,12 +39,7 @@ def ensure_unison_rabbit_permissions():
def install():
pre_install_hooks()
utils.install(*rabbit.PACKAGES)
utils.expose(5672)
# ensure user + permissions for peer relations that
# may be syncing data there via SSH_USER.
unison.ensure_user(user=rabbit.SSH_USER, group=rabbit.RABBIT_USER)
ensure_unison_rabbit_permissions()
# NOTE(jamespage) install actually happens in config_changed hook
def configure_amqp(username, vhost):
@ -365,7 +364,17 @@ MAN_PLUGIN = 'rabbitmq_management'
def config_changed():
unison.ensure_user(user=rabbit.SSH_USER, group='rabbit')
# Add archive source if provided
add_source(utils.config_get('source'), utils.config_get('key'))
apt_update(fatal=True)
# Install packages to ensure and changes to source
# result in an upgrade if applicable.
utils.install(*rabbit.PACKAGES)
utils.expose(5672)
unison.ensure_user(user=rabbit.SSH_USER, group=rabbit.RABBIT_USER)
ensure_unison_rabbit_permissions()
if utils.config_get('management_plugin') is True:

View File

@ -135,8 +135,12 @@ def apt_hold(packages, fatal=False):
def add_source(source, key=None):
if source is None:
log('Source is not present. Skipping')
return
if (source.startswith('ppa:') or
source.startswith('http:') or
source.startswith('http') or
source.startswith('deb ') or
source.startswith('cloud-archive:')):
subprocess.check_call(['add-apt-repository', '--yes', source])
@ -156,7 +160,9 @@ def add_source(source, key=None):
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])
subprocess.check_call(['apt-key', 'adv', '--keyserver',
'keyserver.ubuntu.com', '--recv',
key])
class SourceConfigError(Exception):