diff options
Diffstat (limited to 'functest/utils/openstack_utils.py')
-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(): |