fix package path and move files under doctor_tests
[doctor.git] / doctor_tests / installer / common / congress.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 def set_doctor_driver_conf(ssh_client, restart_cmd):
10     cg_set_cmd = '''#!/bin/bash
11 co_conf=/etc/congress/congress.conf
12 co_conf_bak=/etc/congress/congress.conf.bak
13 co_entry="congress.datasources.doctor_driver.DoctorDriver"
14 if sudo grep -e "^drivers.*$co_entry" $co_conf; then
15     echo "NOTE: congress is configured as we needed"
16 else
17     echo "modify the congress config"
18     sudo cp $co_conf $co_conf_bak
19     sudo sed -i -e "/^drivers/s/$/,$co_entry/"  $co_conf
20     %s
21 fi
22     ''' % (restart_cmd)
23
24     ret, output = ssh_client.ssh(cg_set_cmd)
25     if ret:
26         raise Exception('Do the congress command in controller node failed....'
27                         'ret=%s, cmd=%s, output=%s' % (ret, cg_set_cmd, output))
28
29
30 def restore_doctor_driver_conf(ssh_client, restart_cmd):
31     cg_restore_cmd = '''#!/bin/bash
32 co_conf=/etc/congress/congress.conf
33 co_conf_bak=/etc/congress/congress.conf.bak
34 if [ -e $co_conf_bak ]; then
35     echo "restore the congress config"
36     sudo cp $co_conf_bak $co_conf
37     sudo rm $co_conf_bak
38     %s
39 else
40     echo "Do not need to restore the congress config"
41 fi
42     ''' % (restart_cmd)
43
44     ret, output = ssh_client.ssh(cg_restore_cmd)
45     if ret:
46         raise Exception('Do the congress command in controller node failed....'
47                         'ret=%s, cmd=%s, output=%s' % (ret, cg_restore_cmd, output))