aboutsummaryrefslogtreecommitdiffstats
path: root/testcases/vPing/CI/libraries/vPing_ssh.py
diff options
context:
space:
mode:
authorjose.lausuch <jose.lausuch@ericsson.com>2016-04-07 14:36:43 +0200
committerJose Lausuch <jose.lausuch@ericsson.com>2016-04-11 10:02:45 +0000
commit4b1a0c48c915c0af207587489ec3e556a326be23 (patch)
treef4b5e339619b9230cf64d7778b494040c792f77e /testcases/vPing/CI/libraries/vPing_ssh.py
parenta71001dc2874725b494be6a0c18a586c5d0bfbe2 (diff)
Split functest_utils.py into 2 scripts
JIRA: FUNCTEST-186 All the openstack related functions are in openstack_utils.py and the remaining functions in functest_utils.py All the scripts are adapted to this structure. Change-Id: I7f3805779741f0b085985d0d053feb429250b1ea Signed-off-by: jose.lausuch <jose.lausuch@ericsson.com>
Diffstat (limited to 'testcases/vPing/CI/libraries/vPing_ssh.py')
-rw-r--r--testcases/vPing/CI/libraries/vPing_ssh.py75
1 files changed, 38 insertions, 37 deletions
diff --git a/testcases/vPing/CI/libraries/vPing_ssh.py b/testcases/vPing/CI/libraries/vPing_ssh.py
index b45d23be8..7adf8a23d 100644
--- a/testcases/vPing/CI/libraries/vPing_ssh.py
+++ b/testcases/vPing/CI/libraries/vPing_ssh.py
@@ -69,6 +69,7 @@ if not os.path.exists(REPO_PATH):
exit(-1)
sys.path.append(REPO_PATH + "testcases/")
import functest_utils
+import openstack_utils
with open("/home/opnfv/functest/conf/config_functest.yaml") as f:
functest_yaml = yaml.safe_load(f)
@@ -122,7 +123,7 @@ def waitVmActive(nova, vm):
sleep_time = 3
count = VM_BOOT_TIMEOUT / sleep_time
while True:
- status = functest_utils.get_instance_status(nova, vm)
+ status = openstack_utils.get_instance_status(nova, vm)
logger.debug("Status: %s" % status)
if status == "ACTIVE":
return True
@@ -142,7 +143,7 @@ def waitVmDeleted(nova, vm):
sleep_time = 3
count = VM_DELETE_TIMEOUT / sleep_time
while True:
- status = functest_utils.get_instance_status(nova, vm)
+ status = openstack_utils.get_instance_status(nova, vm)
if not status:
return True
elif count == 0:
@@ -158,23 +159,23 @@ def waitVmDeleted(nova, vm):
def create_private_neutron_net(neutron):
# Check if the network already exists
- network_id = functest_utils.get_network_id(neutron, NEUTRON_PRIVATE_NET_NAME)
- subnet_id = functest_utils.get_subnet_id(neutron, NEUTRON_PRIVATE_SUBNET_NAME)
- router_id = functest_utils.get_router_id(neutron, NEUTRON_ROUTER_NAME)
+ network_id = openstack_utils.get_network_id(neutron, NEUTRON_PRIVATE_NET_NAME)
+ subnet_id = openstack_utils.get_subnet_id(neutron, NEUTRON_PRIVATE_SUBNET_NAME)
+ router_id = openstack_utils.get_router_id(neutron, NEUTRON_ROUTER_NAME)
if network_id != '' and subnet_id != '' and router_id != '':
logger.info("Using existing network '%s'..." % NEUTRON_PRIVATE_NET_NAME)
else:
neutron.format = 'json'
logger.info('Creating neutron network %s...' % NEUTRON_PRIVATE_NET_NAME)
- network_id = functest_utils. \
+ network_id = openstack_utils. \
create_neutron_net(neutron, NEUTRON_PRIVATE_NET_NAME)
if not network_id:
return False
logger.debug("Network '%s' created successfully" % network_id)
logger.debug('Creating Subnet....')
- subnet_id = functest_utils. \
+ subnet_id = openstack_utils. \
create_neutron_subnet(neutron,
NEUTRON_PRIVATE_SUBNET_NAME,
NEUTRON_PRIVATE_SUBNET_CIDR,
@@ -183,7 +184,7 @@ def create_private_neutron_net(neutron):
return False
logger.debug("Subnet '%s' created successfully" % subnet_id)
logger.debug('Creating Router...')
- router_id = functest_utils. \
+ router_id = openstack_utils. \
create_neutron_router(neutron, NEUTRON_ROUTER_NAME)
if not router_id:
@@ -192,12 +193,12 @@ def create_private_neutron_net(neutron):
logger.debug("Router '%s' created successfully" % router_id)
logger.debug('Adding router to subnet...')
- if not functest_utils.add_interface_router(neutron, router_id, subnet_id):
+ if not openstack_utils.add_interface_router(neutron, router_id, subnet_id):
return False
logger.debug("Interface added successfully.")
logger.debug('Adding gateway to router...')
- if not functest_utils.add_gateway_router(neutron, router_id):
+ if not openstack_utils.add_gateway_router(neutron, router_id):
return False
logger.debug("Gateway added successfully.")
@@ -208,12 +209,12 @@ def create_private_neutron_net(neutron):
def create_security_group(neutron_client):
- sg_id = functest_utils.get_security_group_id(neutron_client, SECGROUP_NAME)
+ sg_id = openstack_utils.get_security_group_id(neutron_client, SECGROUP_NAME)
if sg_id != '':
logger.info("Using existing security group '%s'..." % SECGROUP_NAME)
else:
logger.info("Creating security group '%s'..." % SECGROUP_NAME)
- SECGROUP = functest_utils.create_security_group(neutron_client,
+ SECGROUP = openstack_utils.create_security_group(neutron_client,
SECGROUP_NAME,
SECGROUP_DESCR)
if not SECGROUP:
@@ -226,18 +227,18 @@ def create_security_group(neutron_client):
(SECGROUP['name'], sg_id))
logger.debug("Adding ICMP rules in security group '%s'..." % SECGROUP_NAME)
- if not functest_utils.create_secgroup_rule(neutron_client, sg_id, \
+ if not openstack_utils.create_secgroup_rule(neutron_client, sg_id, \
'ingress', 'icmp'):
logger.error("Failed to create the security group rule...")
return False
logger.debug("Adding SSH rules in security group '%s'..." % SECGROUP_NAME)
- if not functest_utils.create_secgroup_rule(neutron_client, sg_id, \
+ if not openstack_utils.create_secgroup_rule(neutron_client, sg_id, \
'ingress', 'tcp', '22', '22'):
logger.error("Failed to create the security group rule...")
return False
- if not functest_utils.create_secgroup_rule(neutron_client, sg_id, \
+ if not openstack_utils.create_secgroup_rule(neutron_client, sg_id, \
'egress', 'tcp', '22', '22'):
logger.error("Failed to create the security group rule...")
return False
@@ -253,10 +254,10 @@ def cleanup(nova, neutron, image_id, network_dic, sg_id, floatingip):
logger.info("Cleaning up...")
if not image_exists:
logger.debug("Deleting image...")
- if not functest_utils.delete_glance_image(nova, image_id):
+ if not openstack_utils.delete_glance_image(nova, image_id):
logger.error("Error deleting the glance image")
- vm1 = functest_utils.get_instance_by_name(nova, NAME_VM_1)
+ vm1 = openstack_utils.get_instance_by_name(nova, NAME_VM_1)
if vm1:
logger.debug("Deleting '%s'..." % NAME_VM_1)
nova.servers.delete(vm1)
@@ -264,11 +265,11 @@ def cleanup(nova, neutron, image_id, network_dic, sg_id, floatingip):
if not waitVmDeleted(nova, vm1):
logger.error(
"Instance '%s' with cannot be deleted. Status is '%s'" % (
- NAME_VM_1, functest_utils.get_instance_status(nova, vm1)))
+ NAME_VM_1, openstack_utils.get_instance_status(nova, vm1)))
else:
logger.debug("Instance %s terminated." % NAME_VM_1)
- vm2 = functest_utils.get_instance_by_name(nova, NAME_VM_2)
+ vm2 = openstack_utils.get_instance_by_name(nova, NAME_VM_2)
if vm2:
logger.debug("Deleting '%s'..." % NAME_VM_2)
@@ -278,7 +279,7 @@ def cleanup(nova, neutron, image_id, network_dic, sg_id, floatingip):
if not waitVmDeleted(nova, vm2):
logger.error(
"Instance '%s' with cannot be deleted. Status is '%s'" % (
- NAME_VM_2, functest_utils.get_instance_status(nova, vm2)))
+ NAME_VM_2, openstack_utils.get_instance_status(nova, vm2)))
else:
logger.debug("Instance %s terminated." % NAME_VM_2)
@@ -288,41 +289,41 @@ def cleanup(nova, neutron, image_id, network_dic, sg_id, floatingip):
subnet_id = network_dic["subnet_id"]
router_id = network_dic["router_id"]
- if not functest_utils.remove_interface_router(neutron, router_id,
+ if not openstack_utils.remove_interface_router(neutron, router_id,
subnet_id):
logger.error("Unable to remove subnet '%s' from router '%s'" % (
subnet_id, router_id))
return False
logger.debug("Interface removed successfully")
- if not functest_utils.delete_neutron_router(neutron, router_id):
+ if not openstack_utils.delete_neutron_router(neutron, router_id):
logger.error("Unable to delete router '%s'" % router_id)
return False
logger.debug("Router deleted successfully")
- if not functest_utils.delete_neutron_subnet(neutron, subnet_id):
+ if not openstack_utils.delete_neutron_subnet(neutron, subnet_id):
logger.error("Unable to delete subnet '%s'" % subnet_id)
return False
logger.debug(
"Subnet '%s' deleted successfully" % NEUTRON_PRIVATE_SUBNET_NAME)
- if not functest_utils.delete_neutron_net(neutron, net_id):
+ if not openstack_utils.delete_neutron_net(neutron, net_id):
logger.error("Unable to delete network '%s'" % net_id)
return False
logger.debug(
"Network '%s' deleted successfully" % NEUTRON_PRIVATE_NET_NAME)
- if not functest_utils.delete_security_group(neutron, sg_id):
+ if not openstack_utils.delete_security_group(neutron, sg_id):
logger.error("Unable to delete security group '%s'" % sg_id)
return False
logger.debug(
"Security group '%s' deleted successfully" % sg_id)
logger.debug("Releasing floating ip '%s'..." % floatingip['fip_addr'])
- if not functest_utils.delete_floating_ip(nova, floatingip['fip_id']):
+ if not openstack_utils.delete_floating_ip(nova, floatingip['fip_id']):
logger.error("Unable to delete floatingip '%s'" % floatingip['fip_addr'])
return False
logger.debug(
@@ -354,11 +355,11 @@ def push_results(start_time_ts, duration, test_status):
def main():
- creds_nova = functest_utils.get_credentials("nova")
+ creds_nova = openstack_utils.get_credentials("nova")
nova_client = novaclient.Client('2', **creds_nova)
- creds_neutron = functest_utils.get_credentials("neutron")
+ creds_neutron = openstack_utils.get_credentials("neutron")
neutron_client = neutronclient.Client(**creds_neutron)
- creds_keystone = functest_utils.get_credentials("keystone")
+ creds_keystone = openstack_utils.get_credentials("keystone")
keystone_client = keystoneclient.Client(**creds_keystone)
glance_endpoint = keystone_client.service_catalog.url_for(service_type='image',
endpoint_type='publicURL')
@@ -370,7 +371,7 @@ def main():
flavor = None
# Check if the given image exists
- image_id = functest_utils.get_image_id(glance_client, GLANCE_IMAGE_NAME)
+ image_id = openstack_utils.get_image_id(glance_client, GLANCE_IMAGE_NAME)
if image_id != '':
logger.info("Using existing image '%s'..." % GLANCE_IMAGE_NAME)
global image_exists
@@ -378,7 +379,7 @@ def main():
else:
logger.info("Creating image '%s' from '%s'..." % (GLANCE_IMAGE_NAME,
GLANCE_IMAGE_PATH))
- image_id = functest_utils.create_glance_image(glance_client,
+ image_id = openstack_utils.create_glance_image(glance_client,
GLANCE_IMAGE_NAME,
GLANCE_IMAGE_PATH)
if not image_id:
@@ -435,7 +436,7 @@ def main():
# wait until VM status is active
if not waitVmActive(nova_client, vm1):
logger.error("Instance '%s' cannot be booted. Status is '%s'" % (
- NAME_VM_1, functest_utils.get_instance_status(nova_client, vm1)))
+ NAME_VM_1, openstack_utils.get_instance_status(nova_client, vm1)))
cleanup(nova_client, neutron_client, image_id, network_dic, sg_id, floatingip)
return (EXIT_CODE)
else:
@@ -446,7 +447,7 @@ def main():
logger.debug("Instance '%s' got private ip '%s'." % (NAME_VM_1, test_ip))
logger.info("Adding '%s' to security group '%s'..." % (NAME_VM_1, SECGROUP_NAME))
- functest_utils.add_secgroup_to_instance(nova_client, vm1.id, sg_id)
+ openstack_utils.add_secgroup_to_instance(nova_client, vm1.id, sg_id)
# boot VM 2
logger.info("Creating instance '%s'..." % NAME_VM_2)
@@ -462,17 +463,17 @@ def main():
if not waitVmActive(nova_client, vm2):
logger.error("Instance '%s' cannot be booted. Status is '%s'" % (
- NAME_VM_2, functest_utils.get_instance_status(nova_client, vm2)))
+ NAME_VM_2, openstack_utils.get_instance_status(nova_client, vm2)))
cleanup(nova_client, neutron_client, image_id, network_dic, sg_id, floatip_dic)
return (EXIT_CODE)
else:
logger.info("Instance '%s' is ACTIVE." % NAME_VM_2)
logger.info("Adding '%s' to security group '%s'..." % (NAME_VM_2, SECGROUP_NAME))
- functest_utils.add_secgroup_to_instance(nova_client, vm2.id, sg_id)
+ openstack_utils.add_secgroup_to_instance(nova_client, vm2.id, sg_id)
logger.info("Creating floating IP for VM '%s'..." % NAME_VM_2)
- floatip_dic = functest_utils.create_floating_ip(neutron_client)
+ floatip_dic = openstack_utils.create_floating_ip(neutron_client)
floatip = floatip_dic['fip_addr']
floatip_id = floatip_dic['fip_id']
@@ -483,7 +484,7 @@ def main():
logger.info("Floating IP created: '%s'" % floatip)
logger.info("Associating floating ip: '%s' to VM '%s' " % (floatip, NAME_VM_2))
- if not functest_utils.add_floating_ip(nova_client, vm2.id, floatip):
+ if not openstack_utils.add_floating_ip(nova_client, vm2.id, floatip):
logger.error("Cannot associate floating IP to VM.")
cleanup(nova_client, neutron_client, image_id, network_dic, sg_id, floatip_dic)
return (EXIT_CODE)