Resync charm-helpers

This commit is contained in:
James Page 2013-09-20 17:40:54 +01:00
parent 428bf6b09e
commit 437f362af7
10 changed files with 49 additions and 71 deletions

View File

@ -11,4 +11,4 @@ test:
@$(PYTHON) /usr/bin/nosetests --nologcapture --with-coverage unit_tests
sync:
@charm-helper-sync -c charm-helpers-sync.yaml
@charm-helper-sync -c charm-helpers.yaml

View File

@ -2,6 +2,7 @@ branch: lp:~openstack-charmers/charm-helpers/to_upstream
destination: hooks/charmhelpers
include:
- core
- fetch
- contrib.openstack|inc=*
- contrib.storage
- contrib.hahelpers:

View File

@ -28,8 +28,11 @@ from charmhelpers.core.hookenv import (
ERROR
)
from charmhelpers.core.host import (
from charmhelpers.fetch import (
apt_install,
)
from charmhelpers.core.host import (
mount,
mounts,
service_start,

View File

@ -7,7 +7,7 @@ from subprocess import (
)
from charmhelpers.core.host import (
from charmhelpers.fetch import (
apt_install,
filter_installed_packages,
)
@ -110,9 +110,9 @@ class SharedDBContext(OSContextGenerator):
'database_user': self.user,
'database_password': passwd,
}
if not context_complete(ctxt):
return {}
return ctxt
if context_complete(ctxt):
return ctxt
return {}
class IdentityServiceContext(OSContextGenerator):
@ -141,9 +141,9 @@ class IdentityServiceContext(OSContextGenerator):
'service_protocol': 'http',
'auth_protocol': 'http',
}
if not context_complete(ctxt):
return {}
return ctxt
if context_complete(ctxt):
return ctxt
return {}
class AMQPContext(OSContextGenerator):
@ -164,20 +164,30 @@ class AMQPContext(OSContextGenerator):
for rid in relation_ids('amqp'):
for unit in related_units(rid):
if relation_get('clustered', rid=rid, unit=unit):
rabbitmq_host = relation_get('vip', rid=rid, unit=unit)
ctxt['clustered'] = True
ctxt['rabbitmq_host'] = relation_get('vip', rid=rid,
unit=unit)
else:
rabbitmq_host = relation_get('private-address',
rid=rid, unit=unit)
ctxt = {
'rabbitmq_host': rabbitmq_host,
ctxt['rabbitmq_host'] = relation_get('private-address',
rid=rid, unit=unit)
ctxt.update({
'rabbitmq_user': username,
'rabbitmq_password': relation_get('password', rid=rid,
unit=unit),
'rabbitmq_virtual_host': vhost,
}
})
if context_complete(ctxt):
# Sufficient information found = break out!
break
# Used for active/active rabbitmq >= grizzly
ctxt['rabbitmq_hosts'] = []
for unit in related_units(rid):
ctxt['rabbitmq_hosts'].append(relation_get('private-address',
rid=rid, unit=unit))
if not context_complete(ctxt):
return {}
return ctxt
else:
return ctxt
class CephContext(OSContextGenerator):

View File

@ -1,6 +1,6 @@
import os
from charmhelpers.core.host import apt_install
from charmhelpers.fetch import apt_install
from charmhelpers.core.hookenv import (
log,

View File

@ -17,6 +17,9 @@ from charmhelpers.core.hookenv import (
from charmhelpers.core.host import (
lsb_release,
)
from charmhelpers.fetch import (
apt_install,
)
@ -130,7 +133,7 @@ def get_os_codename_package(package, fatal=True):
e = 'Could not determine version of uninstalled package: %s' % package
error_out(e)
vers = apt.UpstreamVersion(pkg.current_ver.ver_str)
vers = apt.upstream_version(pkg.current_ver.ver_str)
try:
if 'swift' in pkg.name:

View File

@ -5,7 +5,6 @@
# Nick Moffitt <nick.moffitt@canonical.com>
# Matthew Wedgwood <matthew.wedgwood@canonical.com>
import apt_pkg
import os
import pwd
import grp
@ -20,20 +19,22 @@ from hookenv import log
def service_start(service_name):
service('start', service_name)
return service('start', service_name)
def service_stop(service_name):
service('stop', service_name)
return service('stop', service_name)
def service_restart(service_name):
service('restart', service_name)
return service('restart', service_name)
def service_reload(service_name, restart_on_failure=False):
if not service('reload', service_name) and restart_on_failure:
service('restart', service_name)
service_result = service('reload', service_name)
if not service_result and restart_on_failure:
service_result = service('restart', service_name)
return service_result
def service(action, service_name):
@ -136,49 +137,6 @@ def write_file(path, content, owner='root', group='root', perms=0444):
target.write(content)
def filter_installed_packages(packages):
"""Returns a list of packages that require installation"""
apt_pkg.init()
cache = apt_pkg.Cache()
_pkgs = []
for package in packages:
try:
p = cache[package]
p.current_ver or _pkgs.append(package)
except KeyError:
log('Package {} has no installation candidate.'.format(package),
level='WARNING')
_pkgs.append(package)
return _pkgs
def apt_install(packages, options=None, fatal=False):
"""Install one or more packages"""
options = options or []
cmd = ['apt-get', '-y']
cmd.extend(options)
cmd.append('install')
if isinstance(packages, basestring):
cmd.append(packages)
else:
cmd.extend(packages)
log("Installing {} with options: {}".format(packages,
options))
if fatal:
subprocess.check_call(cmd)
else:
subprocess.call(cmd)
def apt_update(fatal=False):
"""Update local apt cache"""
cmd = ['apt-get', 'update']
if fatal:
subprocess.check_call(cmd)
else:
subprocess.call(cmd)
def mount(device, mountpoint, options=None, persist=False):
'''Mount a filesystem'''
cmd_args = ['mount']

View File

@ -3,8 +3,8 @@ from subprocess import check_call, check_output
from charmhelpers.contrib.openstack import context
from charmhelpers.core.host import (
apt_install, filter_installed_packages, service_running, service_start)
from charmhelpers.core.host import service_running, service_start
from charmhelpers.fetch import apt_install, filter_installed_packages
from charmhelpers.core.hookenv import (
config,

View File

@ -15,10 +15,13 @@ from charmhelpers.core.hookenv import (
)
from charmhelpers.core.host import (
restart_on_change,
)
from charmhelpers.fetch import (
apt_install,
apt_update,
filter_installed_packages,
restart_on_change,
)
from charmhelpers.contrib.openstack.utils import (

View File

@ -5,7 +5,7 @@ from base64 import b64decode
from copy import deepcopy
from subprocess import check_call, check_output
from charmhelpers.core.host import apt_update, apt_install
from charmhelpers.fetch import apt_update, apt_install
from charmhelpers.core.hookenv import (
config,