From 5750895da4e626cc897878acaf6607bd14298802 Mon Sep 17 00:00:00 2001 From: Juan Vidal Date: Tue, 21 Feb 2017 12:49:32 +0000 Subject: Remove get_floating_ips() get_floating_ips() is non-reusable function, with too much logic into it. By using smaller functions, we can compose the same functionality and build all tests upon a common set of utilities. Using the new functions in functest to retrieve the nova ID for a VNF instance, it is possible to use a generic solution at the problem of getting floating ips deterministcally to the instances Change-Id: Ic7dba908fa6bb343c177fe1a68322d3803ed1707 Signed-off-by: Juan Vidal --- .../sfc_one_chain_two_service_functions.py | 75 ++++++++++++++-------- 1 file changed, 48 insertions(+), 27 deletions(-) (limited to 'sfc/tests/functest/sfc_one_chain_two_service_functions.py') diff --git a/sfc/tests/functest/sfc_one_chain_two_service_functions.py b/sfc/tests/functest/sfc_one_chain_two_service_functions.py index d28c6178..bd457bee 100644 --- a/sfc/tests/functest/sfc_one_chain_two_service_functions.py +++ b/sfc/tests/functest/sfc_one_chain_two_service_functions.py @@ -114,15 +114,18 @@ def main(): logger.info('Topology description: {0}' .format(testTopology['description'])) - test_utils.create_instance( - nova_client, CLIENT, COMMON_CONFIG.flavor, - image_id, network_id, sg_id, av_zone=testTopology['client']) + client_instance = test_utils.create_instance( + nova_client, CLIENT, COMMON_CONFIG.flavor, image_id, + network_id, sg_id, av_zone=testTopology['client']) - srv_instance = test_utils.create_instance( + server_instance = test_utils.create_instance( nova_client, SERVER, COMMON_CONFIG.flavor, image_id, network_id, sg_id, av_zone=testTopology['server']) - srv_prv_ip = srv_instance.networks.get(TESTCASE_CONFIG.net_name)[0] + client_ip = client_instance.networks.get(TESTCASE_CONFIG.net_name)[0] + logger.info("Client instance received private ip [{}]".format(client_ip)) + server_ip = server_instance.networks.get(TESTCASE_CONFIG.net_name)[0] + logger.info("Server instance received private ip [{}]".format(client_ip)) tosca_file = os.path.join(COMMON_CONFIG.sfc_test_dir, COMMON_CONFIG.vnfd_dir, @@ -151,16 +154,17 @@ def main(): tacker_client, vnfs[1], 'test-vnfd2', default_param_file, testTopology[vnfs[1]]) - vnf1 = os_tacker.wait_for_vnf(tacker_client, vnf_name=vnfs[0]) - vnf2 = os_tacker.wait_for_vnf(tacker_client, vnf_name=vnfs[1]) - if vnf1 is None or vnf2 is None: + vnf1_id = os_tacker.wait_for_vnf(tacker_client, vnf_name=vnfs[0]) + vnf2_id = os_tacker.wait_for_vnf(tacker_client, vnf_name=vnfs[1]) + if vnf1_id is None or vnf2_id is None: logger.error('ERROR while booting vnfs') sys.exit(1) - instances = os_utils.get_instances(nova_client) - for instance in instances: - if ('client' not in instance.name) and ('server' not in instance.name): - os_utils.add_secgroup_to_instance(nova_client, instance.id, sg_id) + vnf1_instance_id = test_utils.get_nova_id(tacker_client, 'vdu1', vnf1_id) + os_utils.add_secgroup_to_instance(nova_client, vnf1_instance_id, sg_id) + + vnf2_instance_id = test_utils.get_nova_id(tacker_client, 'vdu1', vnf2_id) + os_utils.add_secgroup_to_instance(nova_client, vnf2_instance_id, sg_id) os_tacker.create_sfc(tacker_client, 'red', chain_vnf_names=[vnfs[0], vnfs[1]]) @@ -185,28 +189,45 @@ def main(): except Exception, e: logger.error("Unable to start the thread that counts time %s" % e) - server_ip, client_ip, sf1, sf2 = test_utils.get_floating_ips( - nova_client, neutron_client) - - if not test_utils.check_ssh([sf1, sf2]): + logger.info("Assigning floating IPs to instances") + server_floating_ip = test_utils.assign_floating_ip( + nova_client, neutron_client, server_instance.id) + client_floating_ip = test_utils.assign_floating_ip( + nova_client, neutron_client, client_instance.id) + sf1_floating_ip = test_utils.assign_floating_ip( + nova_client, neutron_client, vnf1_instance_id) + sf2_floating_ip = test_utils.assign_floating_ip( + nova_client, neutron_client, vnf2_instance_id) + + for ip in (server_floating_ip, + client_floating_ip, + sf1_floating_ip, + sf2_floating_ip): + logger.info("Checking connectivity towards floating IP [%s]" % ip) + if not test_utils.ping(ip, retries=50, retry_timeout=1): + logger.error("Cannot ping floating IP [%s]" % ip) + sys.exit(1) + logger.info("Successful ping to floating IP [%s]" % ip) + + if not test_utils.check_ssh([sf1_floating_ip, sf2_floating_ip]): logger.error("Cannot establish SSH connection to the SFs") sys.exit(1) - logger.info("Starting HTTP server on %s" % server_ip) - if not test_utils.start_http_server(server_ip): + logger.info("Starting HTTP server on %s" % server_floating_ip) + if not test_utils.start_http_server(server_floating_ip): logger.error( - '\033[91mFailed to start HTTP server on %s\033[0m' % server_ip) + 'Failed to start HTTP server on %s' % server_floating_ip) sys.exit(1) - for sf in (sf1, sf2): - logger.info("Starting vxlan_tool on %s" % sf) - test_utils.start_vxlan_tool(sf) + for sf_floating_ip in (sf1_floating_ip, sf2_floating_ip): + logger.info("Starting vxlan_tool on %s" % sf_floating_ip) + test_utils.start_vxlan_tool(sf_floating_ip) logger.info("Wait for ODL to update the classification rules in OVS") t1.join() logger.info("Test HTTP") - if not test_utils.is_http_blocked(client_ip, srv_prv_ip): + if not test_utils.is_http_blocked(client_floating_ip, server_ip): results.add_to_summary(2, "PASS", "HTTP works") else: error = ('\033[91mTEST 1 [FAILED] ==> HTTP BLOCKED\033[0m') @@ -218,12 +239,12 @@ def main(): logger.info("Changing the vxlan_tool to block HTTP traffic") # Make SF1 block now http traffic - test_utils.stop_vxlan_tool(sf1) - logger.info("Starting HTTP firewall on %s" % sf1) - test_utils.start_vxlan_tool(sf1, block="80") + test_utils.stop_vxlan_tool(sf1_floating_ip) + logger.info("Starting HTTP firewall on %s" % sf1_floating_ip) + test_utils.start_vxlan_tool(sf1_floating_ip, block="80") logger.info("Test HTTP again") - if test_utils.is_http_blocked(client_ip, srv_prv_ip): + if test_utils.is_http_blocked(client_floating_ip, server_ip): results.add_to_summary(2, "PASS", "HTTP Blocked") else: error = ('\033[91mTEST 2 [FAILED] ==> HTTP WORKS\033[0m') -- cgit 1.2.3-korg