Merge lp:~openstack-charmers/charm-helpers/os-alternatives.
This commit is contained in:
commit
cae4cf181e
|
@ -1,4 +1,7 @@
|
|||
branch: lp:~james-page/charm-helpers/nvp-updates
|
||||
# NOTE: Merge conflicts.
|
||||
#branch: lp:~james-page/charm-helpers/nvp-updates
|
||||
#branch: lp:~openstack-charmers/charm-helpers/os-alternatives
|
||||
branch: lp:charm-helpers
|
||||
destination: hooks/charmhelpers
|
||||
include:
|
||||
- core
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
''' Helper for managing alternatives for file conflict resolution '''
|
||||
|
||||
import subprocess
|
||||
import shutil
|
||||
import os
|
||||
|
||||
|
||||
def install_alternative(name, target, source, priority=50):
|
||||
''' Install alternative configuration '''
|
||||
if (os.path.exists(target) and not os.path.islink(target)):
|
||||
# Move existing file/directory away before installing
|
||||
shutil.move(target, '{}.bak'.format(target))
|
||||
cmd = [
|
||||
'update-alternatives', '--force', '--install',
|
||||
target, name, source, str(priority)
|
||||
]
|
||||
subprocess.check_call(cmd)
|
|
@ -48,7 +48,7 @@ from nova_compute_utils import (
|
|||
register_configs,
|
||||
NOVA_CONF,
|
||||
QUANTUM_CONF, NEUTRON_CONF,
|
||||
CEPH_CONF, CEPH_SECRET
|
||||
ceph_config_file, CEPH_SECRET
|
||||
)
|
||||
|
||||
from nova_compute_context import CEPH_SECRET_UUID
|
||||
|
@ -180,7 +180,7 @@ def ceph_changed():
|
|||
if not ensure_ceph_keyring(service=svc):
|
||||
log('Could not create ceph keyring: peer not ready?')
|
||||
return
|
||||
CONFIGS.write(CEPH_CONF)
|
||||
CONFIGS.write(ceph_config_file())
|
||||
CONFIGS.write(CEPH_SECRET)
|
||||
CONFIGS.write(NOVA_CONF)
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ from copy import deepcopy
|
|||
from subprocess import check_call, check_output
|
||||
|
||||
from charmhelpers.fetch import apt_update, apt_install
|
||||
|
||||
from charmhelpers.core.host import mkdir
|
||||
from charmhelpers.core.hookenv import (
|
||||
config,
|
||||
log,
|
||||
|
@ -14,10 +14,12 @@ from charmhelpers.core.hookenv import (
|
|||
relation_ids,
|
||||
relation_get,
|
||||
DEBUG,
|
||||
service_name
|
||||
)
|
||||
|
||||
from charmhelpers.contrib.openstack.neutron import neutron_plugin_attribute
|
||||
from charmhelpers.contrib.openstack import templating, context
|
||||
from charmhelpers.contrib.openstack.alternatives import install_alternative
|
||||
|
||||
from charmhelpers.contrib.openstack.utils import (
|
||||
configure_installation_source,
|
||||
|
@ -72,13 +74,10 @@ BASE_RESOURCE_MAP = {
|
|||
}
|
||||
|
||||
CEPH_CONF = '/etc/ceph/ceph.conf'
|
||||
CHARM_CEPH_CONF = '/var/lib/charm/{}/ceph.conf'
|
||||
CEPH_SECRET = '/etc/ceph/secret.xml'
|
||||
|
||||
CEPH_RESOURCES = {
|
||||
CEPH_CONF: {
|
||||
'contexts': [NovaComputeCephContext()],
|
||||
'services': [],
|
||||
},
|
||||
CEPH_SECRET: {
|
||||
'contexts': [NovaComputeCephContext()],
|
||||
'services': [],
|
||||
|
@ -114,6 +113,10 @@ VIRT_TYPES = {
|
|||
}
|
||||
|
||||
|
||||
def ceph_config_file():
|
||||
return CHARM_CEPH_CONF.format(service_name())
|
||||
|
||||
|
||||
def resource_map():
|
||||
'''
|
||||
Dynamically generate a map of resources that will be managed for a single
|
||||
|
@ -157,6 +160,22 @@ def resource_map():
|
|||
[resource_map[nmc]['services'].extend(svcs) for nmc in nm_rsc]
|
||||
|
||||
if relation_ids('ceph'):
|
||||
# Add charm ceph configuration to resources and
|
||||
# ensure directory actually exists
|
||||
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 - nova-compute 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())
|
||||
CEPH_RESOURCES[ceph_config_file()] = {
|
||||
'contexts': [NovaComputeCephContext()],
|
||||
'services': [],
|
||||
}
|
||||
resource_map.update(CEPH_RESOURCES)
|
||||
|
||||
return resource_map
|
||||
|
|
|
@ -289,15 +289,18 @@ class NovaComputeRelationsTests(CharmTestCase):
|
|||
'Could not create ceph keyring: peer not ready?'
|
||||
)
|
||||
|
||||
@patch.object(utils, 'service_name')
|
||||
@patch.object(hooks, 'CONFIGS')
|
||||
def test_ceph_changed_with_key_and_relation_data(self, configs):
|
||||
def test_ceph_changed_with_key_and_relation_data(self, configs,
|
||||
service_name):
|
||||
configs.complete_contexts = MagicMock()
|
||||
configs.complete_contexts.return_value = ['ceph']
|
||||
configs.write = MagicMock()
|
||||
service_name.return_value = 'nova-compute'
|
||||
self.ensure_ceph_keyring.return_value = True
|
||||
hooks.ceph_changed()
|
||||
ex = [
|
||||
call('/etc/ceph/ceph.conf'),
|
||||
call('/var/lib/charm/nova-compute/ceph.conf'),
|
||||
call('/etc/ceph/secret.xml'),
|
||||
call('/etc/nova/nova.conf'),
|
||||
]
|
||||
|
|
|
@ -13,6 +13,9 @@ TO_PATCH = [
|
|||
'related_units',
|
||||
'relation_ids',
|
||||
'relation_get',
|
||||
'service_name',
|
||||
'mkdir',
|
||||
'install_alternative'
|
||||
]
|
||||
|
||||
OVS_PKGS = [
|
||||
|
@ -25,6 +28,7 @@ class NovaComputeUtilsTests(CharmTestCase):
|
|||
def setUp(self):
|
||||
super(NovaComputeUtilsTests, self).setUp(utils, TO_PATCH)
|
||||
self.config.side_effect = self.test_config.get
|
||||
self.service_name.return_value = 'nova-compute'
|
||||
|
||||
@patch.object(utils, 'network_manager')
|
||||
def test_determine_packages_nova_network(self, net_man):
|
||||
|
|
Loading…
Reference in New Issue