added ha-vip-only features

changes in unison
This commit is contained in:
yolanda.robla@canonical.com 2014-01-31 09:34:16 +01:00
commit 53414b2c96
5 changed files with 107 additions and 46 deletions

View File

@ -54,6 +54,16 @@ options:
description: |
Default multicast port number that will be used to communicate between
HA Cluster nodes.
ha-vip-only:
type: boolean
default: False
descriptions: |
By default, without pairing with hacluster charm, rabbitmq will deploy
in active/active/active... HA. When pairied with hacluster charm, it
will deploy as active/passive. By enabling this option, pairing with
hacluster charm will keep rabbit in active/active setup, but in addition
it will deploy a VIP that can be used by services that cannot work
with mutiple AMQPs (like Glance in pre-Icehouse).
rbd-size:
type: string
default: 5G
@ -74,3 +84,23 @@ options:
Number of tries to cluster with other units before giving up.
If errors clustering happening in more than these units, charm will
end with an error
install_sources:
type: string
description: |
Repository from which to install. May be one of the following:
distro (default), ppa:somecustom/ppa, a deb url sources entry,
or a supported Cloud Archive release pocket.
Supported Cloud Archive sources include: cloud:precise-folsom,
cloud:precise-folsom/updates, cloud:precise-folsom/staging,
cloud:precise-folsom/proposed. Also, a list is supported:
# install_sources:
# - "ppa:foo"
# - "http://example.com/repo precise main"
# install_keys:
# - null
# - "a1b2c3d4"
install_keys:
type: string
description: |
PGP keys to be installed with install_sources

View File

@ -101,7 +101,7 @@ def cluster_with():
vers = rabbit_version()
if vers >= '3.0.1-1':
cluster_cmd = 'join_cluster'
cmd = ['/usr/sbin/rabbitmqctl', 'set_policy', 'HA', '^(?!amq\\.).*', '{"ha-mode": "all"}']
cmd = [RABBITMQ_CTL, 'set_policy', 'HA', '^(?!amq\.).*', '{"ha-mode": "all"}']
subprocess.check_call(cmd)
else:
cluster_cmd = 'cluster'
@ -285,7 +285,7 @@ def execute(cmd, die=False, echo=False):
rc = p.returncode
if die and rc != 0:
error_out("ERROR: command %s return non-zero.\n" % cmd)
utils.juju_log('INFO', "ERROR: command %s return non-zero.\n" % cmd)
return (stdout, stderr, rc)

View File

@ -16,8 +16,9 @@ import lib.openstack_common as openstack
import _pythonpath
_ = _pythonpath
from charmhelpers.fetch import configure_sources
from charmhelpers.core import hookenv
from charmhelpers.core.host import rsync, mkdir
from charmhelpers.core.host import rsync, mkdir, write_file
from charmhelpers.contrib.charmsupport.nrpe import NRPE
from charmhelpers.contrib.unison import (
ensure_user,
@ -48,9 +49,12 @@ def ensure_unison_user():
def install():
pre_install_hooks()
configure_sources(update=True)
utils.install(*rabbit.PACKAGES)
utils.install(*rabbit.EXTRA_PACKAGES)
utils.expose(5672)
utils.chown(RABBIT_DIR, rabbit.RABBIT_USER, rabbit.RABBIT_USER)
utils.chmod(RABBIT_DIR, 0775)
# ensure user + permissions for peer relations that
# may be syncing data there via SSH_USER.
@ -64,14 +68,11 @@ def configure_amqp(username, vhost):
else:
cmd = ['pwgen', '64', '1']
password = subprocess.check_output(cmd).strip()
with open(password_file, 'wb') as out:
out.write(password)
write_file(password_file, password, "root", rabbit.RABBIT_USER, 0660)
rabbit.create_vhost(vhost)
rabbit.create_user(username, password)
rabbit.grant_permissions(username, vhost)
utils.chown(password_file, rabbit.SSH_USER, rabbit.RABBIT_USER)
utils.chmod(password_file, 0770)
return password
@ -117,6 +118,7 @@ def amqp_changed(relation_id=None, remote_unit=None):
if utils.is_relation_made('ha'):
# active/passive settings
relation_settings['vip'] = utils.config_get('vip')
relation_settings['ha-vip-only'] = utils.config_get('ha-vip-only')
if relation_id:
relation_settings['rid'] = relation_id
@ -136,7 +138,8 @@ def cluster_joined():
group='rabbitmq',
peer_interface='cluster',
ensure_local_user=True)
if utils.is_relation_made('ha'):
if utils.is_relation_made('ha') and \
utils.config_get('ha-vip-only') is False:
utils.juju_log('INFO',
'hacluster relation is present, skipping native '
'rabbitmq cluster config.')
@ -160,7 +163,8 @@ def cluster_joined():
def cluster_changed():
if utils.is_relation_made('ha'):
if utils.is_relation_made('ha') and \
utils.config_get('ha-vip-only') is False:
utils.juju_log('INFO',
'hacluster relation is present, skipping native '
'rabbitmq cluster config.')
@ -202,7 +206,8 @@ def cluster_changed():
def cluster_departed():
if utils.is_relation_made('ha'):
if utils.is_relation_made('ha') and \
utils.config_get('ha-vip-only') is False:
utils.juju_log('INFO',
'hacluster relation is present, skipping native '
'rabbitmq cluster config.')
@ -220,20 +225,26 @@ def ha_joined():
vip_iface = utils.config_get('vip_iface')
vip_cidr = utils.config_get('vip_cidr')
rbd_name = utils.config_get('rbd-name')
vip_only = utils.config_get('ha-vip-only')
if None in [corosync_bindiface, corosync_mcastport, vip, vip_iface,
vip_cidr, rbd_name]:
vip_cidr, rbd_name] and vip_only is False:
utils.juju_log('ERROR', 'Insufficient configuration data to '
'configure hacluster.')
sys.exit(1)
elif None in [corosync_bindiface, corosync_mcastport, vip, vip_iface,
vip_cidr] and vip_only is True:
utils.juju_log('ERROR', 'Insufficient configuration data to '
'configure VIP-only hacluster.')
sys.exit(1)
if not utils.is_relation_made('ceph', 'auth'):
if not utils.is_relation_made('ceph', 'auth') and vip_only is False:
utils.juju_log('INFO',
'ha_joined: No ceph relation yet, deferring.')
return
name = '%s@localhost' % SERVICE_NAME
if rabbit.get_node_name() != name:
if rabbit.get_node_name() != name and vip_only is False:
utils.juju_log('INFO', 'Stopping rabbitmq-server.')
utils.stop('rabbitmq-server')
rabbit.set_node_name('%s@localhost' % SERVICE_NAME)
@ -244,31 +255,44 @@ def ha_joined():
relation_settings['corosync_bindiface'] = corosync_bindiface
relation_settings['corosync_mcastport'] = corosync_mcastport
relation_settings['resources'] = {
'res_rabbitmq_rbd': 'ocf:ceph:rbd',
'res_rabbitmq_fs': 'ocf:heartbeat:Filesystem',
'res_rabbitmq_vip': 'ocf:heartbeat:IPaddr2',
'res_rabbitmq-server': 'lsb:rabbitmq-server',
}
if vip_only is True:
relation_settings['resources'] = {
'res_rabbitmq_vip': 'ocf:heartbeat:IPaddr2',
}
relation_settings['resource_params'] = {
'res_rabbitmq_vip': 'params ip="%s" cidr_netmask="%s" nic="%s"' %
(vip, vip_cidr, vip_iface),
}
relation_settings['groups'] = {
'grp_rabbitmq': 'res_rabbitmq_rbd res_rabbitmq_fs res_rabbitmq_vip '
'res_rabbitmq-server',
}
else:
relation_settings['resources'] = {
'res_rabbitmq_rbd': 'ocf:ceph:rbd',
'res_rabbitmq_fs': 'ocf:heartbeat:Filesystem',
'res_rabbitmq_vip': 'ocf:heartbeat:IPaddr2',
'res_rabbitmq-server': 'lsb:rabbitmq-server',
}
relation_settings['resource_params'] = {
'res_rabbitmq_rbd': 'params name="%s" pool="%s" user="%s" '
'secret="%s"' %
(rbd_name, POOL_NAME,
SERVICE_NAME, ceph.keyfile_path(SERVICE_NAME)),
'res_rabbitmq_fs': 'params device="/dev/rbd/%s/%s" directory="%s" '
'fstype="ext4" op start start-delay="10s"' %
(POOL_NAME, rbd_name, RABBIT_DIR),
'res_rabbitmq_vip': 'params ip="%s" cidr_netmask="%s" nic="%s"' %
(vip, vip_cidr, vip_iface),
'res_rabbitmq-server': 'op start start-delay="5s" '
'op monitor interval="5s"',
}
relation_settings['resource_params'] = {
'res_rabbitmq_rbd': 'params name="%s" pool="%s" user="%s" '
'secret="%s"' %
(rbd_name, POOL_NAME,
SERVICE_NAME, ceph.keyfile_path(SERVICE_NAME)),
'res_rabbitmq_fs': 'params device="/dev/rbd/%s/%s" directory="%s" '
'fstype="ext4" op start start-delay="10s"' %
(POOL_NAME, rbd_name, RABBIT_DIR),
'res_rabbitmq_vip': 'params ip="%s" cidr_netmask="%s" nic="%s"' %
(vip, vip_cidr, vip_iface),
'res_rabbitmq-server': 'op start start-delay="5s" '
'op monitor interval="5s"',
}
relation_settings['groups'] = {
'grp_rabbitmq': 'res_rabbitmq_rbd res_rabbitmq_fs res_rabbitmq_vip '
'res_rabbitmq-server',
}
relation_settings['groups'] = {
'grp_rabbitmq': 'res_rabbitmq_rbd res_rabbitmq_fs res_rabbitmq_vip '
'res_rabbitmq-server',
}
for rel_id in utils.relation_ids('ha'):
utils.relation_set(rid=rel_id, **relation_settings)
@ -373,6 +397,7 @@ def update_nrpe_checks():
def upgrade_charm():
pre_install_hooks()
configure_sources(update=True)
utils.install(*rabbit.EXTRA_PACKAGES)
# Ensure older passwd files in /var/lib/juju are moved to
# /var/lib/rabbitmq which will end up replicated if clustered.
@ -399,7 +424,7 @@ MAN_PLUGIN = 'rabbitmq_management'
def config_changed():
ensure_user(user=rabbit.SSH_USER, group='rabbitmq')
ensure_user(user=rabbit.SSH_USER, group=rabbit.RABBIT_USER)
ensure_unison_rabbit_permissions()
if utils.config_get('management_plugin') is True:
@ -426,7 +451,8 @@ def config_changed():
os.remove(rabbit.RABBITMQ_CONF)
utils.close_port(utils.config_get('ssl_port'))
if cluster.eligible_leader('res_rabbitmq_vip'):
if cluster.eligible_leader('res_rabbitmq_vip') or \
utils.config_get('ha-vip-only') is True:
utils.restart('rabbitmq-server')
update_nrpe_checks()

View File

@ -61,8 +61,7 @@ from charmhelpers.core.hookenv import (
)
BASE_CMD = ['unison', '-auto', '-batch=true', '-confirmbigdel=false',
'-fastcheck=true', '-group=false', '-owner=false',
'-prefer=newer', '-times=true']
'-fastcheck=true', '-prefer=newer', '-times=true']
def get_homedir(user):
@ -227,10 +226,16 @@ def collect_authed_hosts(peer_interface):
return hosts
def sync_path_to_host(path, host, user, verbose=False):
def sync_path_to_host(path, host, user, enforce_perms=True, verbose=False):
cmd = copy(BASE_CMD)
if not verbose:
cmd.append('-silent')
if enforce_perms:
cmd.append('-owner=True')
cmd.append('-group=True')
else:
cmd.append('-owner=False')
cmd.append('-group=False')
# removing trailing slash from directory paths, unison
# doesn't like these.
@ -246,12 +251,12 @@ def sync_path_to_host(path, host, user, verbose=False):
log('Error syncing remote files')
def sync_to_peer(host, user, paths=[], verbose=False):
def sync_to_peer(host, user, paths=[], enforce_perms=True, verbose=False):
'''Sync paths to an specific host'''
[sync_path_to_host(p, host, user, verbose) for p in paths]
[sync_path_to_host(p, host, user, enforce_perms, verbose) for p in paths]
def sync_to_peers(peer_interface, user, paths=[], verbose=False):
def sync_to_peers(peer_interface, user, paths=[], enforce_perms=True, verbose=False):
'''Sync all hosts to an specific path'''
for host in collect_authed_hosts():
sync_to_peer(host, user, paths, verbose)
sync_to_peer(host, user, paths, enforce_perms, verbose)

View File

@ -1 +1 @@
119
120