Publish rally logs 89/67989/1
authorCédric Ollivier <cedric.ollivier@orange.com>
Sun, 2 Jun 2019 12:43:10 +0000 (14:43 +0200)
committerCédric Ollivier <cedric.ollivier@orange.com>
Sun, 2 Jun 2019 12:48:29 +0000 (14:48 +0200)
Both Rally and Tempest publish Rally debug logs.
It also moves the logics from tempest to rally.

Change-Id: I5c057d830202baddd73577ade1b09ce304e3c5a5
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
functest/opnfv_tests/openstack/rally/rally.py
functest/opnfv_tests/openstack/tempest/tempest.py
functest/tests/unit/openstack/rally/test_rally.py

index 6dfdabe..61352c1 100644 (file)
@@ -629,6 +629,7 @@ class RallyBase(singlevm.VmReady2):
     def clean(self):
         """Cleanup of OpenStack resources. Should be called on completion."""
         self.clean_rally_conf()
+        self.clean_rally_logs()
         if self.flavor_alt:
             self.orig_cloud.delete_flavor(self.flavor_alt.id)
         super(RallyBase, self).clean()
@@ -641,12 +642,43 @@ class RallyBase(singlevm.VmReady2):
 
         return super(RallyBase, self).is_successful()
 
+    @staticmethod
+    def update_rally_logs(res_dir, rally_conf='/etc/rally/rally.conf'):
+        """Print rally logs in res dir"""
+        if not os.path.exists(res_dir):
+            os.makedirs(res_dir)
+        rconfig = configparser.RawConfigParser()
+        rconfig.read(rally_conf)
+        rconfig.set('DEFAULT', 'debug', True)
+        rconfig.set('DEFAULT', 'use_stderr', False)
+        rconfig.set('DEFAULT', 'log-file', 'rally.log')
+        rconfig.set('DEFAULT', 'log_dir', res_dir)
+        with open(rally_conf, 'w') as config_file:
+            rconfig.write(config_file)
+
+    @staticmethod
+    def clean_rally_logs(rally_conf='/etc/rally/rally.conf'):
+        """Clean Rally config"""
+        rconfig = configparser.RawConfigParser()
+        rconfig.read(rally_conf)
+        if rconfig.has_option('DEFAULT', 'use_stderr'):
+            rconfig.remove_option('DEFAULT', 'use_stderr')
+        if rconfig.has_option('DEFAULT', 'debug'):
+            rconfig.remove_option('DEFAULT', 'debug')
+        if rconfig.has_option('DEFAULT', 'log-file'):
+            rconfig.remove_option('DEFAULT', 'log-file')
+        if rconfig.has_option('DEFAULT', 'log_dir'):
+            rconfig.remove_option('DEFAULT', 'log_dir')
+        with open(rally_conf, 'w') as config_file:
+            rconfig.write(config_file)
+
     def run(self, **kwargs):
         """Run testcase."""
         self.start_time = time.time()
         try:
             assert super(RallyBase, self).run(
                 **kwargs) == testcase.TestCase.EX_OK
+            self.update_rally_logs(self.res_dir)
             self.create_rally_deployment(environ=self.project.get_environ())
             self.prepare_run(**kwargs)
             self.run_tests(**kwargs)
index 831f732..fb0c155 100644 (file)
@@ -489,19 +489,6 @@ class TempestCommon(singlevm.VmReady2):
         with open(rally_conf, 'w') as config_file:
             rconfig.write(config_file)
 
-    def update_rally_logs(self, rally_conf='/etc/rally/rally.conf'):
-        """Print rally logs in res dir"""
-        if not os.path.exists(self.res_dir):
-            os.makedirs(self.res_dir)
-        rconfig = configparser.RawConfigParser()
-        rconfig.read(rally_conf)
-        rconfig.set('DEFAULT', 'debug', True)
-        rconfig.set('DEFAULT', 'use_stderr', False)
-        rconfig.set('DEFAULT', 'log-file', 'rally.log')
-        rconfig.set('DEFAULT', 'log_dir', self.res_dir)
-        with open(rally_conf, 'w') as config_file:
-            rconfig.write(config_file)
-
     @staticmethod
     def clean_rally_conf(rally_conf='/etc/rally/rally.conf'):
         """Clean Rally config"""
@@ -511,14 +498,6 @@ class TempestCommon(singlevm.VmReady2):
             rconfig.remove_option('openstack', 'img_name_regex')
         if rconfig.has_option('openstack', 'swift_operator_role'):
             rconfig.remove_option('openstack', 'swift_operator_role')
-        if rconfig.has_option('DEFAULT', 'use_stderr'):
-            rconfig.remove_option('DEFAULT', 'use_stderr')
-        if rconfig.has_option('DEFAULT', 'debug'):
-            rconfig.remove_option('DEFAULT', 'debug')
-        if rconfig.has_option('DEFAULT', 'log-file'):
-            rconfig.remove_option('DEFAULT', 'log-file')
-        if rconfig.has_option('DEFAULT', 'log_dir'):
-            rconfig.remove_option('DEFAULT', 'log_dir')
         with open(rally_conf, 'w') as config_file:
             rconfig.write(config_file)
 
@@ -621,7 +600,7 @@ class TempestCommon(singlevm.VmReady2):
                 os.makedirs(self.res_dir)
             self.update_rally_regex()
             self.update_default_role()
-            self.update_rally_logs()
+            rally.RallyBase.update_rally_logs(self.res_dir)
             shutil.copy("/etc/rally/rally.conf", self.res_dir)
             self.configure(**kwargs)
             self.generate_test_list(**kwargs)
@@ -647,6 +626,7 @@ class TempestCommon(singlevm.VmReady2):
         Cleanup all OpenStack objects. Should be called on completion.
         """
         self.clean_rally_conf()
+        rally.RallyBase.clean_rally_logs()
         if self.image_alt:
             self.cloud.delete_image(self.image_alt)
         if self.flavor_alt:
index 83332c8..ac52b87 100644 (file)
@@ -325,13 +325,18 @@ class OSRallyTesting(unittest.TestCase):
         mock_run_task.assert_any_call('test1')
         mock_run_task.assert_any_call('test2')
 
-    def test_clean_up_default(self):
+    @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
+                'clean_rally_logs')
+    def test_clean_up_default(self, *args):
         with mock.patch.object(self.rally_base.orig_cloud,
                                'delete_flavor') as mock_delete_flavor:
             self.rally_base.flavor_alt = mock.Mock()
             self.rally_base.clean()
             self.assertEqual(mock_delete_flavor.call_count, 1)
+            args[0].assert_called_once_with()
 
+    @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
+                'update_rally_logs')
     @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
                 'create_rally_deployment')
     @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
@@ -347,12 +352,17 @@ class OSRallyTesting(unittest.TestCase):
         for func in args:
             func.assert_called()
 
+    @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
+                'update_rally_logs')
     @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
                 'create_rally_deployment', side_effect=Exception)
-    def test_run_exception_create_rally_dep(self, mock_create_rally_dep):
+    def test_run_exception_create_rally_dep(self, *args):
         self.assertEqual(self.rally_base.run(), testcase.TestCase.EX_RUN_ERROR)
-        mock_create_rally_dep.assert_called()
+        args[0].assert_called()
+        args[1].assert_called_once_with(self.rally_base.res_dir)
 
+    @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
+                'update_rally_logs')
     @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
                 'create_rally_deployment', return_value=mock.Mock())
     @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
@@ -361,6 +371,7 @@ class OSRallyTesting(unittest.TestCase):
         # pylint: disable=unused-argument
         self.assertEqual(self.rally_base.run(), testcase.TestCase.EX_RUN_ERROR)
         mock_prep_env.assert_called()
+        args[1].assert_called_once_with(self.rally_base.res_dir)
 
     def test_append_summary(self):
         json_dict = {