summaryrefslogtreecommitdiffstats
path: root/test/functest/testcase_4.py
diff options
context:
space:
mode:
authorRomanos Skiadas <rski@intracom-telecom.com>2016-09-07 12:35:52 +0000
committerJose Lausuch <jose.lausuch@ericsson.com>2016-09-09 13:35:05 +0000
commite0095c0f7bc359910633fda491013e9c1fae3408 (patch)
tree85273c61338a3bc25bab6f8b4a9663f85869740e /test/functest/testcase_4.py
parent75589404a758145d18bdcb7f5813c818f12b3729 (diff)
Refactor some common methods into utils
- generete_ping_userdata(): This method was exactly the same in two tests - create_instance(): The various implementations of this method had almost the same signature, but not quite. This was fixed by adding extra arguments as needed. Also a global variable was used in the function, which was converted into a parameter. - create_network(): The three implementations of create_network had three different signatures and returned different variables. They were all unified in a single create_network class and the calls to create_network were adjusted accordingly. Revision 1: Fix flake8 violations Revision 2: Rename logger in utils Change-Id: Ib6cfe798dc561a69eb50c901e3aa71c19d465821 Signed-off-by: Romanos Skiadas <rski@intracom-telecom.com> (cherry picked from commit 4c2e5fb06be31502ab3476f25f6d1c2ef8d7b0f1)
Diffstat (limited to 'test/functest/testcase_4.py')
-rw-r--r--test/functest/testcase_4.py179
1 files changed, 58 insertions, 121 deletions
diff --git a/test/functest/testcase_4.py b/test/functest/testcase_4.py
index c7d222e..cc4237c 100644
--- a/test/functest/testcase_4.py
+++ b/test/functest/testcase_4.py
@@ -18,6 +18,7 @@ import functest.utils.functest_logger as ft_logger
import functest.utils.functest_utils as ft_utils
import functest.utils.openstack_utils as os_utils
+import utils as test_utils
parser = argparse.ArgumentParser()
@@ -94,79 +95,6 @@ NUM_TESTS = 0
NUM_TESTS_FAILED = 0
-def create_network(neutron_client, net, subnet, router, cidr):
- network_dic = os_utils.create_network_full(neutron_client,
- net,
- subnet,
- router,
- cidr)
- if not network_dic:
- logger.error(
- "There has been a problem when creating the neutron network")
- sys.exit(-1)
- return network_dic["net_id"], \
- network_dic["subnet_id"], \
- network_dic["router_id"]
-
-
-def create_instance(nova_client,
- name,
- flavor,
- image_id,
- network_id,
- sg_id,
- compute_node='',
- userdata=None):
- logger.info("Creating instance '%s'..." % name)
- logger.debug(
- "Configuration:\n name=%s \n flavor=%s \n image=%s \n "
- "network=%s \n secgroup=%s \n hypervisor=%s \n userdata=%s\n"
- % (name, flavor, image_id, network_id, sg_id, compute_node, userdata))
- instance = os_utils.create_instance_and_wait_for_active(
- flavor,
- image_id,
- network_id,
- name,
- config_drive=True,
- userdata=userdata,
- av_zone=compute_node)
-
- if instance is None:
- logger.error("Error while booting instance.")
- sys.exit(-1)
- # Retrieve IP of INSTANCE
- # instance_ip = instance.networks.get(network_id)[0]
-
- logger.debug("Adding '%s' to security group '%s'..."
- % (name, SECGROUP_NAME))
- os_utils.add_secgroup_to_instance(nova_client, instance.id, sg_id)
-
- return instance
-
-
-def generate_ping_userdata(ips_array):
- ips = ""
- for ip in ips_array:
- ips = ("%s %s" % (ips, ip))
-
- ips = ips.replace(' ', ' ')
- return ("#!/bin/sh\n"
- "set%s\n"
- "while true; do\n"
- " for i do\n"
- " ip=$i\n"
- " ping -c 1 $ip 2>&1 >/dev/null\n"
- " RES=$?\n"
- " if [ \"Z$RES\" = \"Z0\" ] ; then\n"
- " echo ping $ip OK\n"
- " else echo ping $ip KO\n"
- " fi\n"
- " done\n"
- " sleep 1\n"
- "done\n"
- % ips)
-
-
def get_ping_status(vm_source, ip_source,
vm_target, ip_target,
expected="PASS", timeout=30):
@@ -260,16 +188,16 @@ def main():
disk=IMAGE_FORMAT,
container="bare",
public=True)
- network_1_id, _, router_1_id = create_network(neutron_client,
- NET_1_NAME,
- SUBNET_1_NAME,
- ROUTER_1_NAME,
- SUBNET_1_CIDR)
- network_2_id, _, router_2_id = create_network(neutron_client,
- NET_2_NAME,
- SUBNET_2_NAME,
- ROUTER_2_NAME,
- SUBNET_2_CIDR)
+ network_1_id, _, router_1_id = test_utils.create_network(neutron_client,
+ NET_1_NAME,
+ SUBNET_1_NAME,
+ SUBNET_1_CIDR,
+ ROUTER_1_NAME)
+ network_2_id, _, router_2_id = test_utils.create_network(neutron_client,
+ NET_2_NAME,
+ SUBNET_2_NAME,
+ SUBNET_2_CIDR,
+ ROUTER_2_NAME)
sg_id = os_utils.create_security_group_full(neutron_client,
SECGROUP_NAME, SECGROUP_DESCR)
@@ -287,63 +215,72 @@ def main():
av_zone_2 = "nova:" + compute_nodes[1]
# boot INTANCES
- vm_2 = create_instance(nova_client,
- INSTANCE_2_NAME,
- FLAVOR,
- image_id,
- network_1_id,
- sg_id,
- av_zone_1)
+ vm_2 = test_utils.create_instance(nova_client,
+ INSTANCE_2_NAME,
+ FLAVOR,
+ image_id,
+ network_1_id,
+ sg_id,
+ secgroup_name=SECGROUP_NAME,
+ compute_node=av_zone_1)
vm_2_ip = vm_2.networks.itervalues().next()[0]
logger.debug("Instance '%s' booted successfully. IP='%s'." %
(INSTANCE_2_NAME, vm_2_ip))
- vm_3 = create_instance(nova_client,
- INSTANCE_3_NAME,
- FLAVOR, image_id,
- network_1_id,
- sg_id,
- av_zone_2)
+ vm_3 = test_utils.create_instance(nova_client,
+ INSTANCE_3_NAME,
+ FLAVOR,
+ image_id,
+ network_1_id,
+ sg_id,
+ secgroup_name=SECGROUP_NAME,
+ compute_node=av_zone_2)
vm_3_ip = vm_3.networks.itervalues().next()[0]
logger.debug("Instance '%s' booted successfully. IP='%s'." %
(INSTANCE_3_NAME, vm_3_ip))
- vm_5 = create_instance(nova_client,
- INSTANCE_5_NAME,
- FLAVOR,
- image_id,
- network_2_id,
- sg_id,
- av_zone_2)
+ vm_5 = test_utils.create_instance(nova_client,
+ INSTANCE_5_NAME,
+ FLAVOR,
+ image_id,
+ network_2_id,
+ sg_id,
+ secgroup_name=SECGROUP_NAME,
+ compute_node=av_zone_2)
vm_5_ip = vm_5.networks.itervalues().next()[0]
logger.debug("Instance '%s' booted successfully. IP='%s'." %
(INSTANCE_5_NAME, vm_5_ip))
# We boot vm5 first because we need vm5_ip for vm4 userdata
- u4 = generate_ping_userdata([vm_5_ip])
- vm_4 = create_instance(nova_client,
- INSTANCE_4_NAME,
- FLAVOR,
- image_id,
- network_2_id,
- sg_id,
- av_zone_1,
- userdata=u4)
+ u4 = test_utils.generate_ping_userdata([vm_5_ip])
+ vm_4 = test_utils.create_instance(nova_client,
+ INSTANCE_4_NAME,
+ FLAVOR,
+ image_id,
+ network_2_id,
+ sg_id,
+ secgroup_name=SECGROUP_NAME,
+ compute_node=av_zone_1,
+ userdata=u4)
vm_4_ip = vm_4.networks.itervalues().next()[0]
logger.debug("Instance '%s' booted successfully. IP='%s'." %
(INSTANCE_4_NAME, vm_4_ip))
# We boot VM1 at the end because we need to get the IPs first to generate
# the userdata
- u1 = generate_ping_userdata([vm_2_ip, vm_3_ip, vm_4_ip, vm_5_ip])
- vm_1 = create_instance(nova_client,
- INSTANCE_1_NAME,
- FLAVOR,
- image_id,
- network_1_id,
- sg_id,
- av_zone_1,
- userdata=u1)
+ u1 = test_utils.generate_ping_userdata([vm_2_ip,
+ vm_3_ip,
+ vm_4_ip,
+ vm_5_ip])
+ vm_1 = test_utils.create_instance(nova_client,
+ INSTANCE_1_NAME,
+ FLAVOR,
+ image_id,
+ network_1_id,
+ sg_id,
+ secgroup_name=SECGROUP_NAME,
+ compute_node=av_zone_1,
+ userdata=u1)
vm_1_ip = vm_1.networks.itervalues().next()[0]
logger.debug("Instance '%s' booted successfully. IP='%s'." %
(INSTANCE_1_NAME, vm_1_ip))