Skip to content

Commit

Permalink
Merge "Update cassandra_server_list in collector and query engine con…
Browse files Browse the repository at this point in the history
…f file" into R3.0
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Mar 9, 2016
2 parents 0879c5e + 39598b9 commit 08dc81e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 20 deletions.
47 changes: 34 additions & 13 deletions contrail_provisioning/collector/upgrade.py
Expand Up @@ -59,42 +59,63 @@ def update_config(self):
if not os.path.exists('/etc/contrail/contrail-keystone-auth.conf'):
self.fixup_keystone_auth_config_file()

# Alarmgen is enabled by default starting in 3.0
# From 3.0:
# 1. Alarmgen is enabled by default.
# 2. Analytics services no longer connect to the local collector.
# All analytics services other than collector would subscribe for
# the collector service with discovery server.
# 3. Collector uses Zookeeper servers.
# 4. Collector and query engine use CQL to connect to cassandra and
# hence the port in DEFAULT.cassandra_server_list needs to be
# updated to the default CQL port - 9042
if (self._args.from_rel < LooseVersion('3.00') and
self._args.to_rel >= LooseVersion('3.00')):
collector_conf = '/etc/contrail/contrail-collector.conf'
qe_conf = '/etc/contrail/contrail-query-engine.conf'
# Sanitize qe_conf by removing leading spaces from each line so
# that iniparse can open it
local('sed "s/^[ \t]*//" -i %s' % (qe_conf))
# 1. Alarmgen is enabled by default.
self.fixup_contrail_alarm_gen()
kafka_broker_list = [server[0] + ":9092"\
for server in self.cassandra_server_list]
kafka_broker_list_str = ' '.join(map(str, kafka_broker_list))
local('openstack-config --set\
/etc/contrail/contrail-collector.conf\
DEFAULT kafka_broker_list %s' % kafka_broker_list_str)

# From 3.0, analytics services no longer connect to the
# local collector. All analytics services other than collector
# would subscribe for the collector service with discovery server.
# Collector uses Zookeeper servers also.
if (self._args.from_rel < LooseVersion('3.00') and
self._args.to_rel >= LooseVersion('3.00')):
self.set_config(collector_conf, 'DEFAULT', 'kafka_broker_list',
kafka_broker_list_str)
# 2. Analytics services no longer connect to the local collector.
# All analytics services other than collector would subscribe for
# the collector service with discovery server.
topology_conf = '/etc/contrail/contrail-topology.conf'
self.set_config(topology_conf, 'DISCOVERY',
'disc_server_ip', self._args.cfgm_ip)
self.set_config(topology_conf, 'DISCOVERY',
'disc_server_port', '5998')
qe_conf = '/etc/contrail/contrail-query-engine.conf'
self.set_config(qe_conf, 'DISCOVERY',
'server', self._args.cfgm_ip)
self.set_config(qe_conf, 'DISCOVERY',
'port', '5998')
self.del_config(qe_conf, 'DEFAULT', 'collectors')
analytics_api_conf = '/etc/contrail/contrail-analytics-api.conf'
self.del_config(analytics_api_conf, 'DEFAULTS', 'collectors')
collector_conf = '/etc/contrail/contrail-collector.conf'
# 3. Collector uses Zookeeper servers.
if self.zookeeper_server_list:
self.set_config(collector_conf, 'DEFAULT',
'zookeeper_server_list',
','.join('%s:%s' % zookeeper_server for zookeeper_server in \
self.zookeeper_server_list))
# 4. Collector and query engine use CQL to connect to cassandra and
# hence the port in DEFAULT.cassandra_server_list needs to be
# updated to the default CQL port - 9042
qe_cass_server_list = self.get_config(qe_conf, 'DEFAULT',
'cassandra_server_list')
self.set_config(qe_conf, 'DEFAULT', 'cassandra_server_list',
' '.join('%s:%s' % (server.split(':')[0], '9042') for server \
in qe_cass_server_list.split()))
collector_cass_server_list = self.get_config(collector_conf, 'DEFAULT',
'cassandra_server_list')
self.set_config(collector_conf, 'DEFAULT', 'cassandra_server_list',
' '.join('%s:%s' % (server.split(':')[0], '9042') for server \
in collector_cass_server_list.split()))

def main():
collector = CollectorUpgrade()
Expand Down
6 changes: 6 additions & 0 deletions contrail_provisioning/common/base.py
Expand Up @@ -300,6 +300,12 @@ def del_config(self, fl, sec, var):
local("openstack-config --del %s %s %s" % (
fl, sec, var))

def get_config(self, fl, sec, var):
with settings(warn_only=True):
output = local("openstack-config --get %s %s %s" % (
fl, sec, var), capture=True)
return output

def setup(self):
self.disable_selinux()
self.disable_iptables()
Expand Down
23 changes: 16 additions & 7 deletions tools/openstack-config
Expand Up @@ -18,17 +18,18 @@

import iniparse
import sys
import json

parameter = value = None

def usage():
sys.stderr.write(sys.argv[0] +
" --set|--del config_file section [parameter] [value]\n")
" --set|--del|--get config_file section [parameter] [value]\n")
sys.exit(1)

try:
mode = sys.argv[1]
if mode not in ('--set', '--del'):
if mode not in ('--set', '--del', '--get'):
usage()
cfgfile = sys.argv[2]
section = sys.argv[3]
Expand All @@ -39,8 +40,8 @@ try:
if mode == '--set':
usage()
else:
if mode == '--del':
sys.stderr.write("A value should not be specified with --del\n")
if mode == '--del' or mode == '--get':
sys.stderr.write("A value should not be specified with %s\n" % (mode))
usage()
except IndexError:
usage()
Expand All @@ -53,11 +54,19 @@ if mode == '--set':
conf.add_section(section)
value += '\n'
conf.set(section, parameter, value)
with open(cfgfile, 'w') as f:
conf.write(f)
elif mode == '--get':
if parameter is None:
items = conf.items(section)
sys.stdout.write("%s\n" % json.dumps(items))
else:
value = conf.get(section, parameter)
sys.stdout.write("%s\n" % (str(value)))
else:
if parameter is None:
conf.remove_section(section)
elif value is None:
conf.remove_option(section, parameter)

with open(cfgfile, 'w') as f:
conf.write(f)
with open(cfgfile, 'w') as f:
conf.write(f)

0 comments on commit 08dc81e

Please sign in to comment.