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