summaryrefslogtreecommitdiffstats
path: root/testcases/functest_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'testcases/functest_utils.py')
-rw-r--r--testcases/functest_utils.py93
1 files changed, 71 insertions, 22 deletions
diff --git a/testcases/functest_utils.py b/testcases/functest_utils.py
index 6af55f7a7..6d60fbce3 100644
--- a/testcases/functest_utils.py
+++ b/testcases/functest_utils.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python
#
# jose.lausuch@ericsson.com
+# valentin.boucher@orange.com
# 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
@@ -9,7 +10,7 @@
import re, json, os, urllib2, shutil, subprocess, sys
-
+############# CREDENTIALS OPENSTACK #############
def check_credentials():
"""
Check if the OpenStack credentials (openrc) are sourced
@@ -66,7 +67,7 @@ def get_credentials(service):
return creds
-
+################# NOVA #################
def get_instance_status(nova_client,instance):
try:
instance = nova_client.servers.get(instance.id)
@@ -83,7 +84,27 @@ def get_instance_by_name(nova_client, instance_name):
return None
+def get_flavor_id(nova_client, flavor_name):
+ flavors = nova_client.flavors.list(detailed=True)
+ id = ''
+ for f in flavors:
+ if f.name == flavor_name:
+ id = f.id
+ break
+ return id
+
+
+def get_flavor_id_by_ram_range(nova_client, min_ram, max_ram):
+ flavors = nova_client.flavors.list(detailed=True)
+ id = ''
+ for f in flavors:
+ if min_ram <= f.ram and f.ram <= max_ram:
+ id = f.id
+ break
+ return id
+
+################# NEUTRON #################
def create_neutron_net(neutron_client, name):
json_body = {'network': {'name': name,
'admin_state_up': True}}
@@ -190,6 +211,34 @@ def check_neutron_net(neutron_client, net_name):
return True
return False
+def get_network_list(neutron_client):
+ network_list = neutron_client.list_networks()['networks']
+ if len(network_list) == 0 :
+ return None
+ else :
+ return network_list
+
+def get_external_net(neutron_client):
+ for network in neutron_client.list_networks()['networks']:
+ if network['router:external']:
+ return network['name']
+ return False
+
+def update_sg_quota(neutron_client, tenant_id, sg_quota, sg_rule_quota):
+ json_body = {"quota": {
+ "security_group": sg_quota,
+ "security_group_rule": sg_rule_quota
+ }}
+
+ try:
+ quota = neutron_client.update_quota(tenant_id=tenant_id, body=json_body)
+ return True
+ except:
+ print "Error:", sys.exc_info()[0]
+ return False
+
+################# GLANCE #################
+
def get_image_id(glance_client, image_name):
images = glance_client.images.list()
id = ''
@@ -199,34 +248,17 @@ def get_image_id(glance_client, image_name):
break
return id
-def create_glance_image(glance_client, image_name, file_path):
+def create_glance_image(glance_client, image_name, file_path, is_public=True):
try:
with open(file_path) as fimage:
- image = glance_client.images.create(name=image_name, is_public=True, disk_format="qcow2",
+ image = glance_client.images.create(name=image_name, is_public=is_public, disk_format="qcow2",
container_format="bare", data=fimage)
return image.id
except:
return False
-def get_flavor_id(nova_client, flavor_name):
- flavors = nova_client.flavors.list(detailed=True)
- id = ''
- for f in flavors:
- if f.name == flavor_name:
- id = f.id
- break
- return id
-
-def get_flavor_id_by_ram_range(nova_client, min_ram, max_ram):
- flavors = nova_client.flavors.list(detailed=True)
- id = ''
- for f in flavors:
- if min_ram <= f.ram and f.ram <= max_ram:
- id = f.id
- break
- return id
-
+################# KEYSTONE #################
def get_tenant_id(keystone_client, tenant_name):
tenants = keystone_client.tenants.list()
id = ''
@@ -270,6 +302,22 @@ def delete_tenant(keystone_client, tenant_id):
print "Error:", sys.exc_info()[0]
return False
+def create_user(keystone_client, user_name, user_password, user_email, tenant_id):
+ try:
+ user = keystone_client.users.create(user_name, user_password, user_email, tenant_id, enabled=True)
+ return user.id
+ except:
+ print "Error:", sys.exc_info()[0]
+ return False
+
+def delete_user(keystone_client, user_id):
+ try:
+ tenant = keystone_client.users.delete(user_id)
+ return True
+ except:
+ print "Error:", sys.exc_info()[0]
+ return False
+
def add_role_user(keystone_client, user_id, role_id, tenant_id):
try:
keystone_client.roles.add_user_role(user_id, role_id, tenant_id)
@@ -279,6 +327,7 @@ def add_role_user(keystone_client, user_id, role_id, tenant_id):
return False
+################# UTILS #################
def check_internet_connectivity(url='http://www.opnfv.org/'):
"""
Check if there is access to the internet