diff options
author | dongwenjuan <dong.wenjuan@zte.com.cn> | 2018-08-22 09:48:58 +0800 |
---|---|---|
committer | dongwenjuan <dong.wenjuan@zte.com.cn> | 2018-08-23 17:44:49 +0800 |
commit | da25598a6a31abe0579ffed12d1719e5ff75f9a7 (patch) | |
tree | 7b51732d5864ea936d907b85a8595bd7c4e6142f /doctor_tests | |
parent | f9e1e3b1ae4be80bc2dc61d9c4213c81c091ea72 (diff) |
bugfix: add doctor datasource in congress
Change-Id: I465fd6c59daf99dd543488a15819dab78e8cdd7b
Signed-off-by: dongwenjuan <dong.wenjuan@zte.com.cn>
Diffstat (limited to 'doctor_tests')
-rw-r--r-- | doctor_tests/installer/apex.py | 55 | ||||
-rw-r--r-- | doctor_tests/installer/base.py | 24 | ||||
-rw-r--r-- | doctor_tests/installer/common/congress.py | 51 | ||||
-rw-r--r-- | doctor_tests/installer/common/restore_congress.py | 26 | ||||
-rw-r--r-- | doctor_tests/installer/common/set_congress.py | 35 | ||||
-rw-r--r-- | doctor_tests/installer/mcp.py | 4 |
6 files changed, 111 insertions, 84 deletions
diff --git a/doctor_tests/installer/apex.py b/doctor_tests/installer/apex.py index bfa72d32..694adb88 100644 --- a/doctor_tests/installer/apex.py +++ b/doctor_tests/installer/apex.py @@ -9,6 +9,7 @@ import re import time +from doctor_tests.common.constants import Inspector from doctor_tests.common.utils import SSHClient from doctor_tests.installer.base import BaseInstaller @@ -16,9 +17,11 @@ from doctor_tests.installer.base import BaseInstaller class ApexInstaller(BaseInstaller): node_user_name = 'heat-admin' cm_set_script = 'set_config.py' - cm_set_compute_script = 'set_compute_config.py' + nc_set_compute_script = 'set_compute_config.py' + cg_set_script = 'set_congress.py' cm_restore_script = 'restore_config.py' - cm_restore_compute_script = 'restore_compute_config.py' + nc_restore_compute_script = 'restore_compute_config.py' + cg_restore_script = 'restore_congress.py' def __init__(self, conf, log): super(ApexInstaller, self).__init__(conf, log) @@ -92,30 +95,36 @@ class ApexInstaller(BaseInstaller): def set_apply_patches(self): self.log.info('Set apply patches start......') - restart_cm_cmd = 'sudo systemctl restart ' \ - 'openstack-ceilometer-notification.service' + restart_cmd = 'sudo systemctl restart' \ + ' openstack-ceilometer-notification.service' + + set_scripts = [self.cm_set_script] if self.conf.test_case != 'fault_management': - restart_cm_cmd += ' openstack-nova-scheduler.service' + restart_cmd += ' openstack-nova-scheduler.service' + + if self.conf.inspector.type == Inspector.CONGRESS: + restart_cmd += ' openstack-congress-server.service' + set_scripts.append(self.cg_set_script) for node_ip in self.controllers: client = SSHClient(node_ip, self.node_user_name, key_filename=self.key_file) self.controller_clients.append(client) self._run_apply_patches(client, - restart_cm_cmd, - self.cm_set_script) + restart_cmd, + set_scripts) if self.conf.test_case != 'fault_management': - restart_cm_cmd = 'sudo systemctl restart ' \ - 'openstack-nova-compute.service' + restart_cmd = 'sudo systemctl restart' \ + ' openstack-nova-compute.service' for node_ip in self.computes: client = SSHClient(node_ip, self.node_user_name, key_filename=self.key_file) self.compute_clients.append(client) self._run_apply_patches(client, - restart_cm_cmd, - self.cm_set_compute_script) + restart_cmd, + [self.nc_set_compute_script]) if self.conf.test_case != 'fault_management': time.sleep(10) @@ -123,21 +132,27 @@ class ApexInstaller(BaseInstaller): def restore_apply_patches(self): self.log.info('restore apply patches start......') - restart_cm_cmd = 'sudo systemctl restart ' \ - 'openstack-ceilometer-notification.service' + restart_cmd = 'sudo systemctl restart' \ + ' openstack-ceilometer-notification.service' + + restore_scripts = [self.cm_restore_script] if self.conf.test_case != 'fault_management': - restart_cm_cmd += ' openstack-nova-scheduler.service' + restart_cmd += ' openstack-nova-scheduler.service' + + if self.conf.inspector.type == Inspector.CONGRESS: + restart_cmd += ' openstack-congress-server.service' + restore_scripts.append(self.cg_restore_script) for client in self.controller_clients: self._run_apply_patches(client, - restart_cm_cmd, - self.cm_restore_script) + restart_cmd, + restore_scripts) if self.conf.test_case != 'fault_management': - restart_cm_cmd = 'sudo systemctl restart ' \ - 'openstack-nova-compute.service' + restart_cmd = 'sudo systemctl restart' \ + ' openstack-nova-compute.service' for client in self.compute_clients: self._run_apply_patches(client, - restart_cm_cmd, - self.cm_restore_compute_script) + restart_cmd, + [self.nc_restore_compute_script]) diff --git a/doctor_tests/installer/base.py b/doctor_tests/installer/base.py index 4eed3f29..953b36d9 100644 --- a/doctor_tests/installer/base.py +++ b/doctor_tests/installer/base.py @@ -118,16 +118,18 @@ class BaseInstaller(object): % (output, command, self.conf.installer.type)) return output - def _run_apply_patches(self, client, restart_cmd, script_name): + def _run_apply_patches(self, client, restart_cmd, script_names): installer_dir = os.path.dirname(os.path.realpath(__file__)) - script_abs_path = '{0}/{1}/{2}'.format(installer_dir, - 'common', script_name) - client.scp(script_abs_path, script_name) - cmd = 'sudo python %s' % script_name - ret, output = client.ssh(cmd) - if ret: - raise Exception('Do the command in controller' - ' node failed, ret=%s, cmd=%s, output=%s' - % (ret, cmd, output)) - client.ssh(restart_cmd) + if isinstance(script_names, list): + for script_name in script_names: + script_abs_path = '{0}/{1}/{2}'.format(installer_dir, + 'common', script_name) + client.scp(script_abs_path, script_name) + cmd = 'sudo python3 %s' % script_name + ret, output = client.ssh(cmd) + if ret: + raise Exception('Do the command in controller' + ' node failed, ret=%s, cmd=%s, output=%s' + % (ret, cmd, output)) + client.ssh(restart_cmd) diff --git a/doctor_tests/installer/common/congress.py b/doctor_tests/installer/common/congress.py deleted file mode 100644 index cc58c390..00000000 --- a/doctor_tests/installer/common/congress.py +++ /dev/null @@ -1,51 +0,0 @@ -############################################################################## -# Copyright (c) 2017 ZTE Corporation and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - - -def set_doctor_driver_conf(ssh_client, restart_cmd): - cg_set_cmd = '''#!/bin/bash -co_conf=/etc/congress/congress.conf -co_conf_bak=/etc/congress/congress.conf.bak -co_entry="congress.datasources.doctor_driver.DoctorDriver" -if sudo grep -e "^drivers.*$co_entry" $co_conf; then - echo "NOTE: congress is configured as we needed" -else - echo "modify the congress config" - sudo cp $co_conf $co_conf_bak - sudo sed -i -e "/^drivers/s/$/,$co_entry/" $co_conf - %s -fi - ''' % (restart_cmd) - - ret, output = ssh_client.ssh(cg_set_cmd) - if ret: - raise Exception('Do the congress command in controller node failed...' - 'ret=%s, cmd=%s, output=%s' - % (ret, cg_set_cmd, output)) - - -def restore_doctor_driver_conf(ssh_client, restart_cmd): - cg_restore_cmd = '''#!/bin/bash -co_conf=/etc/congress/congress.conf -co_conf_bak=/etc/congress/congress.conf.bak -if [ -e $co_conf_bak ]; then - echo "restore the congress config" - sudo cp $co_conf_bak $co_conf - sudo rm $co_conf_bak - %s -else - echo "Do not need to restore the congress config" -fi - ''' % (restart_cmd) - - ret, output = ssh_client.ssh(cg_restore_cmd) - if ret: - raise Exception('Do the congress command in controller node failed...' - 'ret=%s, cmd=%s, output=%s' - % (ret, cg_restore_cmd, output)) diff --git a/doctor_tests/installer/common/restore_congress.py b/doctor_tests/installer/common/restore_congress.py new file mode 100644 index 00000000..b5efb1ef --- /dev/null +++ b/doctor_tests/installer/common/restore_congress.py @@ -0,0 +1,26 @@ +############################################################################## +# Copyright (c) 2017 ZTE Corporation and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +import os +import shutil + + +def restore_drivers_config(): + co_conf = "/etc/congress/congress.conf" + co_conf_bak = "/etc/congress/congress.conf.bak" + + if not os.path.isfile(co_conf_bak): + print('Bak_file:%s does not exist.' % co_conf_bak) + else: + print('restore: %s' % co_conf) + shutil.copyfile(co_conf_bak, co_conf) + os.remove(co_conf_bak) + return + + +restore_drivers_config() diff --git a/doctor_tests/installer/common/set_congress.py b/doctor_tests/installer/common/set_congress.py new file mode 100644 index 00000000..d8438701 --- /dev/null +++ b/doctor_tests/installer/common/set_congress.py @@ -0,0 +1,35 @@ +############################################################################## +# Copyright (c) 2018 ZTE Corporation and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +import configparser +import shutil + + +def set_drivers_config(): + co_conf = "/etc/congress/congress.conf" + co_conf_bak = "/etc/congress/congress.conf.bak" + doctor_driver = "congress.datasources.doctor_driver.DoctorDriver" + config_modified = False + + config = configparser.ConfigParser() + config.read(co_conf) + drivers = config['DEFAULT']['drivers'] + + if doctor_driver not in drivers: + config_modified = True + drivers += ',' + doctor_driver + + config['DEFAULT']['drivers'] = drivers + + if config_modified: + shutil.copyfile(co_conf, co_conf_bak) + with open(co_conf, 'w') as configfile: + config.write(configfile) + + +set_drivers_config() diff --git a/doctor_tests/installer/mcp.py b/doctor_tests/installer/mcp.py index e7e41dbe..9cfff92d 100644 --- a/doctor_tests/installer/mcp.py +++ b/doctor_tests/installer/mcp.py @@ -78,7 +78,7 @@ class McpInstaller(BaseInstaller): self.controller_clients.append(client) self._run_apply_patches(client, restart_cm_cmd, - self.cm_set_script) + [self.cm_set_script]) def restore_apply_patches(self): self.log.info('restore apply patches start......') @@ -87,4 +87,4 @@ class McpInstaller(BaseInstaller): for client in self.controller_clients: self._run_apply_patches(client, restart_cm_cmd, - self.cm_restore_script) + [self.cm_restore_script]) |