Allow regex for blacklist scenarios/installers
[functest.git] / functest / tests / unit / openstack / rally / test_rally.py
index fe25dfc..def9c93 100644 (file)
@@ -19,8 +19,6 @@ from functest.utils.constants import CONST
 
 class OSRallyTesting(unittest.TestCase):
 
-    logging.disable(logging.CRITICAL)
-
     def setUp(self):
         self.nova_client = mock.Mock()
         self.neutron_client = mock.Mock()
@@ -39,7 +37,7 @@ class OSRallyTesting(unittest.TestCase):
             self.polling_iter = 2
 
     def test_build_task_args_missing_floating_network(self):
-        CONST.OS_AUTH_URL = None
+        CONST.__setattr__('OS_AUTH_URL', None)
         with mock.patch('functest.opnfv_tests.openstack.rally.rally.'
                         'os_utils.get_external_net',
                         return_value=None):
@@ -47,7 +45,7 @@ class OSRallyTesting(unittest.TestCase):
             self.assertEqual(task_args['floating_network'], '')
 
     def test_build_task_args_missing_net_id(self):
-        CONST.OS_AUTH_URL = None
+        CONST.__setattr__('OS_AUTH_URL', None)
         self.rally_base.network_dict['net_id'] = ''
         with mock.patch('functest.opnfv_tests.openstack.rally.rally.'
                         'os_utils.get_external_net',
@@ -55,14 +53,6 @@ class OSRallyTesting(unittest.TestCase):
             task_args = self.rally_base._build_task_args('test_file_name')
             self.assertEqual(task_args['netid'], '')
 
-    def test_build_task_args_missing_auth_url(self):
-        CONST.OS_AUTH_URL = None
-        with mock.patch('functest.opnfv_tests.openstack.rally.rally.'
-                        'os_utils.get_external_net',
-                        return_value='test_floating_network'):
-            task_args = self.rally_base._build_task_args('test_file_name')
-            self.assertEqual(task_args['request_url'], '')
-
     def check_scenario_file(self, value):
         yaml_file = 'opnfv-{}.yaml'.format('test_file_name')
         if yaml_file in value:
@@ -136,11 +126,14 @@ class OSRallyTesting(unittest.TestCase):
                          'lineline')
 
     def test_excl_scenario_default(self):
-        CONST.INSTALLER_TYPE = 'test_installer'
-        CONST.DEPLOY_SCENARIO = 'test_scenario'
+        CONST.__setattr__('INSTALLER_TYPE', 'test_installer')
+        CONST.__setattr__('DEPLOY_SCENARIO', 'test_scenario')
         dic = {'scenario': [{'scenarios': ['test_scenario'],
                              'installers': ['test_installer'],
-                             'tests': ['test']}]}
+                             'tests': ['test']},
+                            {'scenarios': ['other_scenario'],
+                             'installers': ['test_installer'],
+                             'tests': ['other_test']}]}
         with mock.patch('__builtin__.open', mock.mock_open()), \
             mock.patch('functest.opnfv_tests.openstack.rally.rally.'
                        'yaml.safe_load',
@@ -148,14 +141,42 @@ class OSRallyTesting(unittest.TestCase):
                 self.assertEqual(self.rally_base.excl_scenario(),
                                  ['test'])
 
+    def test_excl_scenario_regex(self):
+        CONST.__setattr__('INSTALLER_TYPE', 'test_installer')
+        CONST.__setattr__('DEPLOY_SCENARIO', 'os-ctrlT-featT-modeT')
+        dic = {'scenario': [{'scenarios': ['^os-[^-]+-featT-modeT$'],
+                             'installers': ['test_installer'],
+                             'tests': ['test1']},
+                            {'scenarios': ['^os-ctrlT-[^-]+-modeT$'],
+                             'installers': ['test_installer'],
+                             'tests': ['test2']},
+                            {'scenarios': ['^os-ctrlT-featT-[^-]+$'],
+                             'installers': ['test_installer'],
+                             'tests': ['test3']},
+                            {'scenarios': ['^os-'],
+                             'installers': ['test_installer'],
+                             'tests': ['test4']},
+                            {'scenarios': ['other_scenario'],
+                             'installers': ['test_installer'],
+                             'tests': ['test0a']},
+                            {'scenarios': [''],  # empty scenario
+                             'installers': ['test_installer'],
+                             'tests': ['test0b']}]}
+        with mock.patch('__builtin__.open', mock.mock_open()), \
+            mock.patch('functest.opnfv_tests.openstack.rally.rally.'
+                       'yaml.safe_load',
+                       return_value=dic):
+            self.assertEqual(self.rally_base.excl_scenario(),
+                             ['test1', 'test2', 'test3', 'test4'])
+
     def test_excl_scenario_exception(self):
         with mock.patch('__builtin__.open', side_effect=Exception):
                 self.assertEqual(self.rally_base.excl_scenario(),
                                  [])
 
     def test_excl_func_default(self):
-        CONST.INSTALLER_TYPE = 'test_installer'
-        CONST.DEPLOY_SCENARIO = 'test_scenario'
+        CONST.__setattr__('INSTALLER_TYPE', 'test_installer')
+        CONST.__setattr__('DEPLOY_SCENARIO', 'test_scenario')
         dic = {'functionality': [{'functions': ['no_live_migration'],
                                   'tests': ['test']}]}
         with mock.patch('__builtin__.open', mock.mock_open()), \
@@ -343,19 +364,6 @@ class OSRallyTesting(unittest.TestCase):
             self.rally_base._run_tests()
             self.rally_base._run_task.assert_any_call('test1')
 
-    @mock.patch('functest.opnfv_tests.openstack.rally.rally.logger.info')
-    def test_generate_report(self, mock_logger_info):
-        summary = [{'test_name': 'test_name',
-                    'overall_duration': 5,
-                    'nb_tests': 3,
-                    'success': 5}]
-        self.rally_base.summary = summary
-        with mock.patch('functest.opnfv_tests.openstack.rally.rally.'
-                        'ft_utils.check_success_rate',
-                        return_value='criteria'):
-            self.rally_base._generate_report()
-            self.assertTrue(mock_logger_info.called)
-
     def test_clean_up_default(self):
         self.rally_base.volume_type = mock.Mock()
         self.rally_base.cinder_client = mock.Mock()
@@ -388,4 +396,5 @@ class OSRallyTesting(unittest.TestCase):
 
 
 if __name__ == "__main__":
+    logging.disable(logging.CRITICAL)
     unittest.main(verbosity=2)