diff options
-rw-r--r-- | testcases/config_functest.yaml | 2 | ||||
-rw-r--r-- | testcases/functest_utils.py | 14 | ||||
-rw-r--r-- | testcases/vPing/CI/libraries/vPing.py | 72 |
3 files changed, 60 insertions, 28 deletions
diff --git a/testcases/config_functest.yaml b/testcases/config_functest.yaml index eb1c9a2cf..40eb024ad 100644 --- a/testcases/config_functest.yaml +++ b/testcases/config_functest.yaml @@ -35,3 +35,5 @@ vping: vm_flavor: m1.small #adapt to your environment vm_name_1: opnfv-vping-1 vm_name_2: opnfv-vping-2 + ip_1: 192.168.120.30 + ip_2: 192.168.120.40 diff --git a/testcases/functest_utils.py b/testcases/functest_utils.py index 7b61198d1..f879a1a95 100644 --- a/testcases/functest_utils.py +++ b/testcases/functest_utils.py @@ -163,6 +163,20 @@ def remove_interface_router(neutron_client, router_id, subnet_id): print "Error:", sys.exc_info()[0] return False +def create_neutron_port(neutron_client, name, network_id, ip): + json_body = {'port': { + 'admin_state_up': True, + 'name': name, + 'network_id': network_id, + 'fixed_ips': [{"ip_address": ip}] + }} + try: + port = neutron_client.create_port(body=json_body) + return port['port']['id'] + except: + print "Error:", sys.exc_info()[0] + return False + def get_network_id(neutron_client, network_name): networks = neutron_client.list_networks()['networks'] diff --git a/testcases/vPing/CI/libraries/vPing.py b/testcases/vPing/CI/libraries/vPing.py index 379bf9698..1cc73922c 100644 --- a/testcases/vPing/CI/libraries/vPing.py +++ b/testcases/vPing/CI/libraries/vPing.py @@ -53,6 +53,8 @@ VM_DELETE_TIMEOUT = 100 PING_TIMEOUT = functest_yaml.get("vping").get("ping_timeout") NAME_VM_1 = functest_yaml.get("vping").get("vm_name_1") NAME_VM_2 = functest_yaml.get("vping").get("vm_name_2") +IP_1 = functest_yaml.get("vping").get("ip_1") +IP_2 = functest_yaml.get("vping").get("ip_2") GLANCE_IMAGE_NAME = functest_yaml.get("general").get("openstack").get("image_name") FLAVOR = functest_yaml.get("vping").get("vm_flavor") @@ -135,23 +137,26 @@ def create_private_neutron_net(neutron): def cleanup(nova,neutron,network_dic): # delete both VMs - logger.info("Deleting Instances...") - logger.debug("Deleting '%s'..." %NAME_VM_1) - vm1 = nova.servers.find(name=NAME_VM_1) - nova.servers.delete(vm1) - #wait until VMs are deleted - 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_client,vm1))) - else: - logger.debug("Instance %s terminated." % NAME_VM_1) - - logger.debug("Deleting '%s'..." %NAME_VM_2) - vm2 = nova.servers.find(name=NAME_VM_2) - nova.servers.delete(vm2) - 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_client,vm2))) - else: - logger.debug("Instance %s terminated." % NAME_VM_2) + logger.info("Cleaning up...") + vm1 = functest_utils.get_instance_by_name(nova, NAME_VM_1) + if vm1: + logger.debug("Deleting '%s'..." %NAME_VM_1) + nova.servers.delete(vm1) + #wait until VMs are deleted + 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_client,vm1))) + else: + logger.debug("Instance %s terminated." % NAME_VM_1) + + vm2 = functest_utils.get_instance_by_name(nova, NAME_VM_2) + if vm2: + logger.debug("Deleting '%s'..." %NAME_VM_2) + vm2 = nova.servers.find(name=NAME_VM_2) + nova.servers.delete(vm2) + 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_client,vm2))) + else: + logger.debug("Instance %s terminated." % NAME_VM_2) # delete created network logger.info("Deleting network '%s'..." % NEUTRON_PRIVATE_NET_NAME) @@ -229,16 +234,20 @@ def main(): # tune (e.g. flavor, images, network) to your specific openstack configuration here # create VM - logger.info("Creating instance '%s'..." % NAME_VM_1) + logger.debug("Creating port 'vping-port-1' with IP %s..." %IP_1) + port_id=functest_utils.create_neutron_port(neutron_client, "vping-port-1", network_id, IP_1) + if not port_id: + logger.error("Unable to create port.") + exit(-1) + logger.info("Creating instance '%s' with IP %s..." %(NAME_VM_1,IP_1)) logger.debug("Configuration:\n name=%s \n flavor=%s \n image=%s \n network=%s \n" %(NAME_VM_1,flavor,image,network_id)) vm1 = nova_client.servers.create( name = NAME_VM_1, flavor = flavor, image = image, - nics = [{"net-id": network_id}] + #nics = [{"net-id": network_id, "v4-fixed-ip": IP_1}] + nics = [{"port-id": port_id}] ) - - #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))) @@ -248,11 +257,12 @@ def main(): logger.info("Instance '%s' is ACTIVE." % NAME_VM_1) #retrieve IP of first VM - logger.debug("Fetching IP...") - server = functest_utils.get_instance_by_name(nova_client, NAME_VM_1) + #logger.debug("Fetching IP...") + #server = functest_utils.get_instance_by_name(nova_client, NAME_VM_1) # theoretically there is only one IP address so we take the first element of the table # Dangerous! To be improved! - test_ip = server.networks.get(NEUTRON_PRIVATE_NET_NAME)[0] + #test_ip = server.networks.get(NEUTRON_PRIVATE_NET_NAME)[0] + test_ip=IP_1 logger.debug("Instance '%s' got %s" %(NAME_VM_1,test_ip)) # boot VM 2 @@ -260,16 +270,22 @@ def main(): # the long chain corresponds to the ping procedure converted with base 64 # tune (e.g. flavor, images, network) to your specific openstack configuration here u = "#!/bin/sh\n\nwhile true; do\n ping -c 1 %s 2>&1 >/dev/null\n RES=$?\n if [ \"Z$RES\" = \"Z0\" ] ; then\n echo 'vPing OK'\n break\n else\n echo 'vPing KO'\n fi\n sleep 1\ndone\n"%test_ip - # create VM - logger.info("Creating instance '%s'..." % NAME_VM_2) + + logger.debug("Creating port 'vping-port-2' with IP %s..." %IP_2) + port_id=functest_utils.create_neutron_port(neutron_client, "vping-port-2", network_id, IP_2) + if not port_id: + logger.error("Unable to create port.") + exit(-1) + 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 userdata= \n%s" %(NAME_VM_2,flavor,image,network_id,u)) vm2 = nova_client.servers.create( name = NAME_VM_2, flavor = flavor, image = image, - nics = [{"net-id": network_id}], - userdata = u, + #nics = [{"net-id": network_id, "v4-fixed-ip": IP_2}], + nics = [{"port-id": port_id}], + userdata = u ) if not waitVmActive(nova_client,vm2): |