summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2018-03-07 14:02:08 +0100
committerCédric Ollivier <cedric.ollivier@orange.com>2018-03-07 20:30:28 +0100
commit0174b1962464c289d777caa88c91ff2c20be910a (patch)
tree475928cf8ab88d14112ef21498ce6ab59273daa1
parentd2620ae72be08f83548be81fa80a418f2250da28 (diff)
Allow overriding tempest output dir
Change-Id: I31a5d2772bab168b3cb4e6b0713d6e95aa5b6fd7 Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
-rw-r--r--functest/opnfv_tests/openstack/patrole/patrole.py34
-rw-r--r--functest/opnfv_tests/openstack/tempest/conf_utils.py32
-rw-r--r--functest/opnfv_tests/openstack/tempest/tempest.py30
-rw-r--r--functest/tests/unit/openstack/tempest/test_conf_utils.py11
-rw-r--r--functest/tests/unit/openstack/tempest/test_tempest.py7
5 files changed, 63 insertions, 51 deletions
diff --git a/functest/opnfv_tests/openstack/patrole/patrole.py b/functest/opnfv_tests/openstack/patrole/patrole.py
index 363784076..226f6812d 100644
--- a/functest/opnfv_tests/openstack/patrole/patrole.py
+++ b/functest/opnfv_tests/openstack/patrole/patrole.py
@@ -13,10 +13,12 @@ import logging
import os
import time
+from xtesting.core import testcase
+
from functest.opnfv_tests.openstack.snaps import snaps_utils
from functest.opnfv_tests.openstack.tempest import conf_utils
from functest.opnfv_tests.openstack.tempest import tempest
-from xtesting.core import testcase
+from functest.utils import config
class Patrole(tempest.TempestCommon):
@@ -28,12 +30,16 @@ class Patrole(tempest.TempestCommon):
kwargs["case_name"] = 'patrole'
super(Patrole, self).__init__(**kwargs)
self.mode = "^patrole_tempest_plugin."
+ self.res_dir = os.path.join(
+ getattr(config.CONF, 'dir_results'), 'patrole')
+ self.raw_list = os.path.join(self.res_dir, 'test_raw_list.txt')
+ self.list = os.path.join(self.res_dir, 'test_list.txt')
def run(self, **kwargs):
self.start_time = time.time()
try:
- if not os.path.exists(conf_utils.TEMPEST_RESULTS_DIR):
- os.makedirs(conf_utils.TEMPEST_RESULTS_DIR)
+ if not os.path.exists(self.res_dir):
+ os.makedirs(self.res_dir)
resources = self.resources.create()
compute_cnt = snaps_utils.get_active_compute_cnt(
self.resources.os_creds)
@@ -42,7 +48,8 @@ class Patrole(tempest.TempestCommon):
network_name=resources.get("network_name"),
image_id=resources.get("image_id"),
flavor_id=resources.get("flavor_id"),
- compute_cnt=compute_cnt)
+ compute_cnt=compute_cnt,
+ role=kwargs.get('role', 'admin'))
self.generate_test_list(self.verifier_repo_dir)
self.apply_tempest_blacklist()
self.run_verifier_tests()
@@ -59,7 +66,7 @@ class Patrole(tempest.TempestCommon):
def configure_tempest_patrole(
self, deployment_dir, network_name=None, image_id=None,
- flavor_id=None, compute_cnt=None):
+ flavor_id=None, compute_cnt=None, role='admin'):
# pylint: disable=too-many-arguments
"""
Add/update needed parameters into tempest.conf file
@@ -68,12 +75,13 @@ class Patrole(tempest.TempestCommon):
"Updating selected tempest.conf parameters for Patrole")
conf_file = conf_utils.configure_verifier(deployment_dir)
conf_utils.configure_tempest_update_params(
- conf_file, network_name, image_id, flavor_id, compute_cnt)
- config = conf_utils.ConfigParser.RawConfigParser()
- config.read(conf_file)
- config.set('identity-feature-enabled', 'api_v2', False)
- config.add_section('rbac')
- config.set('rbac', 'enable_rbac', True)
- config.set('rbac', 'rbac_test_role', 'admin')
+ conf_file, self.res_dir, network_name, image_id, flavor_id,
+ compute_cnt)
+ rconfig = conf_utils.ConfigParser.RawConfigParser()
+ rconfig.read(conf_file)
+ rconfig.set('identity-feature-enabled', 'api_v2', False)
+ rconfig.add_section('rbac')
+ rconfig.set('rbac', 'enable_rbac', True)
+ rconfig.set('rbac', 'rbac_test_role', role)
with open(conf_file, 'wb') as config_file:
- config.write(config_file)
+ rconfig.write(config_file)
diff --git a/functest/opnfv_tests/openstack/tempest/conf_utils.py b/functest/opnfv_tests/openstack/tempest/conf_utils.py
index fbf9c739b..6121ab970 100644
--- a/functest/opnfv_tests/openstack/tempest/conf_utils.py
+++ b/functest/opnfv_tests/openstack/tempest/conf_utils.py
@@ -33,14 +33,10 @@ RALLY_AARCH64_PATCH_PATH = pkg_resources.resource_filename(
GLANCE_IMAGE_PATH = os.path.join(
getattr(config.CONF, 'dir_functest_images'),
getattr(config.CONF, 'openstack_image_file_name'))
-TEMPEST_RESULTS_DIR = os.path.join(
- getattr(config.CONF, 'dir_results'), 'tempest')
TEMPEST_CUSTOM = pkg_resources.resource_filename(
'functest', 'opnfv_tests/openstack/tempest/custom_tests/test_list.txt')
TEMPEST_BLACKLIST = pkg_resources.resource_filename(
'functest', 'opnfv_tests/openstack/tempest/custom_tests/blacklist.txt')
-TEMPEST_RAW_LIST = os.path.join(TEMPEST_RESULTS_DIR, 'test_raw_list.txt')
-TEMPEST_LIST = os.path.join(TEMPEST_RESULTS_DIR, 'test_list.txt')
TEMPEST_CONF_YAML = pkg_resources.resource_filename(
'functest', 'opnfv_tests/openstack/tempest/custom_tests/tempest_conf.yaml')
TEST_ACCOUNTS_FILE = pkg_resources.resource_filename(
@@ -93,8 +89,7 @@ def create_verifier():
getattr(config.CONF, 'tempest_verifier_name'))
ft_utils.execute_command(cmd, error_msg=(
"Verifier %s does not exist."
- % getattr(config.CONF, 'tempest_verifier_name')),
- verbose=False)
+ % getattr(config.CONF, 'tempest_verifier_name')), verbose=False)
cmd = ("rally verify create-verifier --source {0} "
"--name {1} --type tempest --system-wide"
.format(getattr(config.CONF, 'dir_repo_tempest'),
@@ -168,24 +163,25 @@ def get_verifier_deployment_dir(verifier_id, deployment_id):
'for-deployment-{}'.format(deployment_id))
-def backup_tempest_config(conf_file):
+def backup_tempest_config(conf_file, res_dir):
"""
Copy config file to tempest results directory
"""
- if not os.path.exists(TEMPEST_RESULTS_DIR):
- os.makedirs(TEMPEST_RESULTS_DIR)
+ if not os.path.exists(res_dir):
+ os.makedirs(res_dir)
shutil.copyfile(conf_file,
- os.path.join(TEMPEST_RESULTS_DIR, 'tempest.conf'))
+ os.path.join(res_dir, 'tempest.conf'))
-def configure_tempest(deployment_dir, network_name=None, image_id=None,
- flavor_id=None, compute_cnt=None):
+def configure_tempest(deployment_dir, res_dir, network_name=None,
+ image_id=None, flavor_id=None, compute_cnt=None):
+ # pylint: disable=too-many-arguments
"""
Calls rally verify and updates the generated tempest.conf with
given parameters
"""
conf_file = configure_verifier(deployment_dir)
- configure_tempest_update_params(conf_file, network_name, image_id,
+ configure_tempest_update_params(conf_file, res_dir, network_name, image_id,
flavor_id, compute_cnt)
@@ -226,10 +222,10 @@ def update_tempest_conf_file(conf_file, rconfig):
rconfig.write(config_file)
-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
+def configure_tempest_update_params(tempest_conf_file, res_dir,
+ network_name=None, image_id=None,
+ flavor_id=None, compute_cnt=1):
+ # pylint: disable=too-many-branches, too-many-arguments
"""
Add/update needed parameters into tempest.conf file
"""
@@ -290,7 +286,7 @@ def configure_tempest_update_params(tempest_conf_file, network_name=None,
'into tempest.conf file')
update_tempest_conf_file(tempest_conf_file, rconfig)
- backup_tempest_config(tempest_conf_file)
+ 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 f2b82d886..a0c09ac06 100644
--- a/functest/opnfv_tests/openstack/tempest/tempest.py
+++ b/functest/opnfv_tests/openstack/tempest/tempest.py
@@ -44,6 +44,9 @@ class TempestCommon(testcase.TestCase):
# pylint: disable=too-many-instance-attributes
"""TempestCommon testcases implementation class."""
+ TEMPEST_RESULTS_DIR = os.path.join(
+ getattr(config.CONF, 'dir_results'), 'tempest')
+
def __init__(self, **kwargs):
super(TempestCommon, self).__init__(**kwargs)
self.resources = TempestResourcesManager(**kwargs)
@@ -56,6 +59,9 @@ class TempestCommon(testcase.TestCase):
self.deployment_dir = conf_utils.get_verifier_deployment_dir(
self.verifier_id, self.deployment_id)
self.verification_id = None
+ self.res_dir = TempestCommon.TEMPEST_RESULTS_DIR
+ self.raw_list = os.path.join(self.res_dir, 'test_raw_list.txt')
+ self.list = os.path.join(self.res_dir, 'test_list.txt')
@staticmethod
def read_file(filename):
@@ -98,7 +104,7 @@ class TempestCommon(testcase.TestCase):
if self.mode == 'custom':
if os.path.isfile(conf_utils.TEMPEST_CUSTOM):
shutil.copyfile(
- conf_utils.TEMPEST_CUSTOM, conf_utils.TEMPEST_RAW_LIST)
+ conf_utils.TEMPEST_CUSTOM, self.raw_list)
else:
raise Exception("Tempest test list file %s NOT found."
% conf_utils.TEMPEST_CUSTOM)
@@ -113,14 +119,14 @@ class TempestCommon(testcase.TestCase):
"testr list-tests {1} > {2};"
"cd -;".format(verifier_repo_dir,
testr_mode,
- conf_utils.TEMPEST_RAW_LIST))
+ self.raw_list))
functest_utils.execute_command(cmd)
def apply_tempest_blacklist(self):
"""Exclude blacklisted test cases."""
LOGGER.debug("Applying tempest blacklist...")
- cases_file = self.read_file(conf_utils.TEMPEST_RAW_LIST)
- result_file = open(conf_utils.TEMPEST_LIST, 'w')
+ cases_file = self.read_file(self.raw_list)
+ result_file = open(self.list, 'w')
black_tests = []
try:
installer_type = env.get('INSTALLER_TYPE')
@@ -155,14 +161,14 @@ class TempestCommon(testcase.TestCase):
def run_verifier_tests(self):
"""Execute tempest test cases."""
cmd = ["rally", "verify", "start", "--load-list",
- conf_utils.TEMPEST_LIST]
+ self.list]
cmd.extend(self.option)
LOGGER.info("Starting Tempest test suite: '%s'.", cmd)
f_stdout = open(
- os.path.join(conf_utils.TEMPEST_RESULTS_DIR, "tempest.log"), 'w+')
+ os.path.join(self.res_dir, "tempest.log"), 'w+')
f_stderr = open(
- os.path.join(conf_utils.TEMPEST_RESULTS_DIR,
+ os.path.join(self.res_dir,
"tempest-error.log"), 'w+')
proc = subprocess.Popen(
@@ -205,7 +211,7 @@ class TempestCommon(testcase.TestCase):
LOGGER.error("No test has been executed")
return
- with open(os.path.join(conf_utils.TEMPEST_RESULTS_DIR,
+ with open(os.path.join(self.res_dir,
"tempest.log"), 'r') as logfile:
output = logfile.read()
@@ -232,7 +238,7 @@ class TempestCommon(testcase.TestCase):
def generate_report(self):
"""Generate verification report."""
- html_file = os.path.join(conf_utils.TEMPEST_RESULTS_DIR,
+ html_file = os.path.join(self.res_dir,
"tempest-report.html")
cmd = ["rally", "verify", "report", "--type", "html", "--uuid",
self.verification_id, "--to", html_file]
@@ -243,13 +249,13 @@ class TempestCommon(testcase.TestCase):
self.start_time = time.time()
try:
- if not os.path.exists(conf_utils.TEMPEST_RESULTS_DIR):
- os.makedirs(conf_utils.TEMPEST_RESULTS_DIR)
+ if not os.path.exists(self.res_dir):
+ os.makedirs(self.res_dir)
resources = self.resources.create()
compute_cnt = snaps_utils.get_active_compute_cnt(
self.resources.os_creds)
conf_utils.configure_tempest(
- self.deployment_dir,
+ self.deployment_dir, self.res_dir,
network_name=resources.get("network_name"),
image_id=resources.get("image_id"),
flavor_id=resources.get("flavor_id"),
diff --git a/functest/tests/unit/openstack/tempest/test_conf_utils.py b/functest/tests/unit/openstack/tempest/test_conf_utils.py
index 1d5f29a2c..1c9a8aeee 100644
--- a/functest/tests/unit/openstack/tempest/test_conf_utils.py
+++ b/functest/tests/unit/openstack/tempest/test_conf_utils.py
@@ -219,7 +219,8 @@ class OSTempestConfUtilsTesting(unittest.TestCase):
'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')
+ conf_utils.backup_tempest_config(
+ 'test_conf_file', res_dir='test_dir')
self.assertTrue(mock_makedirs.called)
self.assertTrue(mock_copyfile.called)
@@ -228,7 +229,8 @@ class OSTempestConfUtilsTesting(unittest.TestCase):
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')
+ conf_utils.backup_tempest_config(
+ 'test_conf_file', res_dir='test_dir')
self.assertTrue(mock_copyfile.called)
def test_conf_tempest_def(self):
@@ -238,7 +240,7 @@ class OSTempestConfUtilsTesting(unittest.TestCase):
mock.patch('functest.opnfv_tests.openstack.tempest.'
'conf_utils.configure_tempest_update_params')\
as mock_upd:
- conf_utils.configure_tempest('test_dep_dir')
+ conf_utils.configure_tempest('test_dep_dir', 'test_dir')
self.assertTrue(mock_upd.called)
def test_gen_test_accounts_file_def(self):
@@ -265,7 +267,8 @@ class OSTempestConfUtilsTesting(unittest.TestCase):
return_value={'validation': {'ssh_timeout': 300}}):
os.environ['OS_ENDPOINT_TYPE'] = ''
conf_utils.configure_tempest_update_params(
- 'test_conf_file', image_id=image_id, flavor_id=flavor_id)
+ 'test_conf_file', res_dir='test_dir', image_id=image_id,
+ flavor_id=flavor_id)
mset.assert_any_call(params[0], params[1], params[2])
self.assertTrue(mread.called)
self.assertTrue(mwrite.called)
diff --git a/functest/tests/unit/openstack/tempest/test_tempest.py b/functest/tests/unit/openstack/tempest/test_tempest.py
index 8600506ad..2b9dcff44 100644
--- a/functest/tests/unit/openstack/tempest/test_tempest.py
+++ b/functest/tests/unit/openstack/tempest/test_tempest.py
@@ -80,14 +80,13 @@ class OSTempestTesting(unittest.TestCase):
testr_mode = r"'^tempest\.'"
else:
testr_mode = 'tempest.api.' + self.tempestcommon.mode
- conf_utils.TEMPEST_RAW_LIST = 'raw_list'
verifier_repo_dir = 'test_verifier_repo_dir'
cmd = ("cd {0};"
"testr list-tests {1} > {2};"
"cd -;".format(verifier_repo_dir, testr_mode,
- conf_utils.TEMPEST_RAW_LIST))
+ self.tempestcommon.raw_list))
self.tempestcommon.generate_test_list('test_verifier_repo_dir')
- mock_exec.assert_any_call(cmd)
+ mock_exec.assert_called_once_with(cmd)
def test_gen_tl_smoke_mode(self):
self._test_gen_tl_mode_default('smoke')
@@ -146,7 +145,7 @@ class OSTempestTesting(unittest.TestCase):
'subprocess.Popen')
def test_generate_report(self, mock_popen):
self.tempestcommon.verification_id = "1234"
- html_file = os.path.join(conf_utils.TEMPEST_RESULTS_DIR,
+ html_file = os.path.join(tempest.TempestCommon.TEMPEST_RESULTS_DIR,
"tempest-report.html")
cmd = ["rally", "verify", "report", "--type", "html", "--uuid",
"1234", "--to", html_file]