Merge active-active branch

This commit is contained in:
James Page
2014-03-20 14:07:04 +00:00
7 changed files with 67 additions and 45 deletions

View File

@@ -20,8 +20,7 @@ class CephGlanceContext(OSContextGenerator):
interfaces = ['ceph-glance']
def __call__(self):
"""
Used to generate template context to be added to glance-api.conf in
"""Used to generate template context to be added to glance-api.conf in
the presence of a ceph relation.
"""
if not is_relation_made(relation="ceph",
@@ -39,7 +38,7 @@ class ObjectStoreContext(OSContextGenerator):
interfaces = ['object-store']
def __call__(self):
"""
"""Object store config.
Used to generate template context to be added to glance-api.conf in
the presence of a 'object-store' relation.
"""
@@ -54,8 +53,7 @@ class HAProxyContext(OSContextGenerator):
interfaces = ['cluster']
def __call__(self):
'''
Extends the main charmhelpers HAProxyContext with a port mapping
'''Extends the main charmhelpers HAProxyContext with a port mapping
specific to this charm.
Also used to extend glance-api.conf context with correct bind_port
'''

View File

@@ -16,7 +16,7 @@ from glance_utils import (
GLANCE_API_CONF,
GLANCE_API_PASTE_INI,
HAPROXY_CONF,
CEPH_CONF, )
ceph_config_file)
from charmhelpers.core.hookenv import (
config,
@@ -33,7 +33,8 @@ from charmhelpers.core.hookenv import (
from charmhelpers.core.host import (
restart_on_change,
service_stop,
mkdir, )
mkdir
)
from charmhelpers.fetch import apt_install, apt_update
@@ -140,7 +141,6 @@ def object_store_joined():
@hooks.hook('ceph-relation-joined')
def ceph_joined():
mkdir('/etc/ceph')
apt_install(['ceph-common', 'python-ceph'])
@@ -159,7 +159,7 @@ def ceph_changed():
return
CONFIGS.write(GLANCE_API_CONF)
CONFIGS.write(CEPH_CONF)
CONFIGS.write(ceph_config_file())
if eligible_leader(CLUSTER_RES):
_config = config()
@@ -295,8 +295,7 @@ def relation_broken():
def configure_https():
'''
Enables SSL API Apache config if appropriate and kicks
'''Enables SSL API Apache config if appropriate and kicks
identity-service and image-service with any required
updates
'''

View File

@@ -15,7 +15,8 @@ from charmhelpers.fetch import (
from charmhelpers.core.hookenv import (
config,
log,
relation_ids)
relation_ids,
service_name)
from charmhelpers.core.host import (
mkdir,
@@ -35,10 +36,11 @@ from charmhelpers.contrib.storage.linux.ceph import (
create_pool as ceph_create_pool,
pool_exists as ceph_pool_exists)
from charmhelpers.contrib.openstack.alternatives import install_alternative
from charmhelpers.contrib.openstack.utils import (
get_os_codename_install_source,
get_os_codename_package,
configure_installation_source, )
configure_installation_source)
CLUSTER_RES = "res_glance_vip"
@@ -56,6 +58,8 @@ GLANCE_REGISTRY_PASTE_INI = "/etc/glance/glance-registry-paste.ini"
GLANCE_API_CONF = "/etc/glance/glance-api.conf"
GLANCE_API_PASTE_INI = "/etc/glance/glance-api-paste.ini"
CEPH_CONF = "/etc/ceph/ceph.conf"
CHARM_CEPH_CONF = '/var/lib/charm/{}/ceph.conf'
HAPROXY_CONF = "/etc/haproxy/haproxy.cfg"
HTTPS_APACHE_CONF = "/etc/apache2/sites-available/openstack_https_frontend"
HTTPS_APACHE_24_CONF = "/etc/apache2/sites-available/" \
@@ -65,6 +69,9 @@ CONF_DIR = "/etc/glance"
TEMPLATES = 'templates/'
def ceph_config_file():
return CHARM_CEPH_CONF.format(service_name())
CONFIG_FILES = OrderedDict([
(GLANCE_REGISTRY_CONF, {
'hook_contexts': [context.SharedDBContext(),
@@ -90,7 +97,7 @@ CONFIG_FILES = OrderedDict([
'hook_contexts': [context.IdentityServiceContext()],
'services': ['glance-registry']
}),
(CEPH_CONF, {
(ceph_config_file(), {
'hook_contexts': [context.CephContext()],
'services': ['glance-api', 'glance-registry']
}),
@@ -109,7 +116,6 @@ CONFIG_FILES = OrderedDict([
})
])
def register_configs():
# Register config files with their respective contexts.
# Regstration of some configs may not be required depending on
@@ -125,8 +131,18 @@ def register_configs():
HAPROXY_CONF]
if relation_ids('ceph'):
mkdir('/etc/ceph')
confs.append(CEPH_CONF)
mkdir(os.path.dirname(ceph_config_file()))
mkdir(os.path.dirname(CEPH_CONF))
# Install ceph config as an alternative for co-location with
# ceph and ceph-osd charms - glance ceph.conf will be
# lower priority that both of these but thats OK
if not os.path.exists(ceph_config_file()):
# touch file for pre-templated generation
open(ceph_config_file(), 'w').close()
install_alternative(os.path.basename(CEPH_CONF),
CEPH_CONF, ceph_config_file())
confs.append(ceph_config_file())
for conf in confs:
configs.register(conf, CONFIG_FILES[conf]['hook_contexts'])
@@ -142,23 +158,26 @@ def register_configs():
def migrate_database():
'''Runs glance-manage to initialize a new database or migrate existing'''
'''Runs glance-manage to initialize a new database
or migrate existing
'''
cmd = ['glance-manage', 'db_sync']
subprocess.check_call(cmd)
def ensure_ceph_pool(service, replicas):
'''Creates a ceph pool for service if one does not exist'''
# TODO: Ditto about moving somewhere sharable.
'''Creates a ceph pool for service
if one does not exist
'''
# TODO(Ditto about moving somewhere sharable.)
if not ceph_pool_exists(service=service, name=service):
ceph_create_pool(service=service, name=service, replicas=replicas)
def do_openstack_upgrade(configs):
"""
Perform an uprade of cinder. Takes care of upgrading packages, rewriting
configs + database migration and potentially any other post-upgrade
actions.
"""Perform an uprade of cinder. Takes care of upgrading
packages, rewriting configs + database migration and potentially
any other post-upgrade actions.
:param configs: The charms main OSConfigRenderer object.
@@ -188,8 +207,7 @@ def do_openstack_upgrade(configs):
def restart_map():
'''
Determine the correct resource map to be passed to
'''Determine the correct resource map to be passed to
charmhelpers.core.restart_on_change() based on the services configured.
:returns: dict: A dictionary mapping config file to lists of services

View File

@@ -1,5 +1,5 @@
from mock import patch
import glance_contexts as contexts
from mock import patch
from test_utils import (
CharmTestCase

View File

@@ -1,7 +1,9 @@
from mock import call, patch, MagicMock
import os
from test_utils import CharmTestCase
os.environ['JUJU_UNIT_NAME'] = 'glance'
import glance_utils as utils
_reg = utils.register_configs
@@ -45,12 +47,13 @@ TO_PATCH = [
'migrate_database',
'ensure_ceph_keyring',
'ensure_ceph_pool',
'ceph_config_file',
# other
'call',
'check_call',
'execd_preinstall',
'mkdir',
'lsb_release'
'lsb_release',
'mkdir'
]
@@ -204,7 +207,6 @@ class GlanceRelationTests(CharmTestCase):
def test_ceph_joined(self):
relations.ceph_joined()
self.mkdir.assert_called_with('/etc/ceph')
self.apt_install.assert_called_with(['ceph-common', 'python-ceph'])
@patch.object(relations, 'CONFIGS')
@@ -236,12 +238,13 @@ class GlanceRelationTests(CharmTestCase):
self.ensure_ceph_keyring.return_value = True
relations.ceph_changed()
self.assertEquals([call('/etc/glance/glance-api.conf'),
call('/etc/ceph/ceph.conf')],
call(self.ceph_config_file())],
configs.write.call_args_list)
self.ensure_ceph_pool.assert_called_with(service=self.service_name(),
replicas=2)
def test_keystone_joined_not_leader(self):
self.ceph_config_file.return_value = '/var/lib/charm/glance/ceph.conf'
self.eligible_leader.return_value = False
relations.keystone_joined()
self.assertFalse(self.relation_set.called)

View File

@@ -1,7 +1,9 @@
from mock import patch, call, MagicMock
from collections import OrderedDict
import os
os.environ['JUJU_UNIT_NAME'] = 'glance'
import glance_utils as utils
from test_utils import (
@@ -24,7 +26,9 @@ TO_PATCH = [
'apt_install',
'mkdir',
'service_start',
'service_stop'
'service_stop',
'service_name',
'install_alternative'
]
DPKG_OPTS = [
@@ -41,7 +45,7 @@ class TestGlanceUtils(CharmTestCase):
@patch('subprocess.check_call')
def test_migrate_database(self, check_call):
'''It migrates database with cinder-manage'''
"It migrates database with cinder-manage"
utils.migrate_database()
check_call.assert_called_with(['glance-manage', 'db_sync'])
@@ -97,9 +101,10 @@ class TestGlanceUtils(CharmTestCase):
@patch('os.path.exists')
def test_register_configs_ceph(self, exists):
exists.return_value = False
exists.return_value = True
self.get_os_codename_package.return_value = 'grizzly'
self.relation_ids.return_value = ['ceph:0']
self.service_name.return_value = 'glance'
configs = utils.register_configs()
calls = []
for conf in [utils.GLANCE_REGISTRY_CONF,
@@ -107,8 +112,7 @@ class TestGlanceUtils(CharmTestCase):
utils.GLANCE_API_PASTE_INI,
utils.GLANCE_REGISTRY_PASTE_INI,
utils.HAPROXY_CONF,
utils.HTTPS_APACHE_CONF,
utils.CEPH_CONF]:
utils.ceph_config_file()]:
calls.append(
call(conf,
utils.CONFIG_FILES[conf]['hook_contexts'])
@@ -117,12 +121,14 @@ class TestGlanceUtils(CharmTestCase):
self.mkdir.assert_called_with('/etc/ceph')
def test_restart_map(self):
self.service_name.return_value = 'glance'
ex_map = OrderedDict([
(utils.GLANCE_REGISTRY_CONF, ['glance-registry']),
(utils.GLANCE_API_CONF, ['glance-api']),
(utils.GLANCE_API_PASTE_INI, ['glance-api']),
(utils.GLANCE_REGISTRY_PASTE_INI, ['glance-registry']),
(utils.CEPH_CONF, ['glance-api', 'glance-registry']),
(utils.ceph_config_file(), ['glance-api', 'glance-registry']),
(utils.HAPROXY_CONF, ['haproxy']),
(utils.HTTPS_APACHE_CONF, ['apache2']),
(utils.HTTPS_APACHE_24_CONF, ['apache2'])

View File

@@ -1,6 +1,6 @@
import logging
import unittest
import os
import unittest
import yaml
from contextlib import contextmanager
@@ -8,9 +8,8 @@ from mock import patch, MagicMock
def load_config():
'''
Walk backwords from __file__ looking for config.yaml, load and return the
'options' section'
'''Walk backwords from __file__ looking for config.yaml,
load and return the 'options' section'
'''
config = None
f = __file__
@@ -30,8 +29,7 @@ def load_config():
def get_default_config():
'''
Load default charm config from config.yaml return as a dict.
'''Load default charm config from config.yaml return as a dict.
If no default is set in config.yaml, its value is None.
'''
default_config = {}
@@ -107,8 +105,8 @@ class TestRelation(object):
def patch_open():
'''Patch open() to allow mocking both open() itself and the file that is
yielded.
Yields the mock for "open" and "file", respectively.'''
Yields the mock for "open" and "file", respectively.
'''
mock_open = MagicMock(spec=open)
mock_file = MagicMock(spec=file)