Rebase
This commit is contained in:
commit
a346819efa
@ -1,4 +1,4 @@
|
||||
branch: lp:charm-helpers
|
||||
branch: lp:~hopem/charm-helpers/add-rbd-cache-config-support
|
||||
destination: hooks/charmhelpers
|
||||
include:
|
||||
- core
|
||||
|
@ -225,6 +225,14 @@ options:
|
||||
description: |
|
||||
RBD pool to use with Nova libvirt RBDImageBackend. Only required when you
|
||||
have libvirt-image-backend set to 'rbd'.
|
||||
rbd-client-cache:
|
||||
type: string
|
||||
default:
|
||||
description: |
|
||||
Enable/disable rbd client cache. Leaving this value unset will result in
|
||||
default Ceph rbd client settings being used (rbd cache is enabled by
|
||||
default for Ceph >= Giant). Supported values here are "enabled" or
|
||||
"disabled".
|
||||
ceph-osd-replication-count:
|
||||
type: int
|
||||
default: 3
|
||||
|
@ -13,3 +13,9 @@ log to syslog = {{ use_syslog }}
|
||||
err to syslog = {{ use_syslog }}
|
||||
clog to syslog = {{ use_syslog }}
|
||||
|
||||
[client]
|
||||
{% if rbd_client_cache_settings -%}
|
||||
{% for key, value in rbd_client_cache_settings.iteritems() -%}
|
||||
{{ key }} = {{ value }}
|
||||
{% endfor -%}
|
||||
{%- endif %}
|
@ -18,7 +18,7 @@ import os
|
||||
|
||||
import six
|
||||
|
||||
from charmhelpers.fetch import apt_install
|
||||
from charmhelpers.fetch import apt_install, apt_update
|
||||
from charmhelpers.core.hookenv import (
|
||||
log,
|
||||
ERROR,
|
||||
@ -29,6 +29,7 @@ from charmhelpers.contrib.openstack.utils import OPENSTACK_CODENAMES
|
||||
try:
|
||||
from jinja2 import FileSystemLoader, ChoiceLoader, Environment, exceptions
|
||||
except ImportError:
|
||||
apt_update(fatal=True)
|
||||
apt_install('python-jinja2', fatal=True)
|
||||
from jinja2 import FileSystemLoader, ChoiceLoader, Environment, exceptions
|
||||
|
||||
|
@ -25,6 +25,7 @@ import sys
|
||||
import re
|
||||
|
||||
import six
|
||||
import traceback
|
||||
import yaml
|
||||
|
||||
from charmhelpers.contrib.network import ip
|
||||
@ -34,6 +35,8 @@ from charmhelpers.core import (
|
||||
)
|
||||
|
||||
from charmhelpers.core.hookenv import (
|
||||
action_fail,
|
||||
action_set,
|
||||
config,
|
||||
log as juju_log,
|
||||
charm_dir,
|
||||
@ -51,7 +54,8 @@ from charmhelpers.contrib.storage.linux.lvm import (
|
||||
)
|
||||
|
||||
from charmhelpers.contrib.network.ip import (
|
||||
get_ipv6_addr
|
||||
get_ipv6_addr,
|
||||
is_ipv6,
|
||||
)
|
||||
|
||||
from charmhelpers.contrib.python.packages import (
|
||||
@ -516,6 +520,12 @@ def sync_db_with_multi_ipv6_addresses(database, database_user,
|
||||
relation_prefix=None):
|
||||
hosts = get_ipv6_addr(dynamic_only=False)
|
||||
|
||||
if config('vip'):
|
||||
vips = config('vip').split()
|
||||
for vip in vips:
|
||||
if vip and is_ipv6(vip):
|
||||
hosts.append(vip)
|
||||
|
||||
kwargs = {'database': database,
|
||||
'username': database_user,
|
||||
'hostname': json.dumps(hosts)}
|
||||
@ -921,3 +931,47 @@ def incomplete_relation_data(configs, required_interfaces):
|
||||
for i in incomplete_relations:
|
||||
incomplete_context_data[i] = configs.get_incomplete_context_data(required_interfaces[i])
|
||||
return incomplete_context_data
|
||||
|
||||
|
||||
def do_action_openstack_upgrade(package, upgrade_callback, configs):
|
||||
"""Perform action-managed OpenStack upgrade.
|
||||
|
||||
Upgrades packages to the configured openstack-origin version and sets
|
||||
the corresponding action status as a result.
|
||||
|
||||
If the charm was installed from source we cannot upgrade it.
|
||||
For backwards compatibility a config flag (action-managed-upgrade) must
|
||||
be set for this code to run, otherwise a full service level upgrade will
|
||||
fire on config-changed.
|
||||
|
||||
@param package: package name for determining if upgrade available
|
||||
@param upgrade_callback: function callback to charm's upgrade function
|
||||
@param configs: templating object derived from OSConfigRenderer class
|
||||
|
||||
@return: True if upgrade successful; False if upgrade failed or skipped
|
||||
"""
|
||||
ret = False
|
||||
|
||||
if git_install_requested():
|
||||
action_set({'outcome': 'installed from source, skipped upgrade.'})
|
||||
else:
|
||||
if openstack_upgrade_available(package):
|
||||
if config('action-managed-upgrade'):
|
||||
juju_log('Upgrading OpenStack release')
|
||||
|
||||
try:
|
||||
upgrade_callback(configs=configs)
|
||||
action_set({'outcome': 'success, upgrade completed.'})
|
||||
ret = True
|
||||
except:
|
||||
action_set({'outcome': 'upgrade failed, see traceback.'})
|
||||
action_set({'traceback': traceback.format_exc()})
|
||||
action_fail('do_openstack_upgrade resulted in an '
|
||||
'unexpected error')
|
||||
else:
|
||||
action_set({'outcome': 'action-managed-upgrade config is '
|
||||
'False, skipped upgrade.'})
|
||||
else:
|
||||
action_set({'outcome': 'no upgrade available.'})
|
||||
|
||||
return ret
|
||||
|
@ -1,5 +1,7 @@
|
||||
import uuid
|
||||
import os
|
||||
import platform
|
||||
|
||||
from charmhelpers.contrib.openstack import context
|
||||
from charmhelpers.core.host import service_running, service_start
|
||||
from charmhelpers.fetch import apt_install, filter_installed_packages
|
||||
@ -24,7 +26,6 @@ from charmhelpers.contrib.network.ovs import add_bridge
|
||||
from charmhelpers.contrib.network.ip import (
|
||||
get_address_in_network,
|
||||
get_ipv6_addr,
|
||||
format_ipv6_addr,
|
||||
)
|
||||
|
||||
# This is just a label and it must be consistent across
|
||||
@ -181,6 +182,23 @@ class NovaComputeCephContext(context.CephContext):
|
||||
elif config('libvirt-image-backend') == 'lvm':
|
||||
ctxt['libvirt_images_type'] = 'lvm'
|
||||
|
||||
rbd_cache = config('rbd-client-cache') or ""
|
||||
if rbd_cache.lower() == "enabled":
|
||||
# We use write-though only to be safe for migration
|
||||
ctxt['rbd_client_cache_settings'] = \
|
||||
{'rbd cache': 'true',
|
||||
'rbd cache size': '64 MiB',
|
||||
'rbd cache max dirty': '0 MiB',
|
||||
'rbd cache writethrough until flush': 'true',
|
||||
'admin socket': '/var/run/ceph/rbd-client-$pid.asok'}
|
||||
|
||||
asok_path = '/var/run/ceph/'
|
||||
if not os.path.isdir(asok_path):
|
||||
os.mkdir(asok_path)
|
||||
|
||||
elif rbd_cache.lower() == "disabled":
|
||||
ctxt['rbd_client_cache_settings'] = {'rbd cache': 'false'}
|
||||
|
||||
return ctxt
|
||||
|
||||
|
||||
@ -474,6 +492,7 @@ class HostIPContext(context.OSContextGenerator):
|
||||
host_ip = get_host_ip(unit_get('private-address'))
|
||||
|
||||
if host_ip:
|
||||
ctxt['host_ip'] = format_ipv6_addr(host_ip) or host_ip
|
||||
# NOTE: do not format this even for ipv6 (see bug 1499656)
|
||||
ctxt['host_ip'] = host_ip
|
||||
|
||||
return ctxt
|
||||
|
@ -13,6 +13,7 @@ from charmhelpers.core.hookenv import (
|
||||
service_name,
|
||||
unit_get,
|
||||
UnregisteredHookError,
|
||||
status_set,
|
||||
)
|
||||
from charmhelpers.core.host import (
|
||||
restart_on_change,
|
||||
@ -32,6 +33,7 @@ from charmhelpers.contrib.openstack.utils import (
|
||||
git_install_requested,
|
||||
openstack_upgrade_available,
|
||||
os_requires_version,
|
||||
os_workload_status,
|
||||
)
|
||||
|
||||
from charmhelpers.contrib.storage.linux.ceph import (
|
||||
@ -66,6 +68,8 @@ from nova_compute_utils import (
|
||||
assert_charm_supports_ipv6,
|
||||
manage_ovs,
|
||||
install_hugepages,
|
||||
REQUIRED_INTERFACES,
|
||||
check_optional_relations,
|
||||
)
|
||||
|
||||
from charmhelpers.contrib.network.ip import (
|
||||
@ -88,28 +92,38 @@ CONFIGS = register_configs()
|
||||
|
||||
|
||||
@hooks.hook('install.real')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
def install():
|
||||
status_set('maintenance', 'Executing pre-install')
|
||||
execd_preinstall()
|
||||
configure_installation_source(config('openstack-origin'))
|
||||
|
||||
status_set('maintenance', 'Installing apt packages')
|
||||
apt_update()
|
||||
apt_install(determine_packages(), fatal=True)
|
||||
|
||||
status_set('maintenance', 'Git install')
|
||||
git_install(config('openstack-origin-git'))
|
||||
|
||||
|
||||
@hooks.hook('config-changed')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
@restart_on_change(restart_map())
|
||||
def config_changed():
|
||||
if config('prefer-ipv6'):
|
||||
status_set('maintenance', 'configuring ipv6')
|
||||
assert_charm_supports_ipv6()
|
||||
|
||||
global CONFIGS
|
||||
if git_install_requested():
|
||||
if config_value_changed('openstack-origin-git'):
|
||||
status_set('maintenance', 'Running Git install')
|
||||
git_install(config('openstack-origin-git'))
|
||||
else:
|
||||
if openstack_upgrade_available('nova-common'):
|
||||
status_set('maintenance', 'Running openstack upgrade')
|
||||
CONFIGS = do_openstack_upgrade()
|
||||
|
||||
sysctl_dict = config('sysctl')
|
||||
@ -119,11 +133,13 @@ def config_changed():
|
||||
if migration_enabled() and config('migration-auth-type') == 'ssh':
|
||||
# Check-in with nova-c-c and register new ssh key, if it has just been
|
||||
# generated.
|
||||
status_set('maintenance', 'SSH key exchange')
|
||||
initialize_ssh_keys()
|
||||
import_authorized_keys()
|
||||
|
||||
if config('enable-resize') is True:
|
||||
enable_shell(user='nova')
|
||||
status_set('maintenance', 'SSH key exchange')
|
||||
initialize_ssh_keys(user='nova')
|
||||
import_authorized_keys(user='nova', prefix='nova')
|
||||
else:
|
||||
@ -133,6 +149,9 @@ def config_changed():
|
||||
fp = config('instances-path')
|
||||
fix_path_ownership(fp, user='nova')
|
||||
|
||||
if config('virt-type').lower() == 'lxd':
|
||||
configure_lxd(user='nova')
|
||||
|
||||
[compute_joined(rid) for rid in relation_ids('cloud-compute')]
|
||||
for rid in relation_ids('zeromq-configuration'):
|
||||
zeromq_configuration_relation_joined(rid)
|
||||
@ -147,6 +166,8 @@ def config_changed():
|
||||
|
||||
|
||||
@hooks.hook('amqp-relation-joined')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
def amqp_joined(relation_id=None):
|
||||
relation_set(relation_id=relation_id,
|
||||
username=config('rabbit-user'),
|
||||
@ -155,6 +176,8 @@ def amqp_joined(relation_id=None):
|
||||
|
||||
@hooks.hook('amqp-relation-changed')
|
||||
@hooks.hook('amqp-relation-departed')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
@restart_on_change(restart_map())
|
||||
def amqp_changed():
|
||||
if 'amqp' not in CONFIGS.complete_contexts():
|
||||
@ -170,6 +193,8 @@ def amqp_changed():
|
||||
|
||||
|
||||
@hooks.hook('shared-db-relation-joined')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
def db_joined(rid=None):
|
||||
if is_relation_made('pgsql-db'):
|
||||
# error, postgresql is used
|
||||
@ -185,6 +210,8 @@ def db_joined(rid=None):
|
||||
|
||||
|
||||
@hooks.hook('pgsql-db-relation-joined')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
def pgsql_db_joined():
|
||||
if is_relation_made('shared-db'):
|
||||
# raise error
|
||||
@ -197,6 +224,8 @@ def pgsql_db_joined():
|
||||
|
||||
|
||||
@hooks.hook('shared-db-relation-changed')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
@restart_on_change(restart_map())
|
||||
def db_changed():
|
||||
if 'shared-db' not in CONFIGS.complete_contexts():
|
||||
@ -206,6 +235,8 @@ def db_changed():
|
||||
|
||||
|
||||
@hooks.hook('pgsql-db-relation-changed')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
@restart_on_change(restart_map())
|
||||
def postgresql_db_changed():
|
||||
if 'pgsql-db' not in CONFIGS.complete_contexts():
|
||||
@ -215,6 +246,8 @@ def postgresql_db_changed():
|
||||
|
||||
|
||||
@hooks.hook('image-service-relation-changed')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
@restart_on_change(restart_map())
|
||||
def image_service_changed():
|
||||
if 'image-service' not in CONFIGS.complete_contexts():
|
||||
@ -256,8 +289,11 @@ def compute_changed():
|
||||
|
||||
|
||||
@hooks.hook('ceph-relation-joined')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
@restart_on_change(restart_map())
|
||||
def ceph_joined():
|
||||
status_set('maintenance', 'Installing apt packages')
|
||||
apt_install(filter_installed_packages(['ceph-common']), fatal=True)
|
||||
# Bug 1427660
|
||||
service_restart('libvirt-bin')
|
||||
@ -271,6 +307,8 @@ def get_ceph_request():
|
||||
|
||||
|
||||
@hooks.hook('ceph-relation-changed')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
@restart_on_change(restart_map())
|
||||
def ceph_changed():
|
||||
if 'ceph' not in CONFIGS.complete_contexts():
|
||||
@ -305,6 +343,8 @@ def ceph_changed():
|
||||
|
||||
|
||||
@hooks.hook('ceph-relation-broken')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
def ceph_broken():
|
||||
service = service_name()
|
||||
delete_keyring(service=service)
|
||||
@ -315,6 +355,8 @@ def ceph_broken():
|
||||
'image-service-relation-broken',
|
||||
'shared-db-relation-broken',
|
||||
'pgsql-db-relation-broken')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
@restart_on_change(restart_map())
|
||||
def relation_broken():
|
||||
CONFIGS.write_all()
|
||||
@ -323,6 +365,7 @@ def relation_broken():
|
||||
@hooks.hook('upgrade-charm')
|
||||
def upgrade_charm():
|
||||
# NOTE: ensure psutil install for hugepages configuration
|
||||
status_set('maintenance', 'Installing apt packages')
|
||||
apt_install(filter_installed_packages(['python-psutil']))
|
||||
for r_id in relation_ids('amqp'):
|
||||
amqp_joined(relation_id=r_id)
|
||||
@ -338,6 +381,8 @@ def nova_ceilometer_relation_changed():
|
||||
|
||||
|
||||
@hooks.hook('zeromq-configuration-relation-joined')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
@os_requires_version('kilo', 'nova-common')
|
||||
def zeromq_configuration_relation_joined(relid=None):
|
||||
relation_set(relation_id=relid,
|
||||
@ -346,6 +391,8 @@ def zeromq_configuration_relation_joined(relid=None):
|
||||
|
||||
|
||||
@hooks.hook('zeromq-configuration-relation-changed')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
@restart_on_change(restart_map())
|
||||
def zeromq_configuration_relation_changed():
|
||||
CONFIGS.write(NOVA_CONF)
|
||||
@ -364,6 +411,8 @@ def update_nrpe_config():
|
||||
|
||||
|
||||
@hooks.hook('neutron-plugin-relation-changed')
|
||||
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
@restart_on_change(restart_map())
|
||||
def neutron_plugin_changed():
|
||||
settings = relation_get()
|
||||
|
@ -38,6 +38,7 @@ from charmhelpers.core.hookenv import (
|
||||
relation_get,
|
||||
DEBUG,
|
||||
INFO,
|
||||
status_get,
|
||||
)
|
||||
|
||||
from charmhelpers.core.templating import render
|
||||
@ -54,7 +55,8 @@ from charmhelpers.contrib.openstack.utils import (
|
||||
git_src_dir,
|
||||
git_pip_venv_dir,
|
||||
git_yaml_value,
|
||||
os_release
|
||||
os_release,
|
||||
set_os_workload_status,
|
||||
)
|
||||
|
||||
from charmhelpers.contrib.python.packages import (
|
||||
@ -255,6 +257,13 @@ LIBVIRT_URIS = {
|
||||
'lxc': 'lxc:///',
|
||||
}
|
||||
|
||||
# The interface is said to be satisfied if anyone of the interfaces in the
|
||||
# list has a complete context.
|
||||
REQUIRED_INTERFACES = {
|
||||
'message': ['amqp', 'zeromq-configuration'],
|
||||
'image': ['image-service'],
|
||||
}
|
||||
|
||||
|
||||
def resource_map():
|
||||
'''
|
||||
@ -828,3 +837,21 @@ def install_hugepages():
|
||||
)
|
||||
subprocess.check_call('/etc/init.d/qemu-hugefsdir')
|
||||
subprocess.check_call(['update-rc.d', 'qemu-hugefsdir', 'defaults'])
|
||||
|
||||
|
||||
def check_optional_relations(configs):
|
||||
required_interfaces = {}
|
||||
if relation_ids('ceph'):
|
||||
required_interfaces['storage-backend'] = ['ceph']
|
||||
|
||||
if relation_ids('neutron-plugin'):
|
||||
required_interfaces['neutron-plugin'] = ['neutron-plugin']
|
||||
|
||||
if relation_ids('shared-db') or relation_ids('pgsql-db'):
|
||||
required_interfaces['database'] = ['shared-db', 'pgsql-db']
|
||||
|
||||
if required_interfaces:
|
||||
set_os_workload_status(configs, required_interfaces)
|
||||
return status_get()
|
||||
else:
|
||||
return 'unknown', 'No optional relations'
|
||||
|
@ -39,6 +39,11 @@ my_ip = {{ host_ip }}
|
||||
glance_api_servers = {{ glance_api_servers }}
|
||||
{% endif -%}
|
||||
|
||||
{% if metadata_shared_secret -%}
|
||||
neutron_metadata_proxy_shared_secret = {{ metadata_shared_secret }}
|
||||
service_neutron_metadata_proxy=True
|
||||
{% endif -%}
|
||||
|
||||
{% if console_vnc_type -%}
|
||||
vnc_enabled = True
|
||||
novnc_enabled = True
|
||||
|
@ -230,10 +230,19 @@ class NovaComputeContextTests(CharmTestCase):
|
||||
self.log = fake_log
|
||||
self.unit_get.return_value = '172.24.0.79'
|
||||
host_ip = context.HostIPContext()
|
||||
self.assertEquals(
|
||||
{'host_ip': '172.24.0.79'}, host_ip())
|
||||
self.assertEquals({'host_ip': '172.24.0.79'}, host_ip())
|
||||
self.unit_get.assert_called_with('private-address')
|
||||
|
||||
@patch.object(context, 'get_ipv6_addr')
|
||||
@patch('subprocess.call')
|
||||
def test_host_IP_context_ipv6(self, _call, mock_get_ipv6_addr):
|
||||
self.log = fake_log
|
||||
self.test_config.set('prefer-ipv6', True)
|
||||
mock_get_ipv6_addr.return_value = ['2001:db8:0:1::2']
|
||||
host_ip = context.HostIPContext()
|
||||
self.assertEquals({'host_ip': '2001:db8:0:1::2'}, host_ip())
|
||||
self.assertTrue(mock_get_ipv6_addr.called)
|
||||
|
||||
def test_metadata_service_ctxt(self):
|
||||
self.relation_ids.return_value = 'neutron-plugin:0'
|
||||
self.related_units.return_value = 'neutron-openvswitch/0'
|
||||
|
@ -6,6 +6,9 @@ import yaml
|
||||
from contextlib import contextmanager
|
||||
from mock import patch, MagicMock
|
||||
|
||||
patch('charmhelpers.contrib.openstack.utils.set_os_workload_status').start()
|
||||
patch('charmhelpers.core.hookenv.status_set').start()
|
||||
|
||||
|
||||
def load_config():
|
||||
'''
|
||||
|
Loading…
Reference in New Issue
Block a user