Merge lp:~cts-engineering/charms/trusty/quantum-gateway/ha-scale

This commit is contained in:
Hui Xiang 2014-12-25 16:55:36 +08:00
parent 2b5ef118a9
commit bc1e411872
4 changed files with 46 additions and 14 deletions

View File

@ -13,6 +13,7 @@ clustering-related helpers.
import subprocess
import os
from socket import gethostname as get_unit_hostname
import six
@ -28,12 +29,19 @@ from charmhelpers.core.hookenv import (
WARNING,
unit_get,
)
from charmhelpers.core.decorators import (
retry_on_exception,
)
class HAIncompleteConfig(Exception):
pass
class CRMResourceNotFound(Exception):
pass
def is_elected_leader(resource):
"""
Returns True if the charm executing this is the elected cluster leader.
@ -68,24 +76,30 @@ def is_clustered():
return False
def is_crm_leader(resource):
@retry_on_exception(5, base_delay=2, exc_type=CRMResourceNotFound)
def is_crm_leader(resource, retry=False):
"""
Returns True if the charm calling this is the elected corosync leader,
as returned by calling the external "crm" command.
We allow this operation to be retried to avoid the possibility of getting a
false negative. See LP #1396246 for more info.
"""
cmd = [
"crm", "resource",
"show", resource
]
cmd = ['crm', 'resource', 'show', resource]
try:
status = subprocess.check_output(cmd).decode('UTF-8')
status = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
if not isinstance(status, six.text_type):
status = six.text_type(status, "utf-8")
except subprocess.CalledProcessError:
return False
else:
if get_unit_hostname() in status:
return True
else:
return False
status = None
if status and get_unit_hostname() in status:
return True
if status and "resource %s is NOT running" % (resource) in status:
raise CRMResourceNotFound("CRM resource %s not found" % (resource))
return False
def is_leader(resource):

View File

@ -54,6 +54,17 @@ def enable():
if is_enabled():
return True
if not os.path.isdir('/proc/sys/net/ipv6'):
# disable IPv6 support in ufw
hookenv.log("This machine doesn't have IPv6 enabled", level="INFO")
exit_code = subprocess.call(['sed', '-i', 's/IPV6=yes/IPV6=no/g',
'/etc/default/ufw'])
if exit_code == 0:
hookenv.log('IPv6 support in ufw disabled', level='INFO')
else:
hookenv.log("Couldn't disable IPv6 support in ufw", level="ERROR")
raise Exception("Couldn't disable IPv6 support in ufw")
output = subprocess.check_output(['ufw', 'enable'],
env={'LANG': 'en_US',
'PATH': os.environ['PATH']})

View File

@ -491,6 +491,7 @@ class HAProxyContext(OSContextGenerator):
ctxt['haproxy_client_timeout'] = config('haproxy-client-timeout')
if config('prefer-ipv6'):
ctxt['ipv6'] = True
ctxt['local_host'] = 'ip6-localhost'
ctxt['haproxy_host'] = '::'
ctxt['stat_port'] = ':::8888'

View File

@ -152,9 +152,15 @@ def neutron_plugins():
database=config('neutron-database'),
relation_prefix='neutron',
ssl_dir=NEUTRON_CONF_DIR)],
'services': ['calico-compute', 'bird', 'neutron-dhcp-agent'],
'services': ['calico-felix',
'bird',
'neutron-dhcp-agent',
'nova-api-metadata'],
'packages': [[headers_package()] + determine_dkms_package(),
['calico-compute', 'bird', 'neutron-dhcp-agent']],
['calico-compute',
'bird',
'neutron-dhcp-agent',
'nova-api-metadata']],
'server_packages': ['neutron-server', 'calico-control'],
'server_services': ['neutron-server']
}