2017-11-22 15:22:04 +00:00
|
|
|
#!/usr/bin/env python3
|
2016-07-01 18:12:11 +01:00
|
|
|
#
|
|
|
|
# Copyright 2016 Canonical Ltd
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2012-12-12 09:18:54 -08:00
|
|
|
import os
|
|
|
|
import sys
|
2015-03-29 21:09:05 +01:00
|
|
|
from subprocess import (
|
|
|
|
check_call,
|
|
|
|
CalledProcessError,
|
|
|
|
)
|
2017-11-22 15:22:04 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
|
|
|
|
_path = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
_parent = os.path.abspath(os.path.join(_path, '..'))
|
|
|
|
|
|
|
|
|
|
|
|
def _add_path(path):
|
|
|
|
if path not in sys.path:
|
|
|
|
sys.path.insert(1, path)
|
|
|
|
|
|
|
|
|
|
|
|
_add_path(_parent)
|
|
|
|
|
2013-09-27 13:02:37 +01:00
|
|
|
|
2015-09-07 14:44:04 +01:00
|
|
|
from lib.swift_utils import (
|
2014-12-04 18:41:32 +00:00
|
|
|
SwiftProxyCharmException,
|
2013-09-27 13:02:37 +01:00
|
|
|
register_configs,
|
|
|
|
restart_map,
|
2014-11-17 13:57:33 +10:00
|
|
|
services,
|
2013-09-27 13:02:37 +01:00
|
|
|
determine_packages,
|
|
|
|
ensure_swift_dir,
|
2014-12-01 18:37:56 +00:00
|
|
|
SWIFT_RINGS,
|
|
|
|
get_www_dir,
|
2013-09-27 13:02:37 +01:00
|
|
|
initialize_ring,
|
|
|
|
SWIFT_HA_RES,
|
|
|
|
get_zone,
|
2013-09-27 13:16:22 +01:00
|
|
|
do_openstack_upgrade,
|
2014-12-01 18:37:56 +00:00
|
|
|
setup_ipv6,
|
2014-12-09 15:18:08 +00:00
|
|
|
update_rings,
|
2014-12-01 18:37:56 +00:00
|
|
|
balance_rings,
|
2014-12-09 22:57:39 +00:00
|
|
|
fully_synced,
|
2014-12-01 18:37:56 +00:00
|
|
|
sync_proxy_rings,
|
2014-12-02 17:08:55 +00:00
|
|
|
broadcast_rings_available,
|
2014-12-01 18:37:56 +00:00
|
|
|
mark_www_rings_deleted,
|
2014-12-04 18:41:32 +00:00
|
|
|
SwiftProxyClusterRPC,
|
2014-12-04 20:58:15 +00:00
|
|
|
get_first_available_value,
|
|
|
|
all_responses_equal,
|
2014-12-09 21:57:27 +00:00
|
|
|
ensure_www_dir_permissions,
|
2016-03-02 11:34:58 +00:00
|
|
|
sync_builders_and_rings_if_changed,
|
|
|
|
cluster_sync_rings,
|
|
|
|
is_most_recent_timestamp,
|
|
|
|
timestamps_available,
|
2015-10-08 01:24:59 +00:00
|
|
|
assess_status,
|
2016-09-08 11:08:47 -04:00
|
|
|
try_initialize_swauth,
|
2013-09-27 13:02:37 +01:00
|
|
|
)
|
|
|
|
|
2014-12-01 18:37:56 +00:00
|
|
|
import charmhelpers.contrib.openstack.utils as openstack
|
2016-06-15 12:02:45 -07:00
|
|
|
|
|
|
|
from charmhelpers.contrib.openstack.ha.utils import (
|
|
|
|
update_dns_ha_resource_params,
|
|
|
|
)
|
|
|
|
|
|
|
|
from charmhelpers.contrib.hahelpers.cluster import (
|
|
|
|
get_hacluster_config,
|
2014-12-01 18:37:56 +00:00
|
|
|
is_elected_leader,
|
2017-07-07 10:38:03 +02:00
|
|
|
determine_api_port,
|
2014-12-01 18:37:56 +00:00
|
|
|
)
|
2016-09-08 11:08:47 -04:00
|
|
|
|
2013-09-27 13:02:37 +01:00
|
|
|
from charmhelpers.core.hookenv import (
|
|
|
|
config,
|
2014-12-05 13:21:52 +00:00
|
|
|
local_unit,
|
2014-12-17 12:42:17 +00:00
|
|
|
remote_unit,
|
2013-09-27 13:02:37 +01:00
|
|
|
relation_set,
|
|
|
|
relation_ids,
|
|
|
|
relation_get,
|
2014-12-01 18:37:56 +00:00
|
|
|
related_units,
|
2014-10-20 13:43:39 +01:00
|
|
|
log,
|
2014-12-01 18:37:56 +00:00
|
|
|
DEBUG,
|
2014-10-21 12:45:36 +01:00
|
|
|
INFO,
|
2014-10-20 13:43:39 +01:00
|
|
|
WARNING,
|
2013-09-27 13:02:37 +01:00
|
|
|
Hooks, UnregisteredHookError,
|
2014-12-01 18:37:56 +00:00
|
|
|
open_port,
|
2015-10-08 01:24:59 +00:00
|
|
|
status_set,
|
2013-09-27 13:02:37 +01:00
|
|
|
)
|
|
|
|
from charmhelpers.core.host import (
|
2015-03-30 18:26:29 +01:00
|
|
|
service_reload,
|
2013-09-27 13:02:37 +01:00
|
|
|
service_restart,
|
2014-10-20 11:05:09 +01:00
|
|
|
service_stop,
|
|
|
|
service_start,
|
2013-09-27 13:02:37 +01:00
|
|
|
)
|
|
|
|
from charmhelpers.fetch import (
|
|
|
|
apt_install,
|
2014-12-01 18:37:56 +00:00
|
|
|
apt_update,
|
2017-07-31 15:34:32 +01:00
|
|
|
filter_installed_packages,
|
2013-09-27 13:02:37 +01:00
|
|
|
)
|
2013-09-27 17:11:20 +01:00
|
|
|
from charmhelpers.payload.execd import execd_preinstall
|
2014-07-14 15:03:48 +01:00
|
|
|
from charmhelpers.contrib.openstack.ip import (
|
|
|
|
canonical_url,
|
2014-12-01 18:37:56 +00:00
|
|
|
PUBLIC,
|
|
|
|
INTERNAL,
|
|
|
|
ADMIN,
|
2014-07-14 15:03:48 +01:00
|
|
|
)
|
2014-07-16 14:43:20 +01:00
|
|
|
from charmhelpers.contrib.network.ip import (
|
|
|
|
get_iface_for_address,
|
2014-09-26 12:35:16 +01:00
|
|
|
get_netmask_for_address,
|
2017-05-05 10:35:24 -07:00
|
|
|
get_relation_ip,
|
2014-12-01 18:37:56 +00:00
|
|
|
is_ipv6,
|
2014-09-30 15:48:30 +08:00
|
|
|
format_ipv6_addr,
|
2014-07-16 14:43:20 +01:00
|
|
|
)
|
2014-09-30 09:27:09 +01:00
|
|
|
from charmhelpers.contrib.openstack.context import ADDRESS_TYPES
|
2015-01-12 12:04:01 +00:00
|
|
|
from charmhelpers.contrib.charmsupport import nrpe
|
2016-03-22 21:00:50 +00:00
|
|
|
from charmhelpers.contrib.hardening.harden import harden
|
2014-10-29 22:30:36 -05:00
|
|
|
|
2013-02-27 16:07:46 +00:00
|
|
|
extra_pkgs = [
|
|
|
|
"haproxy",
|
|
|
|
"python-jinja2"
|
2013-09-27 13:02:37 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
hooks = Hooks()
|
|
|
|
CONFIGS = register_configs()
|
2016-04-11 13:56:39 +00:00
|
|
|
restart_on_change = openstack.pausable_restart_on_change
|
2013-03-12 11:17:32 +00:00
|
|
|
|
2013-09-27 13:02:37 +01:00
|
|
|
|
2015-09-22 14:56:33 +01:00
|
|
|
@hooks.hook('install.real')
|
2016-03-22 21:00:50 +00:00
|
|
|
@harden()
|
2012-12-12 09:18:54 -08:00
|
|
|
def install():
|
2015-10-08 01:24:59 +00:00
|
|
|
status_set('maintenance', 'Executing pre-install')
|
2013-09-27 17:11:20 +01:00
|
|
|
execd_preinstall()
|
2013-09-27 13:02:37 +01:00
|
|
|
src = config('openstack-origin')
|
2012-12-12 09:18:54 -08:00
|
|
|
if src != 'distro':
|
|
|
|
openstack.configure_installation_source(src)
|
2014-12-01 18:37:56 +00:00
|
|
|
|
2015-10-08 01:24:59 +00:00
|
|
|
status_set('maintenance', 'Installing apt packages')
|
2013-09-27 13:02:37 +01:00
|
|
|
apt_update(fatal=True)
|
2012-12-12 09:18:54 -08:00
|
|
|
rel = openstack.get_os_codename_install_source(src)
|
2013-09-27 13:02:37 +01:00
|
|
|
pkgs = determine_packages(rel)
|
|
|
|
apt_install(pkgs, fatal=True)
|
|
|
|
apt_install(extra_pkgs, fatal=True)
|
|
|
|
ensure_swift_dir()
|
2012-12-12 09:18:54 -08:00
|
|
|
# configure a directory on webserver for distributing rings.
|
2014-12-09 21:57:27 +00:00
|
|
|
ensure_www_dir_permissions(get_www_dir())
|
2012-12-12 09:18:54 -08:00
|
|
|
|
|
|
|
|
2014-12-01 18:37:56 +00:00
|
|
|
@hooks.hook('config-changed')
|
2016-04-11 13:56:39 +00:00
|
|
|
@restart_on_change(restart_map())
|
2016-03-22 21:00:50 +00:00
|
|
|
@harden()
|
2014-12-01 18:37:56 +00:00
|
|
|
def config_changed():
|
2015-10-10 14:39:17 -07:00
|
|
|
if is_elected_leader(SWIFT_HA_RES):
|
|
|
|
log("Leader established, generating ring builders", level=INFO)
|
|
|
|
# initialize new storage rings.
|
2017-11-22 15:22:04 +00:00
|
|
|
for path in SWIFT_RINGS.values():
|
2015-10-10 14:39:17 -07:00
|
|
|
if not os.path.exists(path):
|
|
|
|
initialize_ring(path,
|
|
|
|
config('partition-power'),
|
|
|
|
config('replicas'),
|
|
|
|
config('min-hours'))
|
|
|
|
|
2014-12-01 18:37:56 +00:00
|
|
|
if config('prefer-ipv6'):
|
2015-10-08 01:24:59 +00:00
|
|
|
status_set('maintenance', 'Configuring ipv6')
|
2014-12-01 18:37:56 +00:00
|
|
|
setup_ipv6()
|
|
|
|
|
|
|
|
configure_https()
|
|
|
|
open_port(config('bind-port'))
|
2015-01-09 10:54:27 +00:00
|
|
|
update_nrpe_config()
|
2014-12-01 18:37:56 +00:00
|
|
|
|
|
|
|
# Determine whether or not we should do an upgrade.
|
2015-09-23 09:28:19 -07:00
|
|
|
if not config('action-managed-upgrade') and \
|
|
|
|
openstack.openstack_upgrade_available('python-swift'):
|
2014-12-01 18:37:56 +00:00
|
|
|
do_openstack_upgrade(CONFIGS)
|
2015-10-08 01:24:59 +00:00
|
|
|
status_set('maintenance', 'Running openstack upgrade')
|
2014-12-01 18:37:56 +00:00
|
|
|
|
2016-03-02 11:34:58 +00:00
|
|
|
status_set('maintenance', 'Updating and (maybe) balancing rings')
|
2017-09-12 16:08:54 -06:00
|
|
|
update_rings(min_part_hours=config('min-hours'))
|
2014-12-01 18:37:56 +00:00
|
|
|
|
2014-12-09 21:26:55 +00:00
|
|
|
if not config('disable-ring-balance') and is_elected_leader(SWIFT_HA_RES):
|
2014-12-09 15:18:08 +00:00
|
|
|
# Try ring balance. If rings are balanced, no sync will occur.
|
|
|
|
balance_rings()
|
2014-12-01 18:37:56 +00:00
|
|
|
|
|
|
|
for r_id in relation_ids('identity-service'):
|
|
|
|
keystone_joined(relid=r_id)
|
|
|
|
|
2017-04-12 12:39:15 +01:00
|
|
|
for r_id in relation_ids('cluster'):
|
|
|
|
cluster_joined(relation_id=r_id)
|
|
|
|
|
2015-10-31 00:16:58 +02:00
|
|
|
for r_id in relation_ids('object-store'):
|
|
|
|
object_store_joined(relation_id=r_id)
|
2017-07-31 15:34:32 +01:00
|
|
|
|
|
|
|
for r_id in relation_ids('amqp'):
|
|
|
|
amqp_joined(relation_id=r_id)
|
|
|
|
|
2016-09-08 11:08:47 -04:00
|
|
|
try_initialize_swauth()
|
2015-10-31 00:16:58 +02:00
|
|
|
|
2012-12-12 09:18:54 -08:00
|
|
|
|
2013-09-27 13:02:37 +01:00
|
|
|
@hooks.hook('identity-service-relation-joined')
|
2012-12-12 09:18:54 -08:00
|
|
|
def keystone_joined(relid=None):
|
2013-09-27 13:02:37 +01:00
|
|
|
port = config('bind-port')
|
2017-11-22 15:22:04 +00:00
|
|
|
admin_url = '{}:{}'.format(canonical_url(CONFIGS, ADMIN), port)
|
|
|
|
internal_url = ('{}:{}/v1/AUTH_$(tenant_id)s'
|
|
|
|
.format(canonical_url(CONFIGS, INTERNAL), port))
|
|
|
|
public_url = ('{}:{}/v1/AUTH_$(tenant_id)s'
|
|
|
|
.format(canonical_url(CONFIGS, PUBLIC), port))
|
2015-04-07 22:47:03 +01:00
|
|
|
region = config('region')
|
|
|
|
|
2017-11-22 15:22:04 +00:00
|
|
|
s3_public_url = ('{}:{}'.format(canonical_url(CONFIGS, PUBLIC), port))
|
|
|
|
s3_internal_url = ('{}:{}'.format(canonical_url(CONFIGS, INTERNAL), port))
|
|
|
|
s3_admin_url = '{}:{}'.format(canonical_url(CONFIGS, ADMIN), port)
|
2016-06-14 11:20:45 -04:00
|
|
|
|
2016-12-02 12:08:04 +01:00
|
|
|
relation_set(relation_id=relid,
|
2016-06-14 11:20:45 -04:00
|
|
|
region=None, public_url=None,
|
|
|
|
internal_url=None, admin_url=None, service=None,
|
|
|
|
swift_service='swift', swift_region=region,
|
|
|
|
swift_public_url=public_url,
|
|
|
|
swift_internal_url=internal_url,
|
|
|
|
swift_admin_url=admin_url,
|
|
|
|
s3_service='s3', s3_region=region,
|
|
|
|
s3_public_url=s3_public_url,
|
|
|
|
s3_admin_url=s3_admin_url,
|
|
|
|
s3_internal_url=s3_internal_url)
|
2012-12-12 09:18:54 -08:00
|
|
|
|
|
|
|
|
2013-09-27 13:02:37 +01:00
|
|
|
@hooks.hook('identity-service-relation-changed')
|
2016-04-11 13:56:39 +00:00
|
|
|
@restart_on_change(restart_map())
|
2012-12-12 09:18:54 -08:00
|
|
|
def keystone_changed():
|
2013-09-27 13:02:37 +01:00
|
|
|
configure_https()
|
2012-12-12 09:18:54 -08:00
|
|
|
|
|
|
|
|
2014-12-01 18:37:56 +00:00
|
|
|
@hooks.hook('swift-storage-relation-joined')
|
2017-11-02 09:55:47 +00:00
|
|
|
def storage_joined(rid=None):
|
2014-12-01 18:37:56 +00:00
|
|
|
if not is_elected_leader(SWIFT_HA_RES):
|
|
|
|
log("New storage relation joined - stopping proxy until ring builder "
|
|
|
|
"synced", level=INFO)
|
|
|
|
service_stop('swift-proxy')
|
2012-12-12 09:18:54 -08:00
|
|
|
|
2014-12-04 15:49:24 +00:00
|
|
|
# This unit is not currently responsible for distributing rings but
|
|
|
|
# may become so at some time in the future so we do this to avoid the
|
|
|
|
# possibility of storage nodes getting out-of-date rings by deprecating
|
|
|
|
# any existing ones from the www dir.
|
2014-12-01 18:37:56 +00:00
|
|
|
mark_www_rings_deleted()
|
2016-09-08 11:08:47 -04:00
|
|
|
try_initialize_swauth()
|
2012-12-12 09:18:54 -08:00
|
|
|
|
2017-11-02 09:55:47 +00:00
|
|
|
# NOTE(jamespage): Ensure private-address is set to any network-space
|
|
|
|
# binding provided by the charm user.
|
|
|
|
relation_set(
|
|
|
|
relation_id=rid,
|
|
|
|
relation_settings={'private-address': get_relation_ip('swift-storage')}
|
|
|
|
)
|
|
|
|
|
2013-03-12 11:17:32 +00:00
|
|
|
|
2015-11-24 13:35:26 +00:00
|
|
|
def get_host_ip(rid=None, unit=None):
|
|
|
|
addr = relation_get('private-address', rid=rid, unit=unit)
|
|
|
|
if config('prefer-ipv6'):
|
|
|
|
host_ip = format_ipv6_addr(addr)
|
|
|
|
if host_ip:
|
|
|
|
return host_ip
|
|
|
|
else:
|
|
|
|
msg = ("Did not get IPv6 address from storage relation "
|
2017-11-22 15:22:04 +00:00
|
|
|
"(got={})".format(addr))
|
2015-11-24 13:35:26 +00:00
|
|
|
log(msg, level=WARNING)
|
|
|
|
|
|
|
|
return openstack.get_host_ip(addr)
|
|
|
|
|
|
|
|
|
|
|
|
def update_rsync_acls():
|
|
|
|
"""Get Host IP of each storage unit and broadcast acl to all units."""
|
|
|
|
hosts = []
|
|
|
|
|
|
|
|
if not is_elected_leader(SWIFT_HA_RES):
|
|
|
|
log("Skipping rsync acl update since not leader", level=DEBUG)
|
|
|
|
return
|
|
|
|
|
|
|
|
# Get all unit addresses
|
|
|
|
for rid in relation_ids('swift-storage'):
|
|
|
|
for unit in related_units(rid):
|
|
|
|
hosts.append(get_host_ip(rid=rid, unit=unit))
|
|
|
|
|
|
|
|
rsync_hosts = ' '.join(hosts)
|
2017-11-22 15:22:04 +00:00
|
|
|
log("Broadcasting acl '{}' to all storage units".format(rsync_hosts),
|
2015-11-24 13:35:26 +00:00
|
|
|
level=DEBUG)
|
|
|
|
# We add a timestamp so that the storage units know which is the newest
|
|
|
|
settings = {'rsync_allowed_hosts': rsync_hosts,
|
|
|
|
'timestamp': time.time()}
|
|
|
|
for rid in relation_ids('swift-storage'):
|
2015-11-27 09:48:45 +00:00
|
|
|
relation_set(relation_id=rid, **settings)
|
2015-11-24 13:35:26 +00:00
|
|
|
|
|
|
|
|
2013-09-27 13:02:37 +01:00
|
|
|
@hooks.hook('swift-storage-relation-changed')
|
2016-04-11 13:56:39 +00:00
|
|
|
@restart_on_change(restart_map())
|
2012-12-18 11:59:19 -08:00
|
|
|
def storage_changed():
|
2014-12-09 15:18:08 +00:00
|
|
|
"""Storage relation.
|
|
|
|
|
|
|
|
Only the leader unit can update and distribute rings so if we are not the
|
|
|
|
leader we ignore this event and wait for a resync request from the leader.
|
|
|
|
"""
|
2014-12-01 18:37:56 +00:00
|
|
|
if not is_elected_leader(SWIFT_HA_RES):
|
2016-03-02 11:34:58 +00:00
|
|
|
log("Not the leader - deferring storage relation change to leader "
|
|
|
|
"unit.", level=DEBUG)
|
2014-12-01 18:37:56 +00:00
|
|
|
return
|
|
|
|
|
2016-03-02 11:34:58 +00:00
|
|
|
log("Storage relation changed -processing", level=DEBUG)
|
2015-11-24 13:35:26 +00:00
|
|
|
host_ip = get_host_ip()
|
|
|
|
if not host_ip:
|
|
|
|
log("No host ip found in storage relation - deferring storage "
|
|
|
|
"relation", level=WARNING)
|
|
|
|
return
|
|
|
|
|
|
|
|
update_rsync_acls()
|
2014-09-18 21:16:28 +08:00
|
|
|
|
2013-09-27 13:02:37 +01:00
|
|
|
zone = get_zone(config('zone-assignment'))
|
2012-12-12 09:18:54 -08:00
|
|
|
node_settings = {
|
2014-08-13 20:15:41 +08:00
|
|
|
'ip': host_ip,
|
2012-12-14 15:07:01 -08:00
|
|
|
'zone': zone,
|
2013-09-27 13:02:37 +01:00
|
|
|
'account_port': relation_get('account_port'),
|
|
|
|
'object_port': relation_get('object_port'),
|
|
|
|
'container_port': relation_get('container_port'),
|
2012-12-12 09:18:54 -08:00
|
|
|
}
|
2014-10-20 19:27:50 +01:00
|
|
|
|
2017-11-22 15:22:04 +00:00
|
|
|
if None in node_settings.values():
|
|
|
|
missing = [k for k, v in node_settings.items() if v is None]
|
2014-12-01 18:37:56 +00:00
|
|
|
log("Relation not ready - some required values not provided by "
|
2017-11-22 15:22:04 +00:00
|
|
|
"relation (missing={})".format(', '.join(missing)), level=INFO)
|
2012-12-12 09:18:54 -08:00
|
|
|
return None
|
|
|
|
|
|
|
|
for k in ['zone', 'account_port', 'object_port', 'container_port']:
|
|
|
|
node_settings[k] = int(node_settings[k])
|
|
|
|
|
2013-09-27 13:02:37 +01:00
|
|
|
CONFIGS.write_all()
|
2012-12-12 09:18:54 -08:00
|
|
|
|
2014-12-01 18:37:56 +00:00
|
|
|
# Allow for multiple devs per unit, passed along as a : separated list
|
2014-12-09 15:18:08 +00:00
|
|
|
# Update and balance rings.
|
2015-10-12 15:02:35 -07:00
|
|
|
nodes = []
|
2014-12-09 15:33:54 +00:00
|
|
|
devs = relation_get('device')
|
|
|
|
if devs:
|
2015-10-12 15:02:35 -07:00
|
|
|
for dev in devs.split(':'):
|
|
|
|
node = {k: v for k, v in node_settings.items()}
|
|
|
|
node['device'] = dev
|
|
|
|
nodes.append(node)
|
2012-12-12 09:18:54 -08:00
|
|
|
|
2017-09-12 16:08:54 -06:00
|
|
|
update_rings(nodes)
|
2016-04-11 13:56:39 +00:00
|
|
|
if not openstack.is_unit_paused_set():
|
2015-09-09 11:55:01 +01:00
|
|
|
# Restart proxy here in case no config changes made (so
|
2016-04-11 13:56:39 +00:00
|
|
|
# restart_on_change() ineffective).
|
2015-09-09 11:55:01 +01:00
|
|
|
service_restart('swift-proxy')
|
2012-12-12 09:18:54 -08:00
|
|
|
|
2013-03-12 11:17:32 +00:00
|
|
|
|
2013-09-27 13:02:37 +01:00
|
|
|
@hooks.hook('swift-storage-relation-broken')
|
2016-04-11 13:56:39 +00:00
|
|
|
@restart_on_change(restart_map())
|
2012-12-18 11:59:19 -08:00
|
|
|
def storage_broken():
|
2013-09-27 13:02:37 +01:00
|
|
|
CONFIGS.write_all()
|
2012-12-12 09:18:54 -08:00
|
|
|
|
2013-03-12 11:17:32 +00:00
|
|
|
|
2015-10-31 00:16:58 +02:00
|
|
|
@hooks.hook('object-store-relation-joined')
|
|
|
|
def object_store_joined(relation_id=None):
|
|
|
|
relation_data = {
|
|
|
|
'swift-url':
|
|
|
|
"{}:{}".format(canonical_url(CONFIGS, INTERNAL), config('bind-port'))
|
|
|
|
}
|
|
|
|
|
|
|
|
relation_set(relation_id=relation_id, **relation_data)
|
|
|
|
|
|
|
|
|
2014-09-26 12:35:16 +01:00
|
|
|
@hooks.hook('cluster-relation-joined')
|
|
|
|
def cluster_joined(relation_id=None):
|
2017-04-12 12:39:15 +01:00
|
|
|
settings = {}
|
2017-05-05 10:35:24 -07:00
|
|
|
|
2014-09-30 09:27:09 +01:00
|
|
|
for addr_type in ADDRESS_TYPES:
|
2017-05-05 10:35:24 -07:00
|
|
|
address = get_relation_ip(
|
|
|
|
addr_type,
|
|
|
|
cidr_network=config('os-{}-network'.format(addr_type)))
|
2014-09-30 09:27:09 +01:00
|
|
|
if address:
|
2017-04-12 12:39:15 +01:00
|
|
|
settings['{}-address'.format(addr_type)] = address
|
2014-10-20 11:05:09 +01:00
|
|
|
|
2017-05-05 10:35:24 -07:00
|
|
|
settings['private-address'] = get_relation_ip('cluster')
|
2017-04-12 12:39:15 +01:00
|
|
|
|
|
|
|
relation_set(relation_id=relation_id, relation_settings=settings)
|
2014-10-20 11:05:09 +01:00
|
|
|
|
|
|
|
|
2016-03-02 11:34:58 +00:00
|
|
|
def is_all_peers_stopped(responses):
|
2014-12-04 15:49:24 +00:00
|
|
|
"""Establish whether all peers have stopped their proxy services.
|
2014-12-02 14:40:58 +00:00
|
|
|
|
2014-12-04 18:51:43 +00:00
|
|
|
Each peer unit will set stop-proxy-service-ack to rq value to indicate that
|
2014-12-04 15:49:24 +00:00
|
|
|
it has stopped its proxy service. We wait for all units to be stopped
|
|
|
|
before triggering a sync. Peer services will be restarted once their rings
|
|
|
|
are synced with the leader.
|
2014-12-02 14:40:58 +00:00
|
|
|
|
|
|
|
To be safe, default expectation is that api is still running.
|
|
|
|
"""
|
2014-12-05 13:32:28 +00:00
|
|
|
rq_key = SwiftProxyClusterRPC.KEY_STOP_PROXY_SVC
|
|
|
|
ack_key = SwiftProxyClusterRPC.KEY_STOP_PROXY_SVC_ACK
|
|
|
|
token = relation_get(attribute=rq_key, unit=local_unit())
|
|
|
|
if not token or token != responses[0].get(ack_key):
|
2017-11-22 15:22:04 +00:00
|
|
|
log("Token mismatch, rq and ack tokens differ (expected ack={}, "
|
|
|
|
"got={})".format(token, responses[0].get(ack_key)), level=DEBUG)
|
2014-12-05 13:21:52 +00:00
|
|
|
return False
|
|
|
|
|
2014-12-05 13:32:28 +00:00
|
|
|
if not all_responses_equal(responses, ack_key):
|
2016-03-02 11:34:58 +00:00
|
|
|
log("Not all ack responses are equal. Either we are still waiting "
|
|
|
|
"for responses or we were not the request originator.",
|
|
|
|
level=DEBUG)
|
2014-12-02 14:40:58 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
2014-12-02 14:21:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
def cluster_leader_actions():
|
2014-12-04 16:47:09 +00:00
|
|
|
"""Cluster relation hook actions to be performed by leader units.
|
|
|
|
|
|
|
|
NOTE: must be called by leader from cluster relation hook.
|
|
|
|
"""
|
2017-11-22 15:22:04 +00:00
|
|
|
log("Cluster changed by unit={} (local is leader)".format(remote_unit()),
|
2014-12-17 12:42:17 +00:00
|
|
|
level=DEBUG)
|
|
|
|
|
2016-03-02 11:34:58 +00:00
|
|
|
rx_settings = relation_get() or {}
|
|
|
|
tx_settings = relation_get(unit=local_unit()) or {}
|
2014-12-17 10:17:50 +00:00
|
|
|
|
2016-03-02 11:34:58 +00:00
|
|
|
rx_rq_token = rx_settings.get(SwiftProxyClusterRPC.KEY_STOP_PROXY_SVC)
|
|
|
|
rx_ack_token = rx_settings.get(SwiftProxyClusterRPC.KEY_STOP_PROXY_SVC_ACK)
|
|
|
|
|
|
|
|
tx_rq_token = tx_settings.get(SwiftProxyClusterRPC.KEY_STOP_PROXY_SVC)
|
|
|
|
tx_ack_token = tx_settings.get(SwiftProxyClusterRPC.KEY_STOP_PROXY_SVC_ACK)
|
|
|
|
|
|
|
|
rx_leader_changed = \
|
|
|
|
rx_settings.get(SwiftProxyClusterRPC.KEY_NOTIFY_LEADER_CHANGED)
|
|
|
|
if rx_leader_changed:
|
|
|
|
log("Leader change notification received and this is leader so "
|
|
|
|
"retrying sync.", level=INFO)
|
|
|
|
# FIXME: check that we were previously part of a successful sync to
|
|
|
|
# ensure we have good rings.
|
|
|
|
cluster_sync_rings(peers_only=tx_settings.get('peers-only', False),
|
|
|
|
token=rx_leader_changed)
|
|
|
|
return
|
|
|
|
|
|
|
|
rx_resync_request = \
|
|
|
|
rx_settings.get(SwiftProxyClusterRPC.KEY_REQUEST_RESYNC)
|
|
|
|
resync_request_ack_key = SwiftProxyClusterRPC.KEY_REQUEST_RESYNC_ACK
|
|
|
|
tx_resync_request_ack = tx_settings.get(resync_request_ack_key)
|
|
|
|
if rx_resync_request and tx_resync_request_ack != rx_resync_request:
|
2017-11-22 15:22:04 +00:00
|
|
|
log("Unit '{}' has requested a resync".format(remote_unit()),
|
2016-03-02 11:34:58 +00:00
|
|
|
level=INFO)
|
|
|
|
cluster_sync_rings(peers_only=True)
|
|
|
|
relation_set(**{resync_request_ack_key: rx_resync_request})
|
2014-12-17 10:17:50 +00:00
|
|
|
return
|
2016-03-02 11:34:58 +00:00
|
|
|
|
|
|
|
# If we have received an ack token ensure it is not associated with a
|
|
|
|
# request we received from another peer. If it is, this would indicate
|
|
|
|
# a leadership change during a sync and this unit will abort the sync or
|
|
|
|
# attempt to restore the original leader so to be able to complete the
|
|
|
|
# sync.
|
|
|
|
|
|
|
|
if rx_ack_token and rx_ack_token == tx_rq_token:
|
2014-12-05 12:44:14 +00:00
|
|
|
# Find out if all peer units have been stopped.
|
|
|
|
responses = []
|
|
|
|
for rid in relation_ids('cluster'):
|
|
|
|
for unit in related_units(rid):
|
|
|
|
responses.append(relation_get(rid=rid, unit=unit))
|
|
|
|
|
|
|
|
# Ensure all peers stopped before starting sync
|
2016-03-02 11:34:58 +00:00
|
|
|
if is_all_peers_stopped(responses):
|
2014-12-05 12:44:14 +00:00
|
|
|
key = 'peers-only'
|
|
|
|
if not all_responses_equal(responses, key, must_exist=False):
|
|
|
|
msg = ("Did not get equal response from every peer unit for "
|
2017-11-22 15:22:04 +00:00
|
|
|
"'{}'".format(key))
|
2014-12-05 12:44:14 +00:00
|
|
|
raise SwiftProxyCharmException(msg)
|
|
|
|
|
2016-03-02 11:34:58 +00:00
|
|
|
peers_only = bool(get_first_available_value(responses, key,
|
|
|
|
default=0))
|
2017-11-22 15:22:04 +00:00
|
|
|
log("Syncing rings and builders (peers-only={})"
|
|
|
|
.format(peers_only), level=DEBUG)
|
2016-03-02 11:34:58 +00:00
|
|
|
broadcast_rings_available(broker_token=rx_ack_token,
|
|
|
|
storage=not peers_only)
|
2014-12-05 12:44:14 +00:00
|
|
|
else:
|
2016-03-02 11:34:58 +00:00
|
|
|
key = SwiftProxyClusterRPC.KEY_STOP_PROXY_SVC_ACK
|
|
|
|
acks = ', '.join([rsp[key] for rsp in responses if key in rsp])
|
2014-12-05 12:44:14 +00:00
|
|
|
log("Not all peer apis stopped - skipping sync until all peers "
|
2017-11-22 15:22:04 +00:00
|
|
|
"ready (current='{}', token='{}')".format(acks, tx_ack_token),
|
2016-03-02 11:34:58 +00:00
|
|
|
level=INFO)
|
|
|
|
elif ((rx_ack_token and (rx_ack_token == tx_ack_token)) or
|
|
|
|
(rx_rq_token and (rx_rq_token == rx_ack_token))):
|
|
|
|
log("It appears that the cluster leader has changed mid-sync - "
|
|
|
|
"stopping proxy service", level=WARNING)
|
|
|
|
service_stop('swift-proxy')
|
|
|
|
broker = rx_settings.get('builder-broker')
|
|
|
|
if broker:
|
|
|
|
# If we get here, manual intervention will be required in order
|
|
|
|
# to restore the cluster.
|
2017-11-22 15:22:04 +00:00
|
|
|
raise SwiftProxyCharmException(
|
|
|
|
"Failed to restore previous broker '{}' as leader"
|
|
|
|
.format(broker))
|
2016-03-02 11:34:58 +00:00
|
|
|
else:
|
2017-11-22 15:22:04 +00:00
|
|
|
raise SwiftProxyCharmException(
|
|
|
|
"No builder-broker on rx_settings relation from '{}' - "
|
|
|
|
"unable to attempt leader restore".format(remote_unit()))
|
2016-03-02 11:34:58 +00:00
|
|
|
else:
|
|
|
|
log("Not taking any sync actions", level=DEBUG)
|
2014-12-02 14:21:47 +00:00
|
|
|
|
|
|
|
CONFIGS.write_all()
|
2014-12-01 18:37:56 +00:00
|
|
|
|
|
|
|
|
2014-12-02 14:21:47 +00:00
|
|
|
def cluster_non_leader_actions():
|
2014-12-04 16:47:09 +00:00
|
|
|
"""Cluster relation hook actions to be performed by non-leader units.
|
|
|
|
|
|
|
|
NOTE: must be called by non-leader from cluster relation hook.
|
|
|
|
"""
|
2017-11-22 15:22:04 +00:00
|
|
|
log("Cluster changed by unit={} (local is non-leader)"
|
|
|
|
.format(remote_unit()), level=DEBUG)
|
2016-03-02 11:34:58 +00:00
|
|
|
rx_settings = relation_get() or {}
|
|
|
|
tx_settings = relation_get(unit=local_unit()) or {}
|
2014-12-02 14:21:47 +00:00
|
|
|
|
2016-03-02 11:34:58 +00:00
|
|
|
token = rx_settings.get(SwiftProxyClusterRPC.KEY_NOTIFY_LEADER_CHANGED)
|
2014-12-04 20:00:00 +00:00
|
|
|
if token:
|
2016-03-02 11:34:58 +00:00
|
|
|
log("Leader-changed notification received from peer unit. Since "
|
|
|
|
"this most likely occurred during a ring sync proxies will "
|
|
|
|
"be disabled until the leader is restored and a fresh sync "
|
|
|
|
"request is set out", level=WARNING)
|
|
|
|
service_stop("swift-proxy")
|
|
|
|
return
|
|
|
|
|
|
|
|
rx_rq_token = rx_settings.get(SwiftProxyClusterRPC.KEY_STOP_PROXY_SVC)
|
|
|
|
|
|
|
|
# Check whether we have been requested to stop proxy service
|
|
|
|
if rx_rq_token:
|
2017-11-22 15:22:04 +00:00
|
|
|
log("Peer request to stop proxy service received ({}) - sending ack"
|
|
|
|
.format(rx_rq_token), level=INFO)
|
2014-12-01 18:37:56 +00:00
|
|
|
service_stop('swift-proxy')
|
2016-03-02 11:34:58 +00:00
|
|
|
peers_only = rx_settings.get('peers-only', None)
|
|
|
|
rq = SwiftProxyClusterRPC().stop_proxy_ack(echo_token=rx_rq_token,
|
2014-12-04 20:00:00 +00:00
|
|
|
echo_peers_only=peers_only)
|
2014-12-04 19:00:54 +00:00
|
|
|
relation_set(relation_settings=rq)
|
2014-12-01 18:37:56 +00:00
|
|
|
return
|
2013-02-27 16:07:46 +00:00
|
|
|
|
2014-12-02 14:21:47 +00:00
|
|
|
# Check if there are any builder files we can sync from the leader.
|
2016-03-02 11:34:58 +00:00
|
|
|
broker = rx_settings.get('builder-broker', None)
|
|
|
|
broker_token = rx_settings.get('broker-token', None)
|
|
|
|
broker_timestamp = rx_settings.get('broker-timestamp', None)
|
|
|
|
tx_ack_token = tx_settings.get(SwiftProxyClusterRPC.KEY_STOP_PROXY_SVC_ACK)
|
2014-12-01 18:37:56 +00:00
|
|
|
if not broker:
|
2016-03-02 11:34:58 +00:00
|
|
|
log("No ring/builder update available", level=DEBUG)
|
2016-04-11 13:56:39 +00:00
|
|
|
if not openstack.is_unit_paused_set():
|
2015-09-09 11:55:01 +01:00
|
|
|
service_start('swift-proxy')
|
2016-03-02 11:34:58 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
elif broker_token:
|
|
|
|
if tx_ack_token:
|
|
|
|
if broker_token == tx_ack_token:
|
2017-11-22 15:22:04 +00:00
|
|
|
log("Broker and ACK tokens match ({})".format(broker_token),
|
2016-03-02 11:34:58 +00:00
|
|
|
level=DEBUG)
|
|
|
|
else:
|
|
|
|
log("Received ring/builder update notification but tokens do "
|
2017-11-22 15:22:04 +00:00
|
|
|
"not match (broker-token={}/ack-token={})"
|
|
|
|
.format(broker_token, tx_ack_token), level=WARNING)
|
2016-03-02 11:34:58 +00:00
|
|
|
return
|
|
|
|
else:
|
|
|
|
log("Broker token available without handshake, assuming we just "
|
|
|
|
"joined and rings won't change", level=DEBUG)
|
|
|
|
else:
|
|
|
|
log("Not taking any sync actions", level=DEBUG)
|
|
|
|
return
|
|
|
|
|
|
|
|
# If we upgrade from cluster that did not use timestamps, the new peer will
|
|
|
|
# need to request a re-sync from the leader
|
|
|
|
if not is_most_recent_timestamp(broker_timestamp):
|
|
|
|
if not timestamps_available(excluded_unit=remote_unit()):
|
|
|
|
log("Requesting resync")
|
|
|
|
rq = SwiftProxyClusterRPC().request_resync(broker_token)
|
|
|
|
relation_set(relation_settings=rq)
|
|
|
|
else:
|
|
|
|
log("Did not receive most recent broker timestamp but timestamps "
|
|
|
|
"are available - waiting for next timestamp", level=INFO)
|
|
|
|
|
2014-12-01 18:37:56 +00:00
|
|
|
return
|
|
|
|
|
2016-03-02 11:34:58 +00:00
|
|
|
log("Ring/builder update available", level=DEBUG)
|
|
|
|
builders_only = int(rx_settings.get('sync-only-builders', 0))
|
2014-12-01 18:37:56 +00:00
|
|
|
path = os.path.basename(get_www_dir())
|
|
|
|
try:
|
2017-11-22 15:22:04 +00:00
|
|
|
sync_proxy_rings('http://{}/{}'.format(broker, path),
|
2014-12-09 22:57:39 +00:00
|
|
|
rings=not builders_only)
|
2015-03-29 21:09:05 +01:00
|
|
|
except CalledProcessError:
|
2014-12-01 18:37:56 +00:00
|
|
|
log("Ring builder sync failed, builders not yet available - "
|
|
|
|
"leader not ready?", level=WARNING)
|
2016-03-02 11:34:58 +00:00
|
|
|
return
|
2014-12-01 18:37:56 +00:00
|
|
|
|
2014-12-09 22:57:39 +00:00
|
|
|
# Re-enable the proxy once all builders and rings are synced
|
|
|
|
if fully_synced():
|
2014-12-01 18:37:56 +00:00
|
|
|
log("Ring builders synced - starting proxy", level=INFO)
|
|
|
|
CONFIGS.write_all()
|
2016-04-11 13:56:39 +00:00
|
|
|
if not openstack.is_unit_paused_set():
|
2015-09-09 11:55:01 +01:00
|
|
|
service_start('swift-proxy')
|
2014-12-01 18:37:56 +00:00
|
|
|
else:
|
2014-12-09 22:57:39 +00:00
|
|
|
log("Not all builders and rings synced yet - waiting for peer sync "
|
|
|
|
"before starting proxy", level=INFO)
|
2013-02-27 16:07:46 +00:00
|
|
|
|
2013-02-27 16:18:34 +00:00
|
|
|
|
2015-03-11 15:34:20 +00:00
|
|
|
@hooks.hook('cluster-relation-changed')
|
2016-04-11 13:56:39 +00:00
|
|
|
@restart_on_change(restart_map())
|
2013-02-27 16:07:46 +00:00
|
|
|
def cluster_changed():
|
2014-12-02 14:21:47 +00:00
|
|
|
if is_elected_leader(SWIFT_HA_RES):
|
|
|
|
cluster_leader_actions()
|
|
|
|
else:
|
|
|
|
cluster_non_leader_actions()
|
2013-02-27 16:07:46 +00:00
|
|
|
|
|
|
|
|
2013-09-27 13:02:37 +01:00
|
|
|
@hooks.hook('ha-relation-changed')
|
2016-03-02 11:34:58 +00:00
|
|
|
@sync_builders_and_rings_if_changed
|
2013-02-27 16:07:46 +00:00
|
|
|
def ha_relation_changed():
|
2013-09-27 13:02:37 +01:00
|
|
|
clustered = relation_get('clustered')
|
2015-03-10 11:43:33 +00:00
|
|
|
if clustered:
|
2014-12-01 18:37:56 +00:00
|
|
|
log("Cluster configured, notifying other services and updating "
|
|
|
|
"keystone endpoint configuration", level=INFO)
|
2013-02-27 16:07:46 +00:00
|
|
|
# Tell all related services to start using
|
2013-03-01 23:20:05 +00:00
|
|
|
# the VIP instead
|
2013-09-27 13:02:37 +01:00
|
|
|
for r_id in relation_ids('identity-service'):
|
2013-02-27 16:07:46 +00:00
|
|
|
keystone_joined(relid=r_id)
|
|
|
|
|
|
|
|
|
2013-09-27 13:02:37 +01:00
|
|
|
@hooks.hook('ha-relation-joined')
|
2016-06-15 12:02:45 -07:00
|
|
|
def ha_relation_joined(relation_id=None):
|
2013-02-27 16:07:46 +00:00
|
|
|
# Obtain the config values necessary for the cluster config. These
|
|
|
|
# include multicast port and interface to bind to.
|
2016-06-15 12:02:45 -07:00
|
|
|
cluster_config = get_hacluster_config()
|
2013-02-27 16:07:46 +00:00
|
|
|
|
|
|
|
# Obtain resources
|
2014-12-01 18:37:56 +00:00
|
|
|
resources = {'res_swift_haproxy': 'lsb:haproxy'}
|
|
|
|
resource_params = {'res_swift_haproxy': 'op monitor interval="5s"'}
|
2014-07-16 14:43:20 +01:00
|
|
|
|
2016-06-15 12:02:45 -07:00
|
|
|
if config('dns-ha'):
|
|
|
|
update_dns_ha_resource_params(relation_id=relation_id,
|
|
|
|
resources=resources,
|
|
|
|
resource_params=resource_params)
|
|
|
|
else:
|
|
|
|
vip_group = []
|
|
|
|
for vip in cluster_config['vip'].split():
|
|
|
|
if is_ipv6(vip):
|
|
|
|
res_swift_vip = 'ocf:heartbeat:IPv6addr'
|
|
|
|
vip_params = 'ipv6addr'
|
|
|
|
else:
|
|
|
|
res_swift_vip = 'ocf:heartbeat:IPaddr2'
|
|
|
|
vip_params = 'ip'
|
|
|
|
|
|
|
|
iface = get_iface_for_address(vip)
|
|
|
|
if iface is not None:
|
|
|
|
vip_key = 'res_swift_{}_vip'.format(iface)
|
2017-08-18 14:03:39 -07:00
|
|
|
if vip_key in vip_group:
|
|
|
|
if vip not in resource_params[vip_key]:
|
|
|
|
vip_key = '{}_{}'.format(vip_key, vip_params)
|
|
|
|
else:
|
2017-11-22 15:22:04 +00:00
|
|
|
log("Resource '{}' (vip='{}') already exists in "
|
|
|
|
"vip group - skipping".format(vip_key, vip),
|
|
|
|
WARNING)
|
2017-08-18 14:03:39 -07:00
|
|
|
continue
|
|
|
|
|
2016-06-15 12:02:45 -07:00
|
|
|
resources[vip_key] = res_swift_vip
|
|
|
|
resource_params[vip_key] = (
|
|
|
|
'params {ip}="{vip}" cidr_netmask="{netmask}"'
|
|
|
|
' nic="{iface}"'
|
|
|
|
''.format(ip=vip_params,
|
|
|
|
vip=vip,
|
|
|
|
iface=iface,
|
|
|
|
netmask=get_netmask_for_address(vip))
|
|
|
|
)
|
|
|
|
vip_group.append(vip_key)
|
|
|
|
|
|
|
|
if len(vip_group) >= 1:
|
|
|
|
relation_set(groups={'grp_swift_vips': ' '.join(vip_group)})
|
2014-07-16 14:43:20 +01:00
|
|
|
|
2014-12-01 18:37:56 +00:00
|
|
|
init_services = {'res_swift_haproxy': 'haproxy'}
|
|
|
|
clones = {'cl_swift_haproxy': 'res_swift_haproxy'}
|
2013-09-27 13:02:37 +01:00
|
|
|
|
2016-06-15 12:02:45 -07:00
|
|
|
relation_set(relation_id=relation_id,
|
|
|
|
init_services=init_services,
|
|
|
|
corosync_bindiface=cluster_config['ha-bindiface'],
|
|
|
|
corosync_mcastport=cluster_config['ha-mcastport'],
|
2013-09-27 13:02:37 +01:00
|
|
|
resources=resources,
|
|
|
|
resource_params=resource_params,
|
|
|
|
clones=clones)
|
|
|
|
|
|
|
|
|
|
|
|
def configure_https():
|
2014-12-01 18:37:56 +00:00
|
|
|
"""Enables SSL API Apache config if appropriate and kicks identity-service
|
2013-09-27 13:02:37 +01:00
|
|
|
with any required api updates.
|
2014-12-01 18:37:56 +00:00
|
|
|
"""
|
2013-09-27 13:02:37 +01:00
|
|
|
# need to write all to ensure changes to the entire request pipeline
|
|
|
|
# propagate (c-api, haprxy, apache)
|
|
|
|
CONFIGS.write_all()
|
|
|
|
if 'https' in CONFIGS.complete_contexts():
|
|
|
|
cmd = ['a2ensite', 'openstack_https_frontend']
|
2015-03-29 21:09:05 +01:00
|
|
|
check_call(cmd)
|
2013-09-27 13:02:37 +01:00
|
|
|
else:
|
|
|
|
cmd = ['a2dissite', 'openstack_https_frontend']
|
2015-03-29 21:09:05 +01:00
|
|
|
check_call(cmd)
|
2013-09-27 13:02:37 +01:00
|
|
|
|
2013-09-27 13:16:22 +01:00
|
|
|
# Apache 2.4 required enablement of configuration
|
|
|
|
if os.path.exists('/usr/sbin/a2enconf'):
|
2015-03-29 21:09:05 +01:00
|
|
|
check_call(['a2enconf', 'swift-rings'])
|
|
|
|
|
2016-04-11 13:56:39 +00:00
|
|
|
if not openstack.is_unit_paused_set():
|
2015-09-09 11:55:01 +01:00
|
|
|
# TODO: improve this by checking if local CN certs are available
|
|
|
|
# first then checking reload status (see LP #1433114).
|
|
|
|
service_reload('apache2', restart_on_failure=True)
|
2013-09-27 13:16:22 +01:00
|
|
|
|
2013-09-27 13:02:37 +01:00
|
|
|
for rid in relation_ids('identity-service'):
|
|
|
|
keystone_joined(relid=rid)
|
|
|
|
|
2014-12-01 18:37:56 +00:00
|
|
|
env_vars = {'OPENSTACK_SERVICE_SWIFT': 'proxy-server',
|
|
|
|
'OPENSTACK_PORT_API': config('bind-port'),
|
|
|
|
'OPENSTACK_PORT_MEMCACHED': 11211}
|
|
|
|
openstack.save_script_rc(**env_vars)
|
2013-09-27 13:16:22 +01:00
|
|
|
|
2013-09-27 13:02:37 +01:00
|
|
|
|
2014-11-17 13:57:33 +10:00
|
|
|
@hooks.hook('nrpe-external-master-relation-joined',
|
|
|
|
'nrpe-external-master-relation-changed')
|
2014-10-29 22:30:36 -05:00
|
|
|
def update_nrpe_config():
|
2015-01-12 12:04:01 +00:00
|
|
|
# python-dbus is used by check_upstart_job
|
2014-10-29 22:30:36 -05:00
|
|
|
apt_install('python-dbus')
|
2015-01-12 12:04:01 +00:00
|
|
|
hostname = nrpe.get_nagios_hostname()
|
|
|
|
current_unit = nrpe.get_nagios_unit_name()
|
|
|
|
nrpe_setup = nrpe.NRPE(hostname=hostname)
|
2015-02-19 15:24:24 +10:00
|
|
|
nrpe.copy_nrpe_checks()
|
2015-01-12 12:04:01 +00:00
|
|
|
nrpe.add_init_service_checks(nrpe_setup, services(), current_unit)
|
2015-02-19 15:24:24 +10:00
|
|
|
nrpe.add_haproxy_checks(nrpe_setup, current_unit)
|
2017-07-07 10:38:03 +02:00
|
|
|
api_port = determine_api_port(config('bind-port'),
|
|
|
|
singlenode_mode=True)
|
2016-09-19 16:22:45 +10:00
|
|
|
nrpe_setup.add_check(
|
|
|
|
shortname="swift-proxy-healthcheck",
|
|
|
|
description="Check Swift Proxy Healthcheck",
|
|
|
|
check_cmd="/usr/lib/nagios/plugins/check_http \
|
2017-07-07 10:38:03 +02:00
|
|
|
-I localhost -u /healthcheck -p {} \
|
|
|
|
-e \"OK\"".format(api_port)
|
2016-09-19 16:22:45 +10:00
|
|
|
)
|
2015-01-12 12:04:01 +00:00
|
|
|
nrpe_setup.write()
|
2014-10-29 22:30:36 -05:00
|
|
|
|
|
|
|
|
2015-11-24 13:35:26 +00:00
|
|
|
@hooks.hook('upgrade-charm')
|
2016-03-22 21:00:50 +00:00
|
|
|
@harden()
|
2015-11-24 13:35:26 +00:00
|
|
|
def upgrade_charm():
|
2017-07-31 15:34:32 +01:00
|
|
|
rel = openstack.get_os_codename_install_source(config('openstack-origin'))
|
|
|
|
pkgs = determine_packages(rel)
|
|
|
|
new_packages = filter_installed_packages(pkgs)
|
|
|
|
if new_packages:
|
|
|
|
apt_install(new_packages)
|
2015-11-24 13:35:26 +00:00
|
|
|
update_rsync_acls()
|
|
|
|
|
|
|
|
|
2016-03-22 21:00:50 +00:00
|
|
|
@hooks.hook('update-status')
|
|
|
|
@harden()
|
|
|
|
def update_status():
|
|
|
|
log('Updating status.')
|
|
|
|
|
|
|
|
|
2017-07-31 15:34:32 +01:00
|
|
|
@hooks.hook('amqp-relation-joined')
|
|
|
|
def amqp_joined(relation_id=None):
|
|
|
|
relation_set(relation_id=relation_id,
|
|
|
|
username=config('rabbit-user'),
|
|
|
|
vhost=config('rabbit-vhost'))
|
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('amqp-relation-changed',
|
|
|
|
'amqp-relation-departed')
|
|
|
|
@restart_on_change(restart_map())
|
|
|
|
def amqp_changed():
|
|
|
|
CONFIGS.write_all()
|
|
|
|
|
|
|
|
|
2013-09-27 13:02:37 +01:00
|
|
|
def main():
|
|
|
|
try:
|
|
|
|
hooks.execute(sys.argv)
|
|
|
|
except UnregisteredHookError as e:
|
2014-12-01 18:37:56 +00:00
|
|
|
log('Unknown hook {} - skipping.'.format(e), level=DEBUG)
|
2015-10-13 08:05:30 -04:00
|
|
|
assess_status(CONFIGS)
|
2013-09-27 13:02:37 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|