Support Apex with services in containers
[doctor.git] / doctor_tests / installer / common / restore_config.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
12
13 cbase = "/var/lib/config-data/puppet-generated/ceilometer"
14 if not os.path.isdir(cbase):
15     cbase = ""
16
17
18 def restore_ep_config():
19     ep_file = cbase + '/etc/ceilometer/event_pipeline.yaml'
20     ep_file_bak = cbase + '/etc/ceilometer/event_pipeline.yaml.bak'
21
22     if not os.path.isfile(ep_file_bak):
23         print('Bak_file:%s does not exist.' % ep_file_bak)
24     else:
25         print('restore')
26         shutil.copyfile(ep_file_bak, ep_file)
27         os.remove(ep_file_bak)
28     return
29
30
31 def restore_ed_config():
32     ed_file = cbase + '/etc/ceilometer/event_definitions.yaml'
33     ed_file_bak = cbase + '/etc/ceilometer/event_definitions.bak'
34
35     if not os.path.isfile(ed_file_bak):
36         print("Bak_file doesn't exist: %s." % ed_file_bak)
37     else:
38         print('restore: %s' % ed_file)
39         if os.stat(ed_file_bak).st_size == 0:
40             print('Bak_file empty, so removing also: %s' % ed_file)
41             os.remove(ed_file)
42         else:
43             shutil.copyfile(ed_file_bak, ed_file)
44         os.remove(ed_file_bak)
45     return
46
47 restore_ep_config()
48 restore_ed_config()