diff options
-rw-r--r-- | sfc/lib/utils.py | 56 | ||||
-rw-r--r-- | sfc/tests/functest/sfc_symmetric_chain.py | 21 |
2 files changed, 41 insertions, 36 deletions
diff --git a/sfc/lib/utils.py b/sfc/lib/utils.py index 6a1192b3..2b8bdc13 100644 --- a/sfc/lib/utils.py +++ b/sfc/lib/utils.py @@ -194,6 +194,16 @@ def ping(remote, retries=100, retry_timeout=1): return False +def assign_floating_ip(nova_client, neutron_client, instance_id): + instance = nova_client.servers.get(instance_id) + floating_ip = os_utils.create_floating_ip(neutron_client)['fip_addr'] + instance.add_floating_ip(floating_ip) + logger.info("Assigned floating ip [%s] to instance [%s]" + % (floating_ip, instance.name)) + + return floating_ip + + def get_floating_ips(nova_client, neutron_client): ips = [] instances = nova_client.servers.list() @@ -222,38 +232,6 @@ def get_floating_ips(nova_client, neutron_client): return server_ip, client_ip, ips[1], ips[0] -# TODO (jvidal): This is pure scaffolding, it needs to be merged with -# get_floating_ips in the future -def get_floating_ips_2(nova_client, neutron_client): - sf_ip = None - client_ip = None - server_ip = None - instances = nova_client.servers.list() - for instance in instances: - floatip_dic = os_utils.create_floating_ip(neutron_client) - floatip = floatip_dic['fip_addr'] - instance.add_floating_ip(floatip) - logger.info("Instance name and ip %s:%s " % (instance.name, floatip)) - logger.info("Waiting for instance %s:%s to come up" % - (instance.name, floatip)) - if not ping(floatip): - logger.info("Instance %s:%s didn't come up" % - (instance.name, floatip)) - return None - - if instance.name == "server": - logger.info("Server:%s is reachable" % floatip) - server_ip = floatip - elif instance.name == "client": - logger.info("Client:%s is reachable" % floatip) - client_ip = floatip - else: - logger.info("SF:%s is reachable" % floatip) - sf_ip = floatip - - return server_ip, client_ip, sf_ip - - def start_http_server(ip): """Start http server on a given machine, Can be VM""" cmd = "\'python -m SimpleHTTPServer 80" @@ -415,3 +393,17 @@ def setup_compute_node(cidr, compute_nodes): compute.run_cmd(add_cidr) else: logger.info("route %s already exists" % cidr) + + +def get_nova_id(tacker_client, resource, vnf_id=None, vnf_name=None): + vnf = os_tacker.get_vnf(tacker_client, vnf_id, vnf_name) + try: + if vnf is None: + raise Exception("VNF not found") + heat = os_utils.get_heat_client() + resource = heat.resources.get(vnf['instance_id'], resource) + return resource.attributes['id'] + except: + logger.error("Cannot get nova ID for VNF (id='%s', name='%s')" + % (vnf_id, vnf_name)) + return None diff --git a/sfc/tests/functest/sfc_symmetric_chain.py b/sfc/tests/functest/sfc_symmetric_chain.py index d82303a2..3e7ff240 100644 --- a/sfc/tests/functest/sfc_symmetric_chain.py +++ b/sfc/tests/functest/sfc_symmetric_chain.py @@ -105,7 +105,7 @@ def main(): logger.info('Topology description: {0}' .format(testTopology['description'])) - test_utils.create_instance( + client_instance = test_utils.create_instance( nova_client, CLIENT, COMMON_CONFIG.flavor, @@ -148,6 +148,8 @@ def main(): logger.error('ERROR while booting VNF') sys.exit(1) + vnf_instance_id = test_utils.get_nova_id(tacker_client, 'vdu1', vnf_id) + os_tacker.create_sfc( tacker_client, sfc_name='red', @@ -180,9 +182,20 @@ def main(): except Exception, e: logger.error("Unable to start the thread that counts time %s" % e) - # TODO: Find a replacement for get_floating_ips() - server_floating_ip, client_floating_ip, sf_floating_ip = \ - test_utils.get_floating_ips_2(nova_client, neutron_client) + 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) + sf_floating_ip = test_utils.assign_floating_ip( + nova_client, neutron_client, vnf_instance_id) + + for ip in (server_floating_ip, client_floating_ip, sf_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([sf_floating_ip]): logger.error("Cannot establish SSH connection to the SFs") |