aboutsummaryrefslogtreecommitdiffstats
path: root/functest/utils
diff options
context:
space:
mode:
Diffstat (limited to 'functest/utils')
-rw-r--r--functest/utils/decorators.py7
-rw-r--r--functest/utils/env.py5
-rw-r--r--functest/utils/functest_utils.py38
-rwxr-xr-xfunctest/utils/openstack_clean.py33
-rwxr-xr-xfunctest/utils/openstack_snapshot.py23
-rw-r--r--functest/utils/openstack_utils.py117
6 files changed, 143 insertions, 80 deletions
diff --git a/functest/utils/decorators.py b/functest/utils/decorators.py
index 73e0a352..230a99e7 100644
--- a/functest/utils/decorators.py
+++ b/functest/utils/decorators.py
@@ -1,5 +1,12 @@
#!/usr/bin/env python
+# Copyright (c) 2017 Orange and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
# pylint: disable=missing-docstring
import errno
diff --git a/functest/utils/env.py b/functest/utils/env.py
index 3724ec99..0174588d 100644
--- a/functest/utils/env.py
+++ b/functest/utils/env.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python
+import pkg_resources
import os
import re
@@ -16,8 +17,8 @@ default_envs = {
'BUILD_TAG': None,
'OS_ENDPOINT_TYPE': None,
'OS_AUTH_URL': None,
- 'CONFIG_FUNCTEST_YAML': os.path.normpath(os.path.join(os.path.dirname(
- os.path.abspath(__file__)), '../ci/config_functest.yaml'))
+ 'CONFIG_FUNCTEST_YAML': pkg_resources.resource_filename(
+ 'functest', 'ci/config_functest.yaml')
}
diff --git a/functest/utils/functest_utils.py b/functest/utils/functest_utils.py
index dc20eea1..91781bd2 100644
--- a/functest/utils/functest_utils.py
+++ b/functest/utils/functest_utils.py
@@ -11,6 +11,7 @@ import functools
import json
import logging
import os
+import pkg_resources
import re
import shutil
import subprocess
@@ -22,10 +23,10 @@ import dns.resolver
import requests
from six.moves import urllib
import yaml
-from git import Repo
from functest.utils import constants
from functest.utils import decorators
+from functest.utils.constants import CONST
logger = logging.getLogger(__name__)
@@ -67,15 +68,6 @@ def download_url(url, dest_path):
# CI UTILS
#
# -----------------------------------------------------------
-def get_git_branch(repo_path):
- """
- Get git branch name
- """
- repo = Repo(repo_path)
- branch = repo.active_branch
- return branch.name
-
-
def get_installer_type():
"""
Get installer type (fuel, apex, joid, compass)
@@ -149,24 +141,15 @@ def get_build_tag():
return build_tag
-def get_db_url():
+def logger_test_results(project, case_name, status, details):
"""
- Returns DB URL
+ Format test case results for the logger
"""
- # TODO use CONST mechanism
- try:
- # if TEST_DB_URL declared in env variable, use it!
- db_url = os.environ['TEST_DB_URL']
- except KeyError:
- db_url = get_functest_config('results.test_db_url')
- return db_url
-
-
-def logger_test_results(project, case_name, status, details):
pod_name = get_pod_name()
scenario = get_scenario()
version = get_version()
build_tag = get_build_tag()
+ db_url = CONST.__getattribute__("results_test_db_url")
logger.info(
"\n"
@@ -182,7 +165,7 @@ def logger_test_results(project, case_name, status, details):
"details:\t%(d)s\n"
% {'p': project,
'n': case_name,
- 'db': get_db_url(),
+ 'db': db_url,
'pod': pod_name,
'v': version,
's': scenario,
@@ -198,7 +181,7 @@ def push_results_to_db(project, case_name,
POST results to the Result target DB
"""
# Retrieve params from CI and conf
- url = get_db_url()
+ url = CONST.__getattribute__("results_test_db_url")
try:
installer = os.environ['INSTALLER_TYPE']
@@ -334,7 +317,8 @@ def execute_command(cmd, info=False, error_msg="",
def get_dict_by_test(testname):
- with open(get_testcases_file_dir()) as f:
+ with open(pkg_resources.resource_filename(
+ 'functest', 'ci/testcases.yaml')) as f:
testcases_yaml = yaml.safe_load(f)
for dic_tier in testcases_yaml.get("tiers"):
@@ -394,10 +378,6 @@ def merge_dicts(dict1, dict2):
yield (k, dict2[k])
-def get_testcases_file_dir():
- return get_functest_config('general.functest.testcases_yaml')
-
-
def get_functest_yaml():
with open(constants.CONST.__getattribute__('CONFIG_FUNCTEST_YAML')) as f:
functest_yaml = yaml.safe_load(f)
diff --git a/functest/utils/openstack_clean.py b/functest/utils/openstack_clean.py
index cdd91852..e88245d6 100755
--- a/functest/utils/openstack_clean.py
+++ b/functest/utils/openstack_clean.py
@@ -80,22 +80,25 @@ def remove_instances(nova_client, default_instances):
break
-def remove_images(nova_client, default_images):
+def remove_images(glance_client, default_images):
logger.debug("Removing Glance images...")
- images = os_utils.get_images(nova_client)
- if images is None or len(images) == 0:
+ images = os_utils.get_images(glance_client)
+ if images is None:
+ return -1
+ images = {image.id: image.name for image in images}
+ if len(images) == 0:
logger.debug("No images found.")
return
for image in images:
- image_name = getattr(image, 'name')
- image_id = getattr(image, 'id')
+ image_id = image
+ image_name = images.get(image_id)
logger.debug("'%s', ID=%s " % (image_name, image_id))
if (image_id not in default_images and
image_name not in default_images.values()):
logger.debug("Removing image '%s', ID=%s ..."
% (image_name, image_id))
- if os_utils.delete_glance_image(nova_client, image_id):
+ if os_utils.delete_glance_image(glance_client, image_id):
logger.debug(" > Done!")
else:
logger.error("There has been a problem removing the"
@@ -135,9 +138,9 @@ def remove_volumes(cinder_client, default_volumes):
"NOT be deleted.")
-def remove_floatingips(nova_client, default_floatingips):
+def remove_floatingips(neutron_client, default_floatingips):
logger.debug("Removing floating IPs...")
- floatingips = os_utils.get_floating_ips(nova_client)
+ floatingips = os_utils.get_floating_ips(neutron_client)
if floatingips is None or len(floatingips) == 0:
logger.debug("No floating IPs found.")
return
@@ -145,13 +148,13 @@ def remove_floatingips(nova_client, default_floatingips):
init_len = len(floatingips)
deleted = 0
for fip in floatingips:
- fip_id = getattr(fip, 'id')
- fip_ip = getattr(fip, 'ip')
+ fip_id = fip['id']
+ fip_ip = fip['floating_ip_address']
logger.debug("'%s', ID=%s " % (fip_ip, fip_id))
if (fip_id not in default_floatingips and
fip_ip not in default_floatingips.values()):
logger.debug("Removing floating IP %s ..." % fip_id)
- if os_utils.delete_floating_ip(nova_client, fip_id):
+ if os_utils.delete_floating_ip(neutron_client, fip_id):
logger.debug(" > Done!")
deleted += 1
else:
@@ -163,7 +166,7 @@ def remove_floatingips(nova_client, default_floatingips):
timeout = 50
while timeout > 0:
- floatingips = os_utils.get_floating_ips(nova_client)
+ floatingips = os_utils.get_floating_ips(neutron_client)
if floatingips is None or len(floatingips) == (init_len - deleted):
break
else:
@@ -385,6 +388,7 @@ def main():
neutron_client = os_utils.get_neutron_client()
keystone_client = os_utils.get_keystone_client()
cinder_client = os_utils.get_cinder_client()
+ glance_client = os_utils.get_glance_client()
try:
with open(OS_SNAPSHOT_FILE) as f:
@@ -411,11 +415,11 @@ def main():
remove_instances(nova_client, default_instances)
separator()
- remove_images(nova_client, default_images)
+ remove_images(glance_client, default_images)
separator()
remove_volumes(cinder_client, default_volumes)
separator()
- remove_floatingips(nova_client, default_floatingips)
+ remove_floatingips(neutron_client, default_floatingips)
separator()
remove_networks(neutron_client, default_networks, default_routers)
separator()
@@ -425,6 +429,7 @@ def main():
separator()
remove_tenants(keystone_client, default_tenants)
separator()
+ return 0
if __name__ == '__main__':
diff --git a/functest/utils/openstack_snapshot.py b/functest/utils/openstack_snapshot.py
index 8f1d3b9b..f4ef751c 100755
--- a/functest/utils/openstack_snapshot.py
+++ b/functest/utils/openstack_snapshot.py
@@ -48,13 +48,13 @@ def get_instances(nova_client):
return {'instances': dic_instances}
-def get_images(nova_client):
+def get_images(glance_client):
logger.debug("Getting images...")
dic_images = {}
- images = os_utils.get_images(nova_client)
- if not (images is None or len(images) == 0):
- for image in images:
- dic_images.update({getattr(image, 'id'): getattr(image, 'name')})
+ images = os_utils.get_images(glance_client)
+ if images is None:
+ return -1
+ dic_images.update({image.id: image.name for image in images})
return {'images': dic_images}
@@ -98,13 +98,14 @@ def get_security_groups(neutron_client):
return {'secgroups': dic_secgroups}
-def get_floatinips(nova_client):
+def get_floatingips(neutron_client):
logger.debug("Getting Floating IPs...")
dic_floatingips = {}
- floatingips = os_utils.get_floating_ips(nova_client)
+ floatingips = os_utils.get_floating_ips(neutron_client)
if not (floatingips is None or len(floatingips) == 0):
for floatingip in floatingips:
- dic_floatingips.update({floatingip.id: floatingip.ip})
+ dic_floatingips.update({floatingip['id']:
+ floatingip['floating_ip_address']})
return {'floatingips': dic_floatingips}
@@ -136,6 +137,7 @@ def main():
neutron_client = os_utils.get_neutron_client()
keystone_client = os_utils.get_keystone_client()
cinder_client = os_utils.get_cinder_client()
+ glance_client = os_utils.get_glance_client()
if not os_utils.check_credentials():
logger.error("Please source the openrc credentials and run the" +
@@ -144,12 +146,12 @@ def main():
snapshot = {}
snapshot.update(get_instances(nova_client))
- snapshot.update(get_images(nova_client))
+ snapshot.update(get_images(glance_client))
snapshot.update(get_volumes(cinder_client))
snapshot.update(get_networks(neutron_client))
snapshot.update(get_routers(neutron_client))
snapshot.update(get_security_groups(neutron_client))
- snapshot.update(get_floatinips(nova_client))
+ snapshot.update(get_floatingips(neutron_client))
snapshot.update(get_users(keystone_client))
snapshot.update(get_tenants(keystone_client))
@@ -160,6 +162,7 @@ def main():
% yaml_file.read())
logger.debug("NOTE: These objects will NOT be deleted after " +
"running the test.")
+ return 0
if __name__ == '__main__':
diff --git a/functest/utils/openstack_utils.py b/functest/utils/openstack_utils.py
index 57a2aa2b..e7cdfc86 100644
--- a/functest/utils/openstack_utils.py
+++ b/functest/utils/openstack_utils.py
@@ -82,7 +82,8 @@ def get_env_cred_dict():
'OS_PROJECT_NAME': 'project_name',
'OS_ENDPOINT_TYPE': 'endpoint_type',
'OS_REGION_NAME': 'region_name',
- 'OS_CACERT': 'https_cacert'
+ 'OS_CACERT': 'https_cacert',
+ 'OS_INSECURE': 'https_insecure'
}
return env_cred_dict
@@ -150,10 +151,12 @@ def get_credentials_for_rally():
cred_key = env_cred_dict.get('OS_REGION_NAME')
rally_conf[cred_key] = region_name
- cacert = os.getenv('OS_CACERT')
- if cacert is not None:
- cred_key = env_cred_dict.get('OS_CACERT')
- rally_conf[cred_key] = cacert
+ cred_key = env_cred_dict.get('OS_CACERT')
+ rally_conf[cred_key] = os.getenv('OS_CACERT', '')
+
+ insecure_key = env_cred_dict.get('OS_INSECURE')
+ rally_conf[insecure_key] = os.getenv('OS_INSECURE', '').lower() == 'true'
+
return rally_conf
@@ -181,14 +184,10 @@ def get_endpoint(service_type, endpoint_type='publicURL'):
def get_session(other_creds={}):
auth = get_session_auth(other_creds)
- cacert = os.getenv('OS_CACERT')
- if cacert is not None:
- if not os.path.isfile(cacert):
- raise Exception("The 'OS_CACERT' environment"
- "variable is set to %s but the file"
- "does not exist.", cacert)
-
- return session.Session(auth=auth, verify=cacert)
+ https_cacert = os.getenv('OS_CACERT', '')
+ https_insecure = os.getenv('OS_INSECURE', '').lower() == 'true'
+ return session.Session(auth=auth,
+ verify=(https_cacert or not https_insecure))
# *********************************************
@@ -279,6 +278,22 @@ def get_heat_client(other_creds={}):
return heatclient.Client(get_heat_client_version(), session=sess)
+def download_and_add_image_on_glance(glance, image_name, image_url, data_dir):
+ dest_path = data_dir
+ if not os.path.exists(dest_path):
+ os.makedirs(dest_path)
+ file_name = image_url.rsplit('/')[-1]
+ if not ft_utils.download_url(image_url, dest_path):
+ return False
+
+ image = create_glance_image(
+ glance, image_name, dest_path + file_name)
+ if not image:
+ return False
+
+ return image
+
+
# *********************************************
# NOVA
# *********************************************
@@ -410,12 +425,12 @@ def get_or_create_flavor(flavor_name, ram, disk, vcpus, public=True):
return flavor_exists, flavor_id
-def get_floating_ips(nova_client):
+def get_floating_ips(neutron_client):
try:
- floating_ips = nova_client.floating_ips.list()
- return floating_ips
+ floating_ips = neutron_client.list_floatingips()
+ return floating_ips['floatingips']
except Exception as e:
- logger.error("Error [get_floating_ips(nova_client)]: %s" % e)
+ logger.error("Error [get_floating_ips(neutron_client)]: %s" % e)
return None
@@ -578,12 +593,12 @@ def delete_instance(nova_client, instance_id):
return False
-def delete_floating_ip(nova_client, floatingip_id):
+def delete_floating_ip(neutron_client, floatingip_id):
try:
- nova_client.floating_ips.delete(floatingip_id)
+ neutron_client.delete_floatingip(floatingip_id)
return True
except Exception as e:
- logger.error("Error [delete_floating_ip(nova_client, '%s')]: %s"
+ logger.error("Error [delete_floating_ip(neutron_client, '%s')]: %s"
% (floatingip_id, e))
return False
@@ -1176,9 +1191,9 @@ def delete_security_group(neutron_client, secgroup_id):
# *********************************************
# GLANCE
# *********************************************
-def get_images(nova_client):
+def get_images(glance_client):
try:
- images = nova_client.images.list()
+ images = glance_client.images.list()
return images
except Exception as e:
logger.error("Error [get_images]: %s" % e)
@@ -1242,12 +1257,12 @@ def get_or_create_image(name, path, format):
return image_exists, image_id
-def delete_glance_image(nova_client, image_id):
+def delete_glance_image(glance_client, image_id):
try:
- nova_client.images.delete(image_id)
+ glance_client.images.delete(image_id)
return True
except Exception as e:
- logger.error("Error [delete_glance_image(nova_client, '%s')]: %s"
+ logger.error("Error [delete_glance_image(glance_client, '%s')]: %s"
% (image_id, e))
return False
@@ -1412,6 +1427,32 @@ def get_or_create_tenant(keystone_client, tenant_name, tenant_description):
return tenant_id
+def get_or_create_tenant_for_vnf(keystone_client, tenant_name,
+ tenant_description):
+ """Get or Create a Tenant
+
+ Args:
+ keystone_client: keystone client reference
+ tenant_name: the name of the tenant
+ tenant_description: the description of the tenant
+
+ return False if tenant retrieved though get
+ return True if tenant created
+ raise Exception if error during processing
+ """
+ try:
+ tenant_id = get_tenant_id(keystone_client, tenant_name)
+ if not tenant_id:
+ tenant_id = create_tenant(keystone_client, tenant_name,
+ tenant_description)
+ return True
+ else:
+ return False
+ except:
+ raise Exception("Impossible to create a Tenant for the VNF {}".format(
+ tenant_name))
+
+
def create_user(keystone_client, user_name, user_password,
user_email, tenant_id):
try:
@@ -1444,6 +1485,32 @@ def get_or_create_user(keystone_client, user_name, user_password,
return user_id
+def get_or_create_user_for_vnf(keystone_client, vnf_ref):
+ """Get or Create user for VNF
+
+ Args:
+ keystone_client: keystone client reference
+ vnf_ref: VNF reference used as user name & password, tenant name
+
+ return False if user retrieved through get
+ return True if user created
+ raise Exception if error during processing
+ """
+ try:
+ user_id = get_user_id(keystone_client, vnf_ref)
+ tenant_id = get_tenant_id(keystone_client, vnf_ref)
+ if not user_id:
+ user_id = create_user(keystone_client, vnf_ref, vnf_ref,
+ "", tenant_id)
+ return True
+ else:
+ return False
+ add_role_user(keystone_client, user_id, 'admin', vnf_ref)
+ except:
+ raise Exception("Impossible to create a user for the VNF {}".format(
+ vnf_ref))
+
+
def add_role_user(keystone_client, user_id, role_id, tenant_id):
try:
if is_keystone_v3():