summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuan Vidal <juan.vidal.allende@ericsson.com>2017-02-21 12:49:32 +0000
committerJuan Vidal <juan.vidal.allende@ericsson.com>2017-04-05 12:26:15 +0000
commit5750895da4e626cc897878acaf6607bd14298802 (patch)
treea5064d41f8772ee0cb43e4a790b2287d48a0d97c
parent8a66eac4bbb898d943d461845e371381425a9cf7 (diff)
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 <juan.vidal.allende@ericsson.com>
-rw-r--r--sfc/lib/utils.py28
-rw-r--r--sfc/tests/functest/sfc_one_chain_two_service_functions.py75
-rw-r--r--sfc/tests/functest/sfc_symmetric_chain.py1
-rw-r--r--sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py85
4 files changed, 98 insertions, 91 deletions
diff --git a/sfc/lib/utils.py b/sfc/lib/utils.py
index fb14ff60..e7e93e15 100644
--- a/sfc/lib/utils.py
+++ b/sfc/lib/utils.py
@@ -263,34 +263,6 @@ def assign_floating_ip(nova_client, neutron_client, instance_id):
return floating_ip
-def get_floating_ips(nova_client, neutron_client):
- ips = []
- 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)
- ips.append(floatip)
-
- return server_ip, client_ip, ips[1], ips[0]
-
-
def start_http_server(ip):
"""Start http server on a given machine, Can be VM"""
cmd = "\'python -m SimpleHTTPServer 80"
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')
diff --git a/sfc/tests/functest/sfc_symmetric_chain.py b/sfc/tests/functest/sfc_symmetric_chain.py
index 1a699ca3..29ecee24 100644
--- a/sfc/tests/functest/sfc_symmetric_chain.py
+++ b/sfc/tests/functest/sfc_symmetric_chain.py
@@ -151,6 +151,7 @@ def main():
sys.exit(1)
vnf_instance_id = test_utils.get_nova_id(tacker_client, 'vdu1', vnf_id)
+ os_utils.add_secgroup_to_instance(nova_client, vnf_instance_id, sg_id)
os_tacker.create_sfc(
tacker_client,
diff --git a/sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py b/sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py
index a774672d..7cde7433 100644
--- a/sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py
+++ b/sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py
@@ -115,25 +115,25 @@ def main():
TESTCASE_CONFIG.secgroup_name,
TESTCASE_CONFIG.secgroup_descr)
- vnfs = ['testVNF1', 'testVNF2']
+ vnf_names = ['testVNF1', 'testVNF2']
topo_seed = topo_shuffler.get_seed() # change to None for nova av zone
- testTopology = topo_shuffler.topology(vnfs, seed=topo_seed)
+ testTopology = topo_shuffler.topology(vnf_names, seed=topo_seed)
logger.info('This test is run with the topology {0}'
.format(testTopology['id']))
logger.info('Topology description: {0}'
.format(testTopology['description']))
- test_utils.create_instance(
+ 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]
+ server_ip = server_instance.networks.get(TESTCASE_CONFIG.net_name)[0]
tosca_red = os.path.join(COMMON_CONFIG.sfc_test_dir,
COMMON_CONFIG.vnfd_dir,
@@ -151,22 +151,23 @@ def main():
COMMON_CONFIG.vnfd_default_params_file)
test_utils.create_vnf_in_av_zone(
- tacker_client, vnfs[0], 'test-vnfd1',
- default_param_file, testTopology[vnfs[0]])
+ tacker_client, vnf_names[0], 'test-vnfd1',
+ default_param_file, testTopology[vnf_names[0]])
test_utils.create_vnf_in_av_zone(
- tacker_client, vnfs[1], 'test-vnfd2',
- default_param_file, testTopology[vnfs[1]])
+ tacker_client, vnf_names[1], 'test-vnfd2',
+ default_param_file, testTopology[vnf_names[1]])
- vnf1_id = os_tacker.wait_for_vnf(tacker_client, vnf_name='testVNF1')
- vnf2_id = os_tacker.wait_for_vnf(tacker_client, vnf_name='testVNF2')
+ vnf1_id = os_tacker.wait_for_vnf(tacker_client, vnf_name=vnf_names[0])
+ vnf2_id = os_tacker.wait_for_vnf(tacker_client, vnf_name=vnf_names[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=['testVNF1'])
os_tacker.create_sfc(tacker_client, 'blue', chain_vnf_names=['testVNF2'])
@@ -200,29 +201,46 @@ 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.error(
- '\033[91mFailed to start HTTP server on %s\033[0m' % 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_floating_ip)
sys.exit(1)
- logger.info("Starting SSH firewall on %s" % sf1)
- test_utils.start_vxlan_tool(sf1, block="22")
- logger.info("Starting HTTP firewall on %s" % sf2)
- test_utils.start_vxlan_tool(sf2, block="80")
+ logger.info("Starting SSH firewall on %s" % sf1_floating_ip)
+ test_utils.start_vxlan_tool(sf1_floating_ip, block="22")
+ logger.info("Starting HTTP firewall on %s" % sf2_floating_ip)
+ test_utils.start_vxlan_tool(sf2_floating_ip, block="80")
logger.info("Wait for ODL to update the classification rules in OVS")
t1.join()
logger.info("Test SSH")
- if test_utils.is_ssh_blocked(client_ip, srv_prv_ip):
+ if test_utils.is_ssh_blocked(client_floating_ip, server_ip):
results.add_to_summary(2, "PASS", "SSH Blocked")
else:
error = ('\033[91mTEST 1 [FAILED] ==> SSH NOT BLOCKED\033[0m')
@@ -232,7 +250,7 @@ def main():
results.add_to_summary(2, "FAIL", "SSH Blocked")
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 2 [FAILED] ==> HTTP BLOCKED\033[0m')
@@ -279,7 +297,7 @@ def main():
t2.join()
logger.info("Test HTTP")
- 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 3 [FAILED] ==> HTTP WORKS\033[0m')
@@ -289,7 +307,7 @@ def main():
results.add_to_summary(2, "FAIL", "HTTP Blocked")
logger.info("Test SSH")
- if not test_utils.is_ssh_blocked(client_ip, srv_prv_ip):
+ if not test_utils.is_ssh_blocked(client_floating_ip, server_ip):
results.add_to_summary(2, "PASS", "SSH works")
else:
error = ('\033[91mTEST 4 [FAILED] ==> SSH BLOCKED\033[0m')
@@ -298,11 +316,6 @@ def main():
ovs_logger, controller_clients, compute_clients, error)
results.add_to_summary(2, "FAIL", "SSH works")
- logger.info('This test is run with the topology {0}'
- .format(testTopology['id']))
- logger.info('Topology description: {0}'
- .format(testTopology['description']))
-
return results.compile_summary()