From 3b3b7f3d1edfb3a0c9c24883b9e29f30e0d52198 Mon Sep 17 00:00:00 2001 From: Kapil Thangavelu Date: Wed, 26 Feb 2014 19:53:57 -0500 Subject: [PATCH] sync helpers --- .../charmhelpers/contrib/hahelpers/cluster.py | 8 ++++---- .../charmhelpers/contrib/openstack/context.py | 19 +++++++++---------- .../contrib/openstack/templates/haproxy.cfg | 5 +++-- hooks/charmhelpers/core/host.py | 12 +++--------- 4 files changed, 19 insertions(+), 25 deletions(-) diff --git a/hooks/charmhelpers/contrib/hahelpers/cluster.py b/hooks/charmhelpers/contrib/hahelpers/cluster.py index bf832f7d..074855f4 100644 --- a/hooks/charmhelpers/contrib/hahelpers/cluster.py +++ b/hooks/charmhelpers/contrib/hahelpers/cluster.py @@ -126,17 +126,17 @@ def determine_api_port(public_port): return public_port - (i * 10) -def determine_apache_port(public_port): +def determine_haproxy_port(public_port): ''' - Description: Determine correct apache listening port based on public IP + - state of the cluster. + Description: Determine correct proxy listening port based on public IP + + existence of HTTPS reverse proxy. public_port: int: standard public port for given service returns: int: the correct listening port for the HAProxy service ''' i = 0 - if len(peer_units()) > 0 or is_clustered(): + if https(): i += 1 return public_port - (i * 10) diff --git a/hooks/charmhelpers/contrib/openstack/context.py b/hooks/charmhelpers/contrib/openstack/context.py index b1c5e1da..a21c0c84 100644 --- a/hooks/charmhelpers/contrib/openstack/context.py +++ b/hooks/charmhelpers/contrib/openstack/context.py @@ -27,9 +27,11 @@ from charmhelpers.core.hookenv import ( ) from charmhelpers.contrib.hahelpers.cluster import ( - determine_apache_port, determine_api_port, + determine_haproxy_port, https, + is_clustered, + peer_units, ) from charmhelpers.contrib.hahelpers.apache import ( @@ -263,12 +265,7 @@ class AMQPContext(OSContextGenerator): # Sufficient information found = break out! break # Used for active/active rabbitmq >= grizzly - if ('clustered' not in ctxt or relation_get('ha-vip-only') == 'True') and \ - len(related_units(rid)) > 1: - if relation_get('ha_queues'): - ctxt['rabbitmq_ha_queues'] = relation_get('ha_queues') - else: - ctxt['rabbitmq_ha_queues'] = False + if 'clustered' not in ctxt and len(related_units(rid)) > 1: rabbitmq_hosts = [] for unit in related_units(rid): rabbitmq_hosts.append(relation_get('private-address', @@ -430,9 +427,11 @@ class ApacheSSLContext(OSContextGenerator): 'private_address': unit_get('private-address'), 'endpoints': [] } - for api_port in self.external_ports: - ext_port = determine_apache_port(api_port) - int_port = determine_api_port(api_port) + for ext_port in self.external_ports: + if peer_units() or is_clustered(): + int_port = determine_haproxy_port(ext_port) + else: + int_port = determine_api_port(ext_port) portmap = (int(ext_port), int(int_port)) ctxt['endpoints'].append(portmap) return ctxt diff --git a/hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg b/hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg index 56ed913e..a1694e44 100644 --- a/hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg +++ b/hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg @@ -8,8 +8,8 @@ global defaults log global - mode tcp - option tcplog + mode http + option httplog option dontlognull retries 3 timeout queue 1000 @@ -29,6 +29,7 @@ listen stats :8888 {% for service, ports in service_ports.iteritems() -%} listen {{ service }} 0.0.0.0:{{ ports[0] }} balance roundrobin + option tcplog {% for unit, address in units.iteritems() -%} server {{ unit }} {{ address }}:{{ ports[1] }} check {% endfor %} diff --git a/hooks/charmhelpers/core/host.py b/hooks/charmhelpers/core/host.py index cfd26847..c8c81b28 100644 --- a/hooks/charmhelpers/core/host.py +++ b/hooks/charmhelpers/core/host.py @@ -194,7 +194,7 @@ def file_hash(path): return None -def restart_on_change(restart_map, stopstart=False): +def restart_on_change(restart_map): """Restart services based on configuration files changing This function is used a decorator, for example @@ -219,14 +219,8 @@ def restart_on_change(restart_map, stopstart=False): for path in restart_map: if checksums[path] != file_hash(path): restarts += restart_map[path] - services_list = list(OrderedDict.fromkeys(restarts)) - if not stopstart: - for service_name in services_list: - service('restart', service_name) - else: - for action in ['stop', 'start']: - for service_name in services_list: - service(action, service_name) + for service_name in list(OrderedDict.fromkeys(restarts)): + service('restart', service_name) return wrapped_f return wrap