aboutsummaryrefslogtreecommitdiffstats
path: root/functest/utils
diff options
context:
space:
mode:
Diffstat (limited to 'functest/utils')
-rw-r--r--functest/utils/env.py5
-rw-r--r--functest/utils/functest_utils.py18
-rw-r--r--functest/utils/openstack_utils.py68
3 files changed, 74 insertions, 17 deletions
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 995d94ff..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,7 +23,6 @@ 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
@@ -68,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)
@@ -326,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"):
@@ -386,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_utils.py b/functest/utils/openstack_utils.py
index cc62f29c..a8966264 100644
--- a/functest/utils/openstack_utils.py
+++ b/functest/utils/openstack_utils.py
@@ -275,6 +275,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
# *********************************************
@@ -1408,6 +1424,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:
@@ -1440,6 +1482,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():