fix package path and move files under doctor_tests
[doctor.git] / doctor_tests / installer / common / set_ceilometer.py
1 ##############################################################################
2 # Copyright (c) 2017 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 os
10 import shutil
11 import yaml
12
13 ep_file = '/etc/ceilometer/event_pipeline.yaml'
14 ep_file_bak = '/etc/ceilometer/event_pipeline.yaml.bak'
15 event_notifier_topic = 'notifier://?topic=alarm.all'
16
17
18 def set_notifier_topic():
19     config_modified = False
20
21     if not os.path.isfile(ep_file):
22         raise Exception("File doesn't exist: %s." % ep_file)
23
24     with open(ep_file, 'r') as file:
25         config = yaml.safe_load(file)
26
27     sinks = config['sinks']
28     for sink in sinks:
29         if sink['name'] == 'event_sink':
30             publishers = sink['publishers']
31             if event_notifier_topic not in publishers:
32                 print('Add event notifier in ceilometer')
33                 publishers.append(event_notifier_topic)
34                 config_modified = True
35             else:
36                 print('NOTE: event notifier is configured in ceilometer as we needed')
37
38     if config_modified:
39         shutil.copyfile(ep_file, ep_file_bak)
40         with open(ep_file, 'w+') as file:
41             file.write(yaml.safe_dump(config))
42
43
44 set_notifier_topic()