summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--functest/opnfv_tests/openstack/patrole/patrole.py6
-rw-r--r--functest/opnfv_tests/openstack/tempest/conf_utils.py15
-rw-r--r--functest/opnfv_tests/openstack/tempest/tempest.py14
-rw-r--r--functest/tests/unit/openstack/tempest/test_conf_utils.py26
-rw-r--r--functest/tests/unit/openstack/tempest/test_tempest.py16
5 files changed, 36 insertions, 41 deletions
diff --git a/functest/opnfv_tests/openstack/patrole/patrole.py b/functest/opnfv_tests/openstack/patrole/patrole.py
index dbf5ed074..0c5eedf48 100644
--- a/functest/opnfv_tests/openstack/patrole/patrole.py
+++ b/functest/opnfv_tests/openstack/patrole/patrole.py
@@ -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', []):
diff --git a/functest/opnfv_tests/openstack/tempest/conf_utils.py b/functest/opnfv_tests/openstack/tempest/conf_utils.py
index be6480e42..6a3d2d6e8 100644
--- a/functest/opnfv_tests/openstack/tempest/conf_utils.py
+++ b/functest/opnfv_tests/openstack/tempest/conf_utils.py
@@ -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):
"""
diff --git a/functest/opnfv_tests/openstack/tempest/tempest.py b/functest/opnfv_tests/openstack/tempest/tempest.py
index 22cb64c6b..9d001a82e 100644
--- a/functest/opnfv_tests/openstack/tempest/tempest.py
+++ b/functest/opnfv_tests/openstack/tempest/tempest.py
@@ -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()
diff --git a/functest/tests/unit/openstack/tempest/test_conf_utils.py b/functest/tests/unit/openstack/tempest/test_conf_utils.py
index 161d9c076..8988e96a1 100644
--- a/functest/tests/unit/openstack/tempest/test_conf_utils.py
+++ b/functest/tests/unit/openstack/tempest/test_conf_utils.py
@@ -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)
diff --git a/functest/tests/unit/openstack/tempest/test_tempest.py b/functest/tests/unit/openstack/tempest/test_tempest.py
index e2c4c975b..1fea4e41d 100644
--- a/functest/tests/unit/openstack/tempest/test_tempest.py
+++ b/functest/tests/unit/openstack/tempest/test_tempest.py
@@ -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)