aboutsummaryrefslogtreecommitdiffstats
path: root/functest
diff options
context:
space:
mode:
Diffstat (limited to 'functest')
-rw-r--r--functest/ci/config_functest.yaml2
-rw-r--r--functest/ci/prepare_env.py74
-rw-r--r--functest/opnfv_tests/openstack/rally/rally.py2
-rw-r--r--functest/opnfv_tests/openstack/tempest/conf_utils.py62
-rw-r--r--functest/tests/unit/ci/test_prepare_env.py83
-rw-r--r--functest/tests/unit/openstack/rally/test_rally.py13
-rw-r--r--functest/tests/unit/openstack/tempest/test_conf_utils.py74
7 files changed, 144 insertions, 166 deletions
diff --git a/functest/ci/config_functest.yaml b/functest/ci/config_functest.yaml
index 575b4478..e2746cf3 100644
--- a/functest/ci/config_functest.yaml
+++ b/functest/ci/config_functest.yaml
@@ -111,7 +111,7 @@ odl_sfc:
tempest:
unique_names: True
- deployment_name: opnfv-tempest
+ verifier_name: opnfv-tempest
identity:
tenant_name: tempest
tenant_description: Tenant for Tempest test suite
diff --git a/functest/ci/prepare_env.py b/functest/ci/prepare_env.py
index 36d04296..c2b6874c 100644
--- a/functest/ci/prepare_env.py
+++ b/functest/ci/prepare_env.py
@@ -7,15 +7,12 @@
#
import argparse
-import json
import logging
import logging.config
import os
import pkg_resources
import re
-import subprocess
import sys
-import fileinput
import yaml
@@ -42,9 +39,6 @@ CONFIG_PATCH_PATH = pkg_resources.resource_filename(
'functest', 'ci/config_patch.yaml')
CONFIG_AARCH64_PATCH_PATH = pkg_resources.resource_filename(
'functest', 'ci/config_aarch64_patch.yaml')
-RALLY_CONF_PATH = "/etc/rally/rally.conf"
-RALLY_AARCH64_PATCH_PATH = pkg_resources.resource_filename(
- 'functest', 'ci/rally_aarch64_patch.conf')
class PrepareEnvParser(object):
@@ -118,7 +112,7 @@ def get_deployment_handler():
global pod_arch
installer_params_yaml = pkg_resources.resource_filename(
- 'functest', 'ci/installer_params.yaml')
+ 'functest', 'ci/installer_params.yaml')
if (CONST.__getattribute__('INSTALLER_IP') and
CONST.__getattribute__('INSTALLER_TYPE') and
CONST.__getattribute__('INSTALLER_TYPE') in
@@ -236,70 +230,6 @@ def verify_deployment():
deployment.check_all()
-def install_rally():
- print_separator()
-
- if pod_arch and pod_arch in arch_filter:
- logger.info("Apply aarch64 specific to rally config...")
- with open(RALLY_AARCH64_PATCH_PATH, "r") as f:
- rally_patch_conf = f.read()
-
- for line in fileinput.input(RALLY_CONF_PATH, inplace=1):
- print line,
- if "cirros|testvm" in line:
- print rally_patch_conf
-
- logger.info("Creating Rally environment...")
-
- cmd = "rally deployment destroy opnfv-rally"
- ft_utils.execute_command(cmd, error_msg=(
- "Deployment %s does not exist."
- % CONST.__getattribute__('rally_deployment_name')),
- verbose=False)
-
- rally_conf = os_utils.get_credentials_for_rally()
- with open('rally_conf.json', 'w') as fp:
- json.dump(rally_conf, fp)
- cmd = ("rally deployment create "
- "--file=rally_conf.json --name={0}"
- .format(CONST.__getattribute__('rally_deployment_name')))
- error_msg = "Problem while creating Rally deployment"
- ft_utils.execute_command_raise(cmd, error_msg=error_msg)
-
- cmd = "rally deployment check"
- error_msg = "OpenStack not responding or faulty Rally deployment."
- ft_utils.execute_command_raise(cmd, error_msg=error_msg)
-
- cmd = "rally deployment list"
- ft_utils.execute_command(cmd,
- error_msg=("Problem while listing "
- "Rally deployment."))
-
- cmd = "rally plugin list | head -5"
- ft_utils.execute_command(cmd,
- error_msg=("Problem while showing "
- "Rally plugins."))
-
-
-def install_tempest():
- logger.info("Installing tempest from existing repo...")
- cmd = ("rally verify list-verifiers | "
- "grep '{0}' | wc -l".format(
- CONST.__getattribute__('tempest_deployment_name')))
- p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
- while p.poll() is None:
- line = p.stdout.readline().rstrip()
- if str(line) == '0':
- logger.debug("Tempest %s does not exist" %
- CONST.__getattribute__('tempest_deployment_name'))
- cmd = ("rally verify create-verifier --source {0} "
- "--name {1} --type tempest --system-wide"
- .format(CONST.__getattribute__('dir_repo_tempest'),
- CONST.__getattribute__('tempest_deployment_name')))
- error_msg = "Problem while installing Tempest."
- ft_utils.execute_command_raise(cmd, error_msg=error_msg)
-
-
def create_flavor():
_, flavor_id = os_utils.get_or_create_flavor('m1.tiny',
'512',
@@ -341,8 +271,6 @@ def prepare_env(**kwargs):
create_directories()
source_rc_file()
update_config_file()
- install_rally()
- install_tempest()
create_flavor()
with open(CONST.__getattribute__('env_active'), "w") as env_file:
env_file.write("1")
diff --git a/functest/opnfv_tests/openstack/rally/rally.py b/functest/opnfv_tests/openstack/rally/rally.py
index fd251899..a4970fc2 100644
--- a/functest/opnfv_tests/openstack/rally/rally.py
+++ b/functest/opnfv_tests/openstack/rally/rally.py
@@ -26,6 +26,7 @@ import yaml
from functest.core import testcase
from functest.energy import energy
from functest.opnfv_tests.openstack.snaps import snaps_utils
+from functest.opnfv_tests.openstack.tempest import conf_utils
from functest.utils.constants import CONST
from snaps.openstack.create_flavor import FlavorSettings, OpenStackFlavor
@@ -621,6 +622,7 @@ class RallyBase(testcase.TestCase):
"""Run testcase."""
self.start_time = time.time()
try:
+ conf_utils.create_rally_deployment()
self._prepare_env()
self._run_tests()
self._generate_report()
diff --git a/functest/opnfv_tests/openstack/tempest/conf_utils.py b/functest/opnfv_tests/openstack/tempest/conf_utils.py
index 7f7db35e..a361c506 100644
--- a/functest/opnfv_tests/openstack/tempest/conf_utils.py
+++ b/functest/opnfv_tests/openstack/tempest/conf_utils.py
@@ -8,7 +8,9 @@
# http://www.apache.org/licenses/LICENSE-2.0
#
import ConfigParser
+import json
import logging
+import fileinput
import os
import pkg_resources
import shutil
@@ -23,6 +25,9 @@ import functest.utils.openstack_utils as os_utils
IMAGE_ID_ALT = None
FLAVOR_ID_ALT = None
+RALLY_CONF_PATH = "/etc/rally/rally.conf"
+RALLY_AARCH64_PATCH_PATH = pkg_resources.resource_filename(
+ 'functest', 'ci/rally_aarch64_patch.conf')
GLANCE_IMAGE_PATH = os.path.join(
CONST.__getattribute__('dir_functest_images'),
CONST.__getattribute__('openstack_image_file_name'))
@@ -52,12 +57,67 @@ CI_INSTALLER_IP = CONST.__getattribute__('INSTALLER_IP')
logger = logging.getLogger(__name__)
+def create_rally_deployment():
+ # set the architecture to default
+ pod_arch = os.getenv("POD_ARCH", None)
+ arch_filter = ['aarch64']
+
+ if pod_arch and pod_arch in arch_filter:
+ logger.info("Apply aarch64 specific to rally config...")
+ with open(RALLY_AARCH64_PATCH_PATH, "r") as f:
+ rally_patch_conf = f.read()
+
+ for line in fileinput.input(RALLY_CONF_PATH, inplace=1):
+ print line,
+ if "cirros|testvm" in line:
+ print rally_patch_conf
+
+ logger.info("Creating Rally environment...")
+
+ cmd = "rally deployment destroy opnfv-rally"
+ ft_utils.execute_command(cmd, error_msg=(
+ "Deployment %s does not exist."
+ % CONST.__getattribute__('rally_deployment_name')),
+ verbose=False)
+
+ rally_conf = os_utils.get_credentials_for_rally()
+ with open('rally_conf.json', 'w') as fp:
+ json.dump(rally_conf, fp)
+ cmd = ("rally deployment create "
+ "--file=rally_conf.json --name={0}"
+ .format(CONST.__getattribute__('rally_deployment_name')))
+ error_msg = "Problem while creating Rally deployment"
+ ft_utils.execute_command_raise(cmd, error_msg=error_msg)
+
+ cmd = "rally deployment check"
+ error_msg = "OpenStack not responding or faulty Rally deployment."
+ ft_utils.execute_command_raise(cmd, error_msg=error_msg)
+
+
+def create_verifier():
+ logger.info("Create verifier from existing repo...")
+ cmd = ("rally verify delete-verifier --id '{0}' --force").format(
+ CONST.__getattribute__('tempest_verifier_name'))
+ ft_utils.execute_command(cmd, error_msg=(
+ "Verifier %s does not exist."
+ % CONST.__getattribute__('tempest_verifier_name')),
+ verbose=False)
+ cmd = ("rally verify create-verifier --source {0} "
+ "--name {1} --type tempest --system-wide"
+ .format(CONST.__getattribute__('dir_repo_tempest'),
+ CONST.__getattribute__('tempest_verifier_name')))
+ ft_utils.execute_command_raise(cmd,
+ error_msg='Problem while creating verifier')
+
+
def get_verifier_id():
"""
Returns verifier id for current Tempest
"""
+ create_rally_deployment()
+ create_verifier()
cmd = ("rally verify list-verifiers | awk '/" +
- CONST.__getattribute__('tempest_deployment_name') +
+ CONST.__getattribute__('tempest_verifier_name') +
"/ {print $2}'")
p = subprocess.Popen(cmd, shell=True,
stdout=subprocess.PIPE,
diff --git a/functest/tests/unit/ci/test_prepare_env.py b/functest/tests/unit/ci/test_prepare_env.py
index 7d5fa564..d53c68e6 100644
--- a/functest/tests/unit/ci/test_prepare_env.py
+++ b/functest/tests/unit/ci/test_prepare_env.py
@@ -259,27 +259,6 @@ class PrepareEnvTesting(unittest.TestCase):
opnfv_constants.INSTALLERS = []
prepare_env.source_rc_file()
- def test_source_rc_missing_os_credfile_ci_inst(self):
- with mock.patch('functest.ci.prepare_env.os.path.isfile',
- return_value=False), \
- mock.patch('functest.ci.prepare_env.os.path.getsize'), \
- mock.patch('functest.ci.prepare_env.os.path.join'), \
- mock.patch('functest.ci.prepare_env.subprocess.Popen') \
- as mock_subproc_popen, \
- self.assertRaises(Exception):
- CONST.__setattr__('openstack_creds', None)
- CONST.__setattr__('INSTALLER_IP', 'test_ip')
- CONST.__setattr__('INSTALLER_TYPE', 'test_type')
- opnfv_constants.INSTALLERS = ['test_type']
-
- process_mock = mock.Mock()
- attrs = {'communicate.return_value': ('output', 'error'),
- 'return_code': 1}
- process_mock.configure_mock(**attrs)
- mock_subproc_popen.return_value = process_mock
-
- prepare_env.source_rc_file()
-
@mock.patch('functest.ci.prepare_env.logger.debug')
def test_patch_file(self, mock_logger_debug):
with mock.patch("__builtin__.open", mock.mock_open()), \
@@ -328,61 +307,6 @@ class PrepareEnvTesting(unittest.TestCase):
"password": 'test_password',
"tenant": 'test_tenant'}}
- @mock.patch('functest.ci.prepare_env.os_utils.get_credentials_for_rally')
- @mock.patch('functest.ci.prepare_env.logger.info')
- @mock.patch('functest.ci.prepare_env.ft_utils.execute_command_raise')
- @mock.patch('functest.ci.prepare_env.ft_utils.execute_command')
- def test_install_rally(self, mock_exec, mock_exec_raise, mock_logger_info,
- mock_os_utils):
-
- mock_os_utils.return_value = self._get_rally_creds()
-
- prepare_env.install_rally()
-
- cmd = "rally deployment destroy opnfv-rally"
- error_msg = "Deployment %s does not exist." % \
- CONST.__getattribute__('rally_deployment_name')
- mock_logger_info.assert_any_call("Creating Rally environment...")
- mock_exec.assert_any_call(cmd, error_msg=error_msg, verbose=False)
-
- cmd = "rally deployment create --file=rally_conf.json --name="
- cmd += CONST.__getattribute__('rally_deployment_name')
- error_msg = "Problem while creating Rally deployment"
- mock_exec_raise.assert_any_call(cmd, error_msg=error_msg)
-
- cmd = "rally deployment check"
- error_msg = ("OpenStack not responding or "
- "faulty Rally deployment.")
- mock_exec_raise.assert_any_call(cmd, error_msg=error_msg)
-
- cmd = "rally deployment list"
- error_msg = ("Problem while listing "
- "Rally deployment.")
- mock_exec.assert_any_call(cmd, error_msg=error_msg)
-
- cmd = "rally plugin list | head -5"
- error_msg = ("Problem while showing "
- "Rally plugins.")
- mock_exec.assert_any_call(cmd, error_msg=error_msg)
-
- @mock.patch('functest.ci.prepare_env.logger.debug')
- def test_install_tempest(self, mock_logger_debug):
- mock_popen = mock.Mock()
- attrs = {'poll.return_value': None,
- 'stdout.readline.return_value': '0'}
- mock_popen.configure_mock(**attrs)
-
- CONST.__setattr__('tempest_deployment_name', 'test_dep_name')
- with mock.patch('functest.ci.prepare_env.'
- 'ft_utils.execute_command_raise',
- side_effect=Exception), \
- mock.patch('functest.ci.prepare_env.subprocess.Popen',
- return_value=mock_popen), \
- self.assertRaises(Exception):
- prepare_env.install_tempest()
- mock_logger_debug.assert_any_call("Tempest test_dep_name"
- " does not exist")
-
def test_create_flavor(self):
with mock.patch('functest.ci.prepare_env.'
'os_utils.get_or_create_flavor',
@@ -422,8 +346,6 @@ class PrepareEnvTesting(unittest.TestCase):
@mock.patch('functest.ci.prepare_env.check_environment')
@mock.patch('functest.ci.prepare_env.create_flavor')
- @mock.patch('functest.ci.prepare_env.install_tempest')
- @mock.patch('functest.ci.prepare_env.install_rally')
@mock.patch('functest.ci.prepare_env.verify_deployment')
@mock.patch('functest.ci.prepare_env.update_config_file')
@mock.patch('functest.ci.prepare_env.source_rc_file')
@@ -432,8 +354,7 @@ class PrepareEnvTesting(unittest.TestCase):
@mock.patch('functest.ci.prepare_env.logger.info')
def test_main_start(self, mock_logger_info, mock_env_var,
mock_create_dir, mock_source_rc, mock_update_config,
- mock_verify_depl, mock_install_rally,
- mock_install_temp, mock_create_flavor,
+ mock_verify_depl, mock_create_flavor,
mock_check_env):
with mock.patch("__builtin__.open", mock.mock_open()) as m:
args = {'action': 'start'}
@@ -445,8 +366,6 @@ class PrepareEnvTesting(unittest.TestCase):
self.assertTrue(mock_source_rc.called)
self.assertTrue(mock_update_config.called)
self.assertTrue(mock_verify_depl.called)
- self.assertTrue(mock_install_rally.called)
- self.assertTrue(mock_install_temp.called)
self.assertTrue(mock_create_flavor.called)
m.assert_called_once_with(
CONST.__getattribute__('env_active'), "w")
diff --git a/functest/tests/unit/openstack/rally/test_rally.py b/functest/tests/unit/openstack/rally/test_rally.py
index 6a85536d..83f0c86a 100644
--- a/functest/tests/unit/openstack/rally/test_rally.py
+++ b/functest/tests/unit/openstack/rally/test_rally.py
@@ -405,6 +405,8 @@ class OSRallyTesting(unittest.TestCase):
self.assertTrue(creator1.clean.called)
self.assertTrue(creator2.clean.called)
+ @mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
+ 'create_rally_deployment')
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
'_prepare_env')
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
@@ -417,9 +419,18 @@ class OSRallyTesting(unittest.TestCase):
self.assertEqual(self.rally_base.run(), testcase.TestCase.EX_OK)
map(lambda m: m.assert_called(), args)
+ @mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
+ 'create_rally_deployment', side_effect=Exception)
+ def test_run_exception_create_rally_dep(self, mock_create_rally_dep):
+ self.assertEqual(self.rally_base.run(), testcase.TestCase.EX_RUN_ERROR)
+ mock_create_rally_dep.assert_called()
+
@mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
'_prepare_env', side_effect=Exception)
- def test_run_exception(self, mock_prep_env):
+ @mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
+ 'create_rally_deployment', return_value=mock.Mock())
+ def test_run_exception_prepare_env(self, mock_create_rally_dep,
+ mock_prep_env):
self.assertEqual(self.rally_base.run(), testcase.TestCase.EX_RUN_ERROR)
mock_prep_env.assert_called()
diff --git a/functest/tests/unit/openstack/tempest/test_conf_utils.py b/functest/tests/unit/openstack/tempest/test_conf_utils.py
index 50b0edc6..f20a7e93 100644
--- a/functest/tests/unit/openstack/tempest/test_conf_utils.py
+++ b/functest/tests/unit/openstack/tempest/test_conf_utils.py
@@ -88,8 +88,62 @@ class OSTempestConfUtilsTesting(unittest.TestCase):
msg = 'Failed to create flavor'
self.assertTrue(msg in context.exception, msg=str(context.exception))
- def test_get_verifier_id_missing_verifier(self):
- CONST.__setattr__('tempest_deployment_name', 'test_deploy_name')
+ def _get_rally_creds(self):
+ return {"type": "ExistingCloud",
+ "admin": {"username": 'test_user_name',
+ "password": 'test_password',
+ "tenant": 'test_tenant'}}
+
+ @mock.patch('functest.utils.openstack_utils.get_credentials_for_rally')
+ @mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils'
+ '.logger.info')
+ @mock.patch('functest.utils.functest_utils.execute_command_raise')
+ @mock.patch('functest.utils.functest_utils.execute_command')
+ def test_create_rally_deployment(self, mock_exec, mock_exec_raise,
+ mock_logger_info, mock_os_utils):
+
+ mock_os_utils.return_value = self._get_rally_creds()
+
+ conf_utils.create_rally_deployment()
+
+ cmd = "rally deployment destroy opnfv-rally"
+ error_msg = "Deployment %s does not exist." % \
+ CONST.__getattribute__('rally_deployment_name')
+ mock_logger_info.assert_any_call("Creating Rally environment...")
+ mock_exec.assert_any_call(cmd, error_msg=error_msg, verbose=False)
+
+ cmd = "rally deployment create --file=rally_conf.json --name="
+ cmd += CONST.__getattribute__('rally_deployment_name')
+ error_msg = "Problem while creating Rally deployment"
+ mock_exec_raise.assert_any_call(cmd, error_msg=error_msg)
+
+ cmd = "rally deployment check"
+ error_msg = ("OpenStack not responding or "
+ "faulty Rally deployment.")
+ mock_exec_raise.assert_any_call(cmd, error_msg=error_msg)
+
+ @mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils'
+ '.logger.debug')
+ def test_create_verifier(self, mock_logger_debug):
+ mock_popen = mock.Mock()
+ attrs = {'poll.return_value': None,
+ 'stdout.readline.return_value': '0'}
+ mock_popen.configure_mock(**attrs)
+
+ CONST.__setattr__('tempest_verifier_name', 'test_veifier_name')
+ with mock.patch('functest.utils.functest_utils.execute_command_raise',
+ side_effect=Exception), \
+ self.assertRaises(Exception):
+ conf_utils.create_verifier()
+ mock_logger_debug.assert_any_call("Tempest test_veifier_name"
+ " does not exist")
+
+ @mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
+ 'create_verifier', return_value=mock.Mock())
+ @mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
+ 'create_rally_deployment', return_value=mock.Mock())
+ def test_get_verifier_id_missing_verifier(self, mock_rally, mock_tempest):
+ CONST.__setattr__('tempest_verifier_name', 'test_verifier_name')
with mock.patch('functest.opnfv_tests.openstack.tempest.'
'conf_utils.subprocess.Popen') as mock_popen, \
self.assertRaises(Exception):
@@ -97,10 +151,14 @@ class OSTempestConfUtilsTesting(unittest.TestCase):
attrs = {'stdout.readline.return_value': ''}
mock_stdout.configure_mock(**attrs)
mock_popen.return_value = mock_stdout
- conf_utils.get_verifier_id(),
-
- def test_get_verifier_id_default(self):
- CONST.__setattr__('tempest_deployment_name', 'test_deploy_name')
+ conf_utils.get_verifier_id()
+
+ @mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
+ 'create_verifier', return_value=mock.Mock())
+ @mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.'
+ 'create_rally_deployment', return_value=mock.Mock())
+ def test_get_verifier_id_default(self, mock_rally, mock_tempest):
+ CONST.__setattr__('tempest_verifier_name', 'test_verifier_name')
with mock.patch('functest.opnfv_tests.openstack.tempest.'
'conf_utils.subprocess.Popen') as mock_popen:
mock_stdout = mock.Mock()
@@ -112,7 +170,7 @@ class OSTempestConfUtilsTesting(unittest.TestCase):
'test_deploy_id')
def test_get_verifier_deployment_id_missing_rally(self):
- CONST.__setattr__('tempest_deployment_name', 'test_deploy_name')
+ CONST.__setattr__('tempest_verifier_name', 'test_deploy_name')
with mock.patch('functest.opnfv_tests.openstack.tempest.'
'conf_utils.subprocess.Popen') as mock_popen, \
self.assertRaises(Exception):
@@ -123,7 +181,7 @@ class OSTempestConfUtilsTesting(unittest.TestCase):
conf_utils.get_verifier_deployment_id(),
def test_get_verifier_deployment_id_default(self):
- CONST.__setattr__('tempest_deployment_name', 'test_deploy_name')
+ CONST.__setattr__('tempest_verifier_name', 'test_deploy_name')
with mock.patch('functest.opnfv_tests.openstack.tempest.'
'conf_utils.subprocess.Popen') as mock_popen:
mock_stdout = mock.Mock()