Fix role processing in Patrole 11/55611/2
authorCédric Ollivier <cedric.ollivier@orange.com>
Thu, 12 Apr 2018 18:58:01 +0000 (20:58 +0200)
committerCédric Ollivier <cedric.ollivier@orange.com>
Thu, 12 Apr 2018 19:05:55 +0000 (21:05 +0200)
Role has to be listed in tempest.conf before calling testr.
It also saves the right config file.

Change-Id: Ifd122f31d0bfe3e9b3f93c6d62526acce96953d3
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
functest/opnfv_tests/openstack/patrole/patrole.py
functest/opnfv_tests/openstack/tempest/conf_utils.py
functest/opnfv_tests/openstack/tempest/tempest.py
functest/tests/unit/openstack/tempest/test_conf_utils.py
functest/tests/unit/openstack/tempest/test_tempest.py

index dbf5ed0..0c5eedf 100644 (file)
@@ -41,6 +41,12 @@ class Patrole(tempest.TempestCommon):
         rconfig.set('rbac', 'rbac_test_role', kwargs.get('role', 'admin'))
         with open(self.conf_file, 'wb') as config_file:
             rconfig.write(config_file)
+        self.backup_tempest_config(self.conf_file, self.res_dir)
+
+    def generate_test_list(self):
+        self.backup_tempest_config(self.conf_file, '/etc')
+        super(Patrole, self).generate_test_list()
+        os.remove('/etc/tempest.conf')
 
     def run(self, **kwargs):
         for exclude in kwargs.get('exclude', []):
index be6480e..6a3d2d6 100644 (file)
@@ -14,7 +14,6 @@ import ConfigParser
 import logging
 import fileinput
 import os
-import shutil
 import subprocess
 
 import pkg_resources
@@ -167,16 +166,6 @@ def get_verifier_deployment_dir(verifier_id, deployment_id):
                         'for-deployment-{}'.format(deployment_id))
 
 
-def backup_tempest_config(conf_file, res_dir):
-    """
-    Copy config file to tempest results directory
-    """
-    if not os.path.exists(res_dir):
-        os.makedirs(res_dir)
-    shutil.copyfile(conf_file,
-                    os.path.join(res_dir, 'tempest.conf'))
-
-
 def update_tempest_conf_file(conf_file, rconfig):
     """Update defined paramters into tempest config file"""
     with open(TEMPEST_CONF_YAML) as yfile:
@@ -194,7 +183,7 @@ def update_tempest_conf_file(conf_file, rconfig):
         rconfig.write(config_file)
 
 
-def configure_tempest_update_params(tempest_conf_file, res_dir,
+def configure_tempest_update_params(tempest_conf_file,
                                     network_name=None, image_id=None,
                                     flavor_id=None, compute_cnt=1):
     # pylint: disable=too-many-branches, too-many-arguments
@@ -253,8 +242,6 @@ def configure_tempest_update_params(tempest_conf_file, res_dir,
                  'into tempest.conf file')
     update_tempest_conf_file(tempest_conf_file, rconfig)
 
-    backup_tempest_config(tempest_conf_file, res_dir)
-
 
 def configure_verifier(deployment_dir):
     """
index 22cb64c..9d001a8 100644 (file)
@@ -97,6 +97,16 @@ class TempestCommon(testcase.TestCase):
                 result['num_failures'] = int(new_line[2])
         return result
 
+    @staticmethod
+    def backup_tempest_config(conf_file, res_dir):
+        """
+        Copy config file to tempest results directory
+        """
+        if not os.path.exists(res_dir):
+            os.makedirs(res_dir)
+        shutil.copyfile(conf_file,
+                        os.path.join(res_dir, 'tempest.conf'))
+
     def generate_test_list(self):
         """Generate test list based on the test mode."""
         LOGGER.debug("Generating test case list...")
@@ -259,11 +269,11 @@ class TempestCommon(testcase.TestCase):
             self.resources.os_creds)
         self.conf_file = conf_utils.configure_verifier(self.deployment_dir)
         conf_utils.configure_tempest_update_params(
-            self.conf_file, self.res_dir,
-            network_name=resources.get("network_name"),
+            self.conf_file, network_name=resources.get("network_name"),
             image_id=resources.get("image_id"),
             flavor_id=resources.get("flavor_id"),
             compute_cnt=compute_cnt)
+        self.backup_tempest_config(self.conf_file, self.res_dir)
 
     def run(self, **kwargs):
         self.start_time = time.time()
index 161d9c0..8988e96 100644 (file)
@@ -188,28 +188,6 @@ class OSTempestConfUtilsTesting(unittest.TestCase):
             self.assertTrue(mock_get_vid.called)
             self.assertTrue(mock_get_did.called)
 
-    def test_backup_config_default(self):
-        with mock.patch('functest.opnfv_tests.openstack.tempest.'
-                        'conf_utils.os.path.exists',
-                        return_value=False), \
-            mock.patch('functest.opnfv_tests.openstack.tempest.'
-                       'conf_utils.os.makedirs') as mock_makedirs, \
-            mock.patch('functest.opnfv_tests.openstack.tempest.'
-                       'conf_utils.shutil.copyfile') as mock_copyfile:
-            conf_utils.backup_tempest_config(
-                'test_conf_file', res_dir='test_dir')
-            self.assertTrue(mock_makedirs.called)
-            self.assertTrue(mock_copyfile.called)
-
-        with mock.patch('functest.opnfv_tests.openstack.tempest.'
-                        'conf_utils.os.path.exists',
-                        return_value=True), \
-            mock.patch('functest.opnfv_tests.openstack.tempest.'
-                       'conf_utils.shutil.copyfile') as mock_copyfile:
-            conf_utils.backup_tempest_config(
-                'test_conf_file', res_dir='test_dir')
-            self.assertTrue(mock_copyfile.called)
-
     def _test_missing_param(self, params, image_id, flavor_id):
         with mock.patch('functest.opnfv_tests.openstack.tempest.'
                         'conf_utils.ConfigParser.RawConfigParser.'
@@ -221,13 +199,11 @@ class OSTempestConfUtilsTesting(unittest.TestCase):
                        'conf_utils.ConfigParser.RawConfigParser.'
                        'write') as mwrite, \
             mock.patch('__builtin__.open', mock.mock_open()), \
-            mock.patch('functest.opnfv_tests.openstack.tempest.'
-                       'conf_utils.backup_tempest_config'), \
             mock.patch('functest.utils.functest_utils.yaml.safe_load',
                        return_value={'validation': {'ssh_timeout': 300}}):
             os.environ['OS_ENDPOINT_TYPE'] = ''
             conf_utils.configure_tempest_update_params(
-                'test_conf_file', res_dir='test_dir', image_id=image_id,
+                'test_conf_file', image_id=image_id,
                 flavor_id=flavor_id)
             mset.assert_any_call(params[0], params[1], params[2])
             self.assertTrue(mread.called)
index e2c4c97..1fea4e4 100644 (file)
@@ -20,6 +20,7 @@ from functest.opnfv_tests.openstack.tempest import conf_utils
 
 
 class OSTempestTesting(unittest.TestCase):
+    # pylint: disable=too-many-public-methods
 
     def setUp(self):
         os_creds = OSCreds(
@@ -101,6 +102,21 @@ class OSTempestTesting(unittest.TestCase):
         with self.assertRaises(Exception):
             self.tempestcommon.parse_verifier_result()
 
+    def test_backup_config_default(self):
+        with mock.patch('os.path.exists', return_value=False), \
+                mock.patch('os.makedirs') as mock_makedirs, \
+                mock.patch('shutil.copyfile') as mock_copyfile:
+            self.tempestcommon.backup_tempest_config(
+                'test_conf_file', res_dir='test_dir')
+            self.assertTrue(mock_makedirs.called)
+            self.assertTrue(mock_copyfile.called)
+
+        with mock.patch('os.path.exists', return_value=True), \
+                mock.patch('shutil.copyfile') as mock_copyfile:
+            self.tempestcommon.backup_tempest_config(
+                'test_conf_file', res_dir='test_dir')
+            self.assertTrue(mock_copyfile.called)
+
     @mock.patch("os.rename")
     @mock.patch("os.remove")
     @mock.patch("os.path.exists", return_value=True)