Support Apex with services in containers
[doctor.git] / doctor_tests / installer / common / set_congress.py
1 ##############################################################################
2 # Copyright (c) 2018 ZTE Corporation and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 import configparser
10 import os
11 import shutil
12
13
14 def set_drivers_config():
15     co_base = "/var/lib/config-data/puppet-generated/congress"
16     if not os.path.isdir(co_base):
17         co_base = ""
18     co_conf = co_base + "/etc/congress/congress.conf"
19     co_conf_bak = co_base + "/etc/congress/congress.conf.bak"
20     doctor_driver = "congress.datasources.doctor_driver.DoctorDriver"
21     config_modified = False
22
23     config = configparser.ConfigParser()
24     config.read(co_conf)
25     drivers = config['DEFAULT']['drivers']
26
27     if doctor_driver not in drivers:
28         config_modified = True
29         drivers += ',' + doctor_driver
30
31     config['DEFAULT']['drivers'] = drivers
32
33     if config_modified:
34         shutil.copyfile(co_conf, co_conf_bak)
35         with open(co_conf, 'w') as configfile:
36             config.write(configfile)
37
38
39 set_drivers_config()