aboutsummaryrefslogtreecommitdiffstats
path: root/testcases/vPing/CI/libraries/vPing2.py
diff options
context:
space:
mode:
Diffstat (limited to 'testcases/vPing/CI/libraries/vPing2.py')
-rw-r--r--testcases/vPing/CI/libraries/vPing2.py107
1 files changed, 75 insertions, 32 deletions
diff --git a/testcases/vPing/CI/libraries/vPing2.py b/testcases/vPing/CI/libraries/vPing2.py
index a60ae000f..1ce6dc9e5 100644
--- a/testcases/vPing/CI/libraries/vPing2.py
+++ b/testcases/vPing/CI/libraries/vPing2.py
@@ -197,7 +197,7 @@ def create_private_neutron_net(neutron):
return network_dic
-def cleanup(nova, neutron, image_id, network_dic, port_id1, port_id2):
+def cleanup(nova, neutron, image_id, network_dic, port_id1, port_id2, secgroup_id):
# delete both VMs
logger.info("Cleaning up...")
@@ -232,7 +232,7 @@ def cleanup(nova, neutron, image_id, network_dic, port_id1, port_id2):
logger.debug("Instance %s terminated." % NAME_VM_2)
# delete created network
- logger.info("Deleting network '%s'..." % NEUTRON_PRIVATE_NET_NAME)
+ logger.debug("Deleting network '%s'..." % NEUTRON_PRIVATE_NET_NAME)
net_id = network_dic["net_id"]
subnet_id = network_dic["subnet_id"]
router_id = network_dic["router_id"]
@@ -274,8 +274,28 @@ def cleanup(nova, neutron, image_id, network_dic, port_id1, port_id2):
logger.debug(
"Network '%s' deleted successfully" % NEUTRON_PRIVATE_NET_NAME)
+ if not functest_utils.delete_security_group(neutron, secgroup_id):
+ logger.error("Unable to delete security group '%s'" % secgroup_id)
+ return False
+ logger.debug(
+ "Security group '%s' deleted successfully" % secgroup_id)
+
return True
+def push_results(start_time_ts, duration, test_status):
+ try:
+ logger.debug("Pushing result into DB...")
+ scenario = functest_utils.get_scenario(logger)
+ pod_name = functest_utils.get_pod_name(logger)
+ functest_utils.push_results_to_db(TEST_DB,
+ "vPing",
+ logger, pod_name, scenario,
+ payload={'timestart': start_time_ts,
+ 'duration': duration,
+ 'status': test_status})
+ except:
+ logger.error("Error pushing results into Database '%s'" % sys.exc_info()[0])
+
def main():
@@ -302,7 +322,8 @@ def main():
if not image_id:
logger.error("Failed to create a Glance image...")
return(EXIT_CODE)
-
+ logger.debug("Image '%s' with ID=%s created successfully." %\
+ (GLANCE_IMAGE_NAME, image_id))
# Check if the given image exists
image = functest_utils.get_image_id(glance_client, GLANCE_IMAGE_NAME)
if image == '':
@@ -339,6 +360,36 @@ def main():
logger.info("Instance %s found. Deleting..." % server.name)
server.delete()
+ SECGROUP_NAME = "vPing-sg"
+ SECGROUP_DESCR = "Security group for vPing test case"
+ logger.info("Creating security group '%s'..." % SECGROUP_NAME)
+ SECGROUP = functest_utils.create_security_group(neutron_client,
+ SECGROUP_NAME,
+ SECGROUP_DESCR)
+ SECGROUP_ID = SECGROUP['id']
+ if not SECGROUP:
+ logger.error("Failed to create the security group...")
+ return(EXIT_CODE)
+ logger.debug("Security group '%s' with ID=%s created successfully." %\
+ (SECGROUP['name'], SECGROUP_ID))
+
+ logger.debug("Adding ICMP rules in security group '%s'..." % SECGROUP_NAME)
+ if not functest_utils.create_secgroup_rule(neutron_client, SECGROUP_ID, \
+ 'ingress', 'icmp'):
+ logger.error("Failed to create the security group rule...")
+ return(EXIT_CODE)
+
+ logger.debug("Adding SSH rules in security group '%s'..." % SECGROUP_NAME)
+ if not functest_utils.create_secgroup_rule(neutron_client, SECGROUP_ID, \
+ 'ingress', 'tcp', '22', '22'):
+ logger.error("Failed to create the security group rule...")
+ return(EXIT_CODE)
+
+ if not functest_utils.create_secgroup_rule(neutron_client, SECGROUP_ID, \
+ 'egress', 'tcp', '22', '22'):
+ logger.error("Failed to create the security group rule...")
+ return(EXIT_CODE)
+
# boot VM 1
# basic boot
# tune (e.g. flavor, images, network) to your specific
@@ -373,10 +424,10 @@ 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)))
- cleanup(nova_client, neutron_client, image_id, network_dic, port_id1)
+ cleanup(nova_client, neutron_client, image_id, network_dic,
+ port_id1, SECGROUP_ID)
return (EXIT_CODE)
else:
logger.info("Instance '%s' is ACTIVE." % NAME_VM_1)
@@ -391,6 +442,9 @@ def main():
test_ip = IP_1
logger.debug("Instance '%s' got %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, SECGROUP['id'])
+
# boot VM 2
# we will boot then execute a ping script with cloud-init
# the long chain corresponds to the ping procedure converted with base 64
@@ -410,8 +464,8 @@ def main():
logger.info("Creating instance '%s' with IP %s..." % (NAME_VM_2, IP_2))
logger.debug(
- "Configuration:\n name=%s \n flavor=%s \n image=%s \n network=%s "
- "\n" % (NAME_VM_2, flavor, image, network_id))
+ "Configuration:\n name=%s \n flavor=%s \n image=%s \n "
+ "network=%s \n" % (NAME_VM_2, flavor, image, network_id))
vm2 = nova_client.servers.create(
name=NAME_VM_2,
flavor=flavor,
@@ -423,25 +477,28 @@ def main():
logger.error("Instance '%s' cannot be booted. Status is '%s'" % (
NAME_VM_2, functest_utils.get_instance_status(nova_client, vm2)))
cleanup(nova_client, neutron_client, image_id, network_dic,
- port_id1, port_id2)
+ port_id1, port_id2, SECGROUP_ID)
return (EXIT_CODE)
else:
logger.info("Instance '%s' is ACTIVE." % NAME_VM_2)
- logger.info("Creating floating IP for the second VM...")
+ logger.info("Adding '%s' to security group '%s'..." % (NAME_VM_2, SECGROUP_NAME))
+ functest_utils.add_secgroup_to_instance(nova_client, vm2.id, SECGROUP['id'])
+
+ logger.info("Creating floating IP for VM '%s'..." % NAME_VM_2)
floatip = functest_utils.create_floating_ip(neutron_client)
if floatip == None:
logger.error("Cannot create floating IP.")
cleanup(nova_client, neutron_client, image_id, network_dic,
- port_id1, port_id2)
+ port_id1, port_id2, SECGROUP_ID)
return (EXIT_CODE)
logger.info("Floating IP created: '%s'" % floatip)
- logger.info("Associating floating ip: '%s' to VM2 " % 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):
logger.error("Cannot associate floating IP to VM.")
cleanup(nova_client, neutron_client, image_id, network_dic,
- port_id1, port_id2)
+ port_id1, port_id2, SECGROUP_ID)
return (EXIT_CODE)
logger.info("Trying to establish SSH connection to %s..." % floatip)
@@ -465,7 +522,7 @@ def main():
if timeout == 0: # 300 sec timeout (5 min)
logger.error("Cannot establish connection to IP '%s'. Aborting" % floatip)
cleanup(nova_client, neutron_client, image_id, network_dic,
- port_id1, port_id2)
+ port_id1, port_id2, SECGROUP_ID)
return (EXIT_CODE)
scp = SCPClient(ssh.get_transport())
@@ -517,7 +574,7 @@ def main():
# we consider start time at VM1 booting
end_time_ts = time.time()
duration = round(end_time_ts - start_time_ts, 1)
- logger.info("vPing duration:'%s'" % duration)
+ logger.info("vPing duration:'%s' s." % duration)
EXIT_CODE = 0
flag = True
break
@@ -531,32 +588,18 @@ def main():
sec += 1
cleanup(nova_client, neutron_client, image_id, network_dic,
- port_id1, port_id2)
+ port_id1, port_id2, SECGROUP_ID)
test_status = "NOK"
if EXIT_CODE == 0:
logger.info("vPing OK")
test_status = "OK"
else:
+ duration = 0
logger.error("vPing FAILED")
- try:
- if args.report:
- logger.debug("Push result into DB")
- # TODO check path result for the file
- scenario = functest_utils.get_scenario(logger)
- pod_name = functest_utils.get_pod_name(logger)
- functest_utils.push_results_to_db(TEST_DB,
- "vPing",
- logger, pod_name, scenario,
- payload={'timestart': start_time_ts,
- 'duration': duration,
- 'status': test_status})
- # with open("vPing-result.json", "w") as outfile:
- # json.dump({'timestart': start_time_ts, 'duration': duration,
- # 'status': test_status}, outfile, indent=4)
- except:
- logger.error("Error pushing results into Database '%s'" % sys.exc_info()[0])
+ if args.report:
+ push_results(start_time_ts, duration, test_status)
exit(EXIT_CODE)