From 58667cba215c2cb999d6bcaf891980bda4325b42 Mon Sep 17 00:00:00 2001 From: Morgan Richomme Date: Wed, 24 May 2017 17:00:49 +0200 Subject: Refactor core VNF class MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 Change-Id: I8dd24eea55089277c9e5b2b51fb14dc377f2fcaf Signed-off-by: Morgan Richomme Signed-off-by: Cédric Ollivier --- functest/utils/openstack_utils.py | 68 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'functest/utils') 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(): -- cgit 1.2.3-korg