bugfix: add doctor datasource in congress 23/61223/7
authordongwenjuan <dong.wenjuan@zte.com.cn>
Wed, 22 Aug 2018 01:48:58 +0000 (09:48 +0800)
committerdongwenjuan <dong.wenjuan@zte.com.cn>
Thu, 23 Aug 2018 09:44:49 +0000 (17:44 +0800)
Change-Id: I465fd6c59daf99dd543488a15819dab78e8cdd7b
Signed-off-by: dongwenjuan <dong.wenjuan@zte.com.cn>
doctor_tests/installer/apex.py
doctor_tests/installer/base.py
doctor_tests/installer/common/congress.py [deleted file]
doctor_tests/installer/common/restore_congress.py [new file with mode: 0644]
doctor_tests/installer/common/set_congress.py [new file with mode: 0644]
doctor_tests/installer/mcp.py

index bfa72d3..694adb8 100644 (file)
@@ -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])
index 4eed3f2..953b36d 100644 (file)
@@ -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 (file)
index cc58c39..0000000
+++ /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 (file)
index 0000000..b5efb1e
--- /dev/null
@@ -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 (file)
index 0000000..d843870
--- /dev/null
@@ -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()
index e7e41db..9cfff92 100644 (file)
@@ -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])