diff options
Diffstat (limited to 'utils')
-rw-r--r-- | utils/functest_utils.py | 52 | ||||
-rwxr-xr-x | utils/openstack_clean.py | 6 | ||||
-rwxr-xr-x | utils/openstack_snapshot.py | 4 | ||||
-rwxr-xr-x | utils/openstack_utils.py | 17 |
4 files changed, 47 insertions, 32 deletions
diff --git a/utils/functest_utils.py b/utils/functest_utils.py index 644ad1a1b..717e4b2ce 100644 --- a/utils/functest_utils.py +++ b/utils/functest_utils.py @@ -7,23 +7,21 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 # -from datetime import datetime as dt import json import os import re -import requests import shutil import subprocess import sys import urllib2 - -import functest.ci.tier_builder as tb -import functest.utils.functest_logger as ft_logger +from datetime import datetime as dt import dns.resolver -from git import Repo +import requests import yaml +from git import Repo +import functest.utils.functest_logger as ft_logger logger = ft_logger.Logger("functest_utils").getLogger() @@ -152,9 +150,7 @@ def get_db_url(): """ Returns DB URL """ - functest_yaml = get_functest_yaml() - db_url = functest_yaml.get("results").get("test_db_url") - return db_url + return get_functest_config('results.test_db_url') def logger_test_results(project, case_name, status, details): @@ -331,10 +327,8 @@ def get_deployment_dir(): """ Returns current Rally deployment directory """ - functest_yaml = get_functest_yaml() - deployment_name = functest_yaml.get("rally").get("deployment_name") - rally_dir = functest_yaml.get("general").get("directories").get( - "dir_rally_inst") + deployment_name = get_functest_config('rally.deployment_name') + rally_dir = get_functest_config('general.directories.dir_rally_inst') cmd = ("rally deployment list | awk '/" + deployment_name + "/ {print $2}'") p = subprocess.Popen(cmd, shell=True, @@ -350,15 +344,16 @@ def get_deployment_dir(): def get_criteria_by_test(testname): - criteria = "" - file = get_testcases_file() - tiers = tb.TierBuilder("", "", file) - for tier in tiers.get_tiers(): - for test in tier.get_tests(): - if test.get_name() == testname: - criteria = test.get_criteria() + with open(get_testcases_file()) as f: + testcases_yaml = yaml.safe_load(f) + + for dic_tier in testcases_yaml.get("tiers"): + for dic_testcase in dic_tier['testcases']: + if dic_testcase['name'] == testname: + return dic_testcase['criteria'] - return criteria + logger.error('Project %s is not defined in testcases.yaml' % testname) + return None # ---------------------------------------------------------- @@ -366,18 +361,16 @@ def get_criteria_by_test(testname): # YAML UTILS # # ----------------------------------------------------------- -def get_parameter_from_yaml(parameter, file=None): +def get_parameter_from_yaml(parameter, file): """ - Returns the value of a given parameter in config_functest.yaml + Returns the value of a given parameter in file.yaml parameter must be given in string format with dots Example: general.openstack.image_name """ - if file is None: - file = os.environ["CONFIG_FUNCTEST_YAML"] with open(file) as f: - functest_yaml = yaml.safe_load(f) + file_yaml = yaml.safe_load(f) f.close() - value = functest_yaml + value = file_yaml for element in parameter.split("."): value = value.get(element) if value is None: @@ -386,6 +379,11 @@ def get_parameter_from_yaml(parameter, file=None): return value +def get_functest_config(parameter): + yaml_ = os.environ["CONFIG_FUNCTEST_YAML"] + return get_parameter_from_yaml(parameter, yaml_) + + def check_success_rate(case_name, success_rate): success_rate = float(success_rate) criteria = get_criteria_by_test(case_name) diff --git a/utils/openstack_clean.py b/utils/openstack_clean.py index 3b937c917..bf582dea2 100755 --- a/utils/openstack_clean.py +++ b/utils/openstack_clean.py @@ -29,8 +29,8 @@ import yaml logger = ft_logger.Logger("openstack_clean").getLogger() -OS_SNAPSHOT_FILE = ft_utils.get_parameter_from_yaml( - "general.openstack.snapshot_file") +OS_SNAPSHOT_FILE = \ + ft_utils.get_functest_config("general.openstack.snapshot_file") def separator(): @@ -233,7 +233,7 @@ def remove_ports(neutron_client, ports, network_ids): except: logger.debug(" > WARNING: Port %s does not contain fixed_ips" % port_id) - print port + logger.info(port) router_id = port['device_id'] if len(port['fixed_ips']) == 0 and router_id == '': logger.debug("Removing port %s ..." % port_id) diff --git a/utils/openstack_snapshot.py b/utils/openstack_snapshot.py index 236cf74e5..560cadbdb 100755 --- a/utils/openstack_snapshot.py +++ b/utils/openstack_snapshot.py @@ -29,8 +29,8 @@ import yaml logger = ft_logger.Logger("openstack_snapshot").getLogger() -OS_SNAPSHOT_FILE = ft_utils.get_parameter_from_yaml( - "general.openstack.snapshot_file") +OS_SNAPSHOT_FILE = \ + ft_utils.get_functest_config("general.openstack.snapshot_file") def separator(): diff --git a/utils/openstack_utils.py b/utils/openstack_utils.py index ff9b54a58..8c2e00cb1 100755 --- a/utils/openstack_utils.py +++ b/utils/openstack_utils.py @@ -16,6 +16,7 @@ import time from cinderclient import client as cinderclient import functest.utils.functest_logger as ft_logger +import functest.utils.functest_utils as ft_utils from glanceclient import client as glanceclient from keystoneclient.v2_0 import client as keystoneclient from neutronclient.v2_0 import client as neutronclient @@ -235,6 +236,14 @@ def get_hypervisors(nova_client): def create_flavor(nova_client, flavor_name, ram, disk, vcpus): try: flavor = nova_client.flavors.create(flavor_name, ram, vcpus, disk) + try: + extra_specs = ft_utils.get_functest_config( + 'general.flavor_extra_specs') + flavor.update(extra_specs) + except ValueError: + # flavor extra specs are not configured, therefore skip the update + pass + except Exception, e: logger.error("Error [create_flavor(nova_client, '%s', '%s', '%s', " "'%s')]: %s" % (flavor_name, ram, disk, vcpus, e)) @@ -902,11 +911,19 @@ def create_glance_image(glance_client, image_name, file_path, disk="qcow2", if logger: logger.info("Creating image '%s' from '%s'..." % (image_name, file_path)) + try: + properties = ft_utils.get_functest_config( + 'general.image_properties') + except ValueError: + # image properties are not configured + # therefore don't add any properties + properties = {} with open(file_path) as fimage: image = glance_client.images.create(name=image_name, is_public=public, disk_format=disk, container_format=container, + properties=properties, data=fimage) image_id = image.id return image_id |