import time
import uuid
-import yaml
-
-from functest.core import testcase
-from functest.opnfv_tests.openstack.snaps import snaps_utils
-from functest.opnfv_tests.openstack.tempest import conf_utils
-from functest.utils.constants import CONST
-import functest.utils.functest_utils as ft_utils
-
from snaps.config.flavor import FlavorConfig
from snaps.config.network import NetworkConfig, SubnetConfig
from snaps.config.project import ProjectConfig
from snaps.config.user import UserConfig
-
from snaps.openstack import create_flavor
from snaps.openstack.create_flavor import OpenStackFlavor
from snaps.openstack.tests import openstack_tests
from snaps.openstack.utils import deploy_utils
+from xtesting.core import testcase
+import yaml
+from functest.opnfv_tests.openstack.snaps import snaps_utils
+from functest.opnfv_tests.openstack.tempest import conf_utils
+from functest.utils import config
+from functest.utils import env
+from functest.utils import functest_utils
LOGGER = logging.getLogger(__name__)
def generate_test_list(self, verifier_repo_dir):
"""Generate test list based on the test mode."""
LOGGER.debug("Generating test case list...")
- if self.mode == 'defcore':
- shutil.copyfile(
- conf_utils.TEMPEST_DEFCORE, conf_utils.TEMPEST_RAW_LIST)
- elif self.mode == 'custom':
+ 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)
else:
if self.mode == 'smoke':
- testr_mode = "smoke"
+ testr_mode = r"'tempest\.(api|scenario).*\[.*\bsmoke\b.*\]'"
elif self.mode == 'full':
- testr_mode = ""
+ testr_mode = r"'^tempest\.'"
else:
- testr_mode = 'tempest.api.' + self.mode
+ testr_mode = self.mode
cmd = ("cd {0};"
"testr list-tests {1} > {2};"
"cd -;".format(verifier_repo_dir,
testr_mode,
conf_utils.TEMPEST_RAW_LIST))
- ft_utils.execute_command(cmd)
+ functest_utils.execute_command(cmd)
def apply_tempest_blacklist(self):
"""Exclude blacklisted test cases."""
result_file = open(conf_utils.TEMPEST_LIST, 'w')
black_tests = []
try:
- installer_type = CONST.__getattribute__('INSTALLER_TYPE')
- deploy_scenario = CONST.__getattribute__('DEPLOY_SCENARIO')
+ installer_type = env.get('INSTALLER_TYPE')
+ deploy_scenario = env.get('DEPLOY_SCENARIO')
if bool(installer_type) * bool(deploy_scenario):
# if INSTALLER_TYPE and DEPLOY_SCENARIO are set we read the
# file
cmd.extend(self.option)
LOGGER.info("Starting Tempest test suite: '%s'.", cmd)
- header = ("Tempest environment:\n"
- " SUT: %s\n Scenario: %s\n Node: %s\n Date: %s\n" %
- (CONST.__getattribute__('INSTALLER_TYPE'),
- CONST.__getattribute__('DEPLOY_SCENARIO'),
- CONST.__getattribute__('NODE_NAME'),
- time.strftime("%a %b %d %H:%M:%S %Z %Y")))
-
f_stdout = open(
os.path.join(conf_utils.TEMPEST_RESULTS_DIR, "tempest.log"), 'w+')
f_stderr = open(
os.path.join(conf_utils.TEMPEST_RESULTS_DIR,
"tempest-error.log"), 'w+')
- f_env = open(os.path.join(conf_utils.TEMPEST_RESULTS_DIR,
- "environment.log"), 'w+')
- f_env.write(header)
proc = subprocess.Popen(
cmd,
f_stdout.close()
f_stderr.close()
- f_env.close()
- def parse_verifier_result(self):
- """Parse and save test results."""
if self.verification_id is None:
raise Exception('Verification UUID not found')
+ def parse_verifier_result(self):
+ """Parse and save test results."""
stat = self.get_verifier_result(self.verification_id)
try:
num_executed = stat['num_tests'] - stat['num_skipped']
LOGGER.info("Tempest %s success_rate is %s%%",
self.case_name, self.result)
- def run(self):
+ def generate_report(self):
+ """Generate verification report."""
+ html_file = os.path.join(conf_utils.TEMPEST_RESULTS_DIR,
+ "tempest-report.html")
+ cmd = ["rally", "verify", "report", "--type", "html", "--uuid",
+ self.verification_id, "--to", html_file]
+ subprocess.Popen(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
+
+ def run(self, **kwargs):
self.start_time = time.time()
try:
self.resources.os_creds)
conf_utils.configure_tempest(
self.deployment_dir,
+ network_name=resources.get("network_name"),
image_id=resources.get("image_id"),
flavor_id=resources.get("flavor_id"),
compute_cnt=compute_cnt)
self.apply_tempest_blacklist()
self.run_verifier_tests()
self.parse_verifier_result()
+ self.generate_report()
res = testcase.TestCase.EX_OK
except Exception as err: # pylint: disable=broad-except
LOGGER.error('Error with run: %s', err)
self.os_creds = kwargs.get('os_creds') or snaps_utils.get_credentials()
self.guid = '-' + str(uuid.uuid4())
self.creators = list()
-
- if hasattr(CONST, 'snaps_images_cirros'):
- self.cirros_image_config = CONST.__getattribute__(
- 'snaps_images_cirros')
- else:
- self.cirros_image_config = None
+ self.cirros_image_config = getattr(
+ config.CONF, 'snaps_images_cirros', None)
def _create_project(self):
"""Create project for tests."""
project_creator = deploy_utils.create_project(
self.os_creds, ProjectConfig(
- name=CONST.__getattribute__(
- 'tempest_identity_tenant_name') + self.guid,
- description=CONST.__getattribute__(
- 'tempest_identity_tenant_description')))
+ name=getattr(
+ config.CONF, 'tempest_identity_tenant_name') + self.guid,
+ description=getattr(
+ config.CONF, 'tempest_identity_tenant_description')))
if project_creator is None or project_creator.get_project() is None:
raise Exception("Failed to create tenant")
self.creators.append(project_creator)
"""Create user for tests."""
user_creator = deploy_utils.create_user(
self.os_creds, UserConfig(
- name=CONST.__getattribute__(
- 'tempest_identity_user_name') + self.guid,
- password=CONST.__getattribute__(
- 'tempest_identity_user_password'),
- project_name=CONST.__getattribute__(
- 'tempest_identity_tenant_name') + self.guid))
+ name=getattr(
+ config.CONF, 'tempest_identity_user_name') + self.guid,
+ password=getattr(
+ config.CONF, 'tempest_identity_user_password'),
+ project_name=getattr(
+ config.CONF, 'tempest_identity_tenant_name') + self.guid))
if user_creator is None or user_creator.get_user() is None:
raise Exception("Failed to create user")
self.creators.append(user_creator)
tempest_physical_network = None
tempest_segmentation_id = None
- if hasattr(CONST, 'tempest_network_type'):
- tempest_network_type = CONST.__getattribute__(
- 'tempest_network_type')
- if hasattr(CONST, 'tempest_physical_network'):
- tempest_physical_network = CONST.__getattribute__(
- 'tempest_physical_network')
- if hasattr(CONST, 'tempest_segmentation_id'):
- tempest_segmentation_id = CONST.__getattribute__(
- 'tempest_segmentation_id')
+ tempest_network_type = getattr(
+ config.CONF, 'tempest_network_type', None)
+ tempest_physical_network = getattr(
+ config.CONF, 'tempest_physical_network', None)
+ tempest_segmentation_id = getattr(
+ config.CONF, 'tempest_segmentation_id', None)
+ tempest_net_name = getattr(
+ config.CONF, 'tempest_private_net_name') + self.guid
network_creator = deploy_utils.create_network(
self.os_creds, NetworkConfig(
- name=CONST.__getattribute__(
- 'tempest_private_net_name') + self.guid,
+ name=tempest_net_name,
project_name=project_name,
network_type=tempest_network_type,
physical_network=tempest_physical_network,
segmentation_id=tempest_segmentation_id,
subnet_settings=[SubnetConfig(
- name=CONST.__getattribute__(
+ name=getattr(
+ config.CONF,
'tempest_private_subnet_name') + self.guid,
project_name=project_name,
- cidr=CONST.__getattribute__(
- 'tempest_private_subnet_cidr'))]))
+ cidr=getattr(
+ config.CONF, 'tempest_private_subnet_cidr'))]))
if network_creator is None or network_creator.get_network() is None:
raise Exception("Failed to create private network")
self.creators.append(network_creator)
+ return tempest_net_name
def _create_image(self, name):
"""Create image for tests"""
def _create_flavor(self, name):
"""Create flavor for tests."""
- scenario = CONST.__getattribute__('DEPLOY_SCENARIO')
+ scenario = env.get('DEPLOY_SCENARIO')
flavor_metadata = None
if 'ovs' in scenario or 'fdio' in scenario:
flavor_metadata = create_flavor.MEM_PAGE_SIZE_LARGE
flavor_creator = OpenStackFlavor(
self.os_creds, FlavorConfig(
name=name,
- ram=CONST.__getattribute__('openstack_flavor_ram'),
- disk=CONST.__getattribute__('openstack_flavor_disk'),
- vcpus=CONST.__getattribute__('openstack_flavor_vcpus'),
+ ram=getattr(config.CONF, 'openstack_flavor_ram'),
+ disk=getattr(config.CONF, 'openstack_flavor_disk'),
+ vcpus=getattr(config.CONF, 'openstack_flavor_vcpus'),
metadata=flavor_metadata))
flavor = flavor_creator.create()
if flavor is None:
create_project=False):
"""Create resources for Tempest test suite."""
result = {
+ 'tempest_net_name': None,
'image_id': None,
'image_id_alt': None,
'flavor_id': None,
if create_project:
LOGGER.debug("Creating project and user for Tempest suite")
- project_name = CONST.__getattribute__(
- 'tempest_identity_tenant_name') + self.guid
+ project_name = getattr(
+ config.CONF, 'tempest_identity_tenant_name') + self.guid
result['project_id'] = self._create_project()
result['user_id'] = self._create_user()
result['tenant_id'] = result['project_id'] # for compatibility
LOGGER.debug("Creating private network for Tempest suite")
- self._create_network(project_name)
+ result['tempest_net_name'] = self._create_network(project_name)
LOGGER.debug("Creating image for Tempest suite")
- image_name = CONST.__getattribute__('openstack_image_name') + self.guid
+ image_name = getattr(config.CONF, 'openstack_image_name') + self.guid
result['image_id'] = self._create_image(image_name)
if use_custom_images:
LOGGER.debug("Creating 2nd image for Tempest suite")
- image_name = CONST.__getattribute__(
- 'openstack_image_name_alt') + self.guid
+ image_name = getattr(
+ config.CONF, 'openstack_image_name_alt') + self.guid
result['image_id_alt'] = self._create_image(image_name)
- if (CONST.__getattribute__('tempest_use_custom_flavors') == 'True' or
+ if (getattr(config.CONF, 'tempest_use_custom_flavors') == 'True' or
use_custom_flavors):
LOGGER.info("Creating flavor for Tempest suite")
- name = CONST.__getattribute__('openstack_flavor_name') + self.guid
+ name = getattr(config.CONF, 'openstack_flavor_name') + self.guid
result['flavor_id'] = self._create_flavor(name)
if use_custom_flavors:
LOGGER.info("Creating 2nd flavor for Tempest suite")
- scenario = CONST.__getattribute__('DEPLOY_SCENARIO')
+ scenario = env.get('DEPLOY_SCENARIO')
if 'ovs' in scenario or 'fdio' in scenario:
- CONST.__setattr__('openstack_flavor_ram', 1024)
- name = CONST.__getattribute__(
- 'openstack_flavor_name_alt') + self.guid
+ setattr(config.CONF, 'openstack_flavor_ram', 1024)
+ name = getattr(
+ config.CONF, 'openstack_flavor_name_alt') + self.guid
result['flavor_id_alt'] = self._create_flavor(name)
return result