diff options
author | Morgan Richomme <morgan.richomme@orange.com> | 2017-05-24 17:00:49 +0200 |
---|---|---|
committer | Morgan Richomme <morgan.richomme@orange.com> | 2017-06-06 14:02:11 +0200 |
commit | 58667cba215c2cb999d6bcaf891980bda4325b42 (patch) | |
tree | 43daaa0fac17d5a8e283126c9fe7d68d523f62c5 /functest/utils | |
parent | d1fe9ae1d51537c73f3264cb1e01342888f5fd3f (diff) |
Refactor core VNF class
- Simplify processing
- Implement run method to inherit testcase methods
- Add unit tests
- Fix all pylint issues
It also obliges vnf and its uts to be rated 10/10 by pylint.
JIRA: FUNCTEST-830
Co-Authored-By: Cédric Ollivier <cedric.ollivier@orange.com>
Change-Id: I8dd24eea55089277c9e5b2b51fb14dc377f2fcaf
Signed-off-by: Morgan Richomme <morgan.richomme@orange.com>
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'functest/utils')
-rw-r--r-- | functest/utils/openstack_utils.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/functest/utils/openstack_utils.py b/functest/utils/openstack_utils.py index 57a2aa2b..f155449d 100644 --- a/functest/utils/openstack_utils.py +++ b/functest/utils/openstack_utils.py @@ -279,6 +279,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 # ********************************************* @@ -1412,6 +1428,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 +1486,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(): |