diff options
8 files changed, 57 insertions, 57 deletions
diff --git a/sfc/lib/utils.py b/sfc/lib/utils.py index 71f46b86..4289ee0a 100644 --- a/sfc/lib/utils.py +++ b/sfc/lib/utils.py @@ -12,10 +12,12 @@ import os import re import subprocess import time +import yaml 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 functest.utils.openstack_tacker as os_tacker logger = ft_logger.Logger("sfc_test_utils").getLogger() @@ -76,6 +78,22 @@ def download_image(url, image_path): logger.info("Using old image") +def create_vnf_in_av_zone(tacker_client, vnf_name, vnfd_name, av_zone=None): + param_file = os.path.join(os.getcwd(), + 'vnfd-templates', + 'test-vnfd-default-params.yaml') + if av_zone is not None: + param_file = os.path.join('/tmp', 'param_{0}.yaml'.format(av_zone)) + data = {'zone': av_zone} + with open(param_file) as f: + yaml.dump(data, f) + + os_tacker.create_vnf(tacker_client, + vnf_name, + vnfd_name=vnfd_name, + param_file=param_file) + + def setup_neutron(neutron_client, net, subnet, router, subnet_cidr): n_dict = os_utils.create_network_full(neutron_client, net, @@ -238,32 +256,28 @@ def vxlan_tool_stop(sf): run_cmd_remote(sf, cmd) -def netcat(s_ip, c_ip, port="80", timeout=5): - """Run netcat on a give machine, Can be VM""" - cmd = "nc -zv " - cmd = cmd + " -w %s %s %s" % (timeout, s_ip, port) - cmd = cmd + " 2>&1" - _, output, _ = run_cmd_remote(c_ip, cmd) +def netcat(source_ip, destination_ip, port, timeout=5): + """ + SSH into source_ip, and check the connectivity from there to destination_ip + on the specified port, using the netcat command. + Returns 0 on successful execution, != 0 on failure + """ + cmd = "nc -zv -w %s %s %s 2>&1" % (timeout, destination_ip, port) + rc, output, _ = run_cmd_remote(source_ip, cmd) + logger.info("Running netcat from [%s] - connecting to [%s] on port [%s]" % + (source_ip, destination_ip, port)) logger.info("%s" % output) - return output + return rc -def is_ssh_blocked(srv_prv_ip, client_ip): - res = netcat(srv_prv_ip, client_ip, port="22") - match = re.search("nc:.*timed out:.*", res, re.M) - if match: - return True - - return False +def is_ssh_blocked(source_ip, destination_ip): + rc = netcat(source_ip, destination_ip, port="22") + return rc != 0 -def is_http_blocked(srv_prv_ip, client_ip): - res = netcat(srv_prv_ip, client_ip, port="80") - match = re.search(".* 80 port.* succeeded!", res, re.M) - if match: - return False - - return True +def is_http_blocked(source_ip, destination_ip): + rc = netcat(source_ip, destination_ip, port="80") + return rc != 0 def capture_ovs_logs(ovs_logger, controller_clients, compute_clients, error): diff --git a/sfc/tests/functest/sfc_one_chain_two_service_functions_different_computes.py b/sfc/tests/functest/sfc_one_chain_two_service_functions_different_computes.py index 71b69dff..8ec4dffb 100644 --- a/sfc/tests/functest/sfc_one_chain_two_service_functions_different_computes.py +++ b/sfc/tests/functest/sfc_one_chain_two_service_functions_different_computes.py @@ -10,7 +10,6 @@ import argparse import os -import re import sys import time @@ -69,26 +68,6 @@ def setup_availability_zones(nova_client): return az -# JIRA: SFC-52 new function -def modify_vnfd(tacker_vnfd, az): - try: - with open(tacker_vnfd, 'r') as stream: - lines = stream.readlines() - with open(tacker_vnfd, 'w') as stream: - for line in lines: - stream.write(re.sub('nova$', az, line)) - - except Exception, e: - logger.error("Problem when changing vnfd %s" % e) - - -# JIRA: SFC-52 new function -def prepare_tacker_vnfd(nova_client): - azs = setup_availability_zones(nova_client) - modify_vnfd(TACKER_VNFD1, azs[0]) - modify_vnfd(TACKER_VNFD2, azs[1]) - - def main(): installer_type = os.environ.get("INSTALLER_TYPE") if installer_type != "fuel": @@ -143,7 +122,7 @@ def main(): TESTCASE_CONFIG.secgroup_name, TESTCASE_CONFIG.secgroup_descr) - prepare_tacker_vnfd(nova_client) + availability_zones = setup_availability_zones(nova_client) test_utils.create_instance( nova_client, CLIENT, COMMON_CONFIG.flavor, @@ -170,10 +149,16 @@ def main(): tacker_client, tosca_file=tosca_file) - os_tacker.create_vnf( - tacker_client, 'testVNF1', vnfd_name='test-vnfd1') - os_tacker.create_vnf( - tacker_client, 'testVNF2', vnfd_name='test-vnfd2') + test_utils.create_vnf_in_av_zone( + tacker_client, + 'testVNF1', + 'test-vnfd1', + av_zone=availability_zones[0]) + test_utils.create_vnf_in_av_zone( + tacker_client, + 'testVNF2', + 'test-vnfd2', + av_zone=availability_zones[1]) try: os_tacker.wait_for_vnf(tacker_client, vnf_name='testVNF1') @@ -218,7 +203,7 @@ def main(): time.sleep(100) logger.info("Test HTTP") - if not test_utils.is_http_blocked(srv_prv_ip, client_ip): + if not test_utils.is_http_blocked(client_ip, srv_prv_ip): logger.info('\033[92mTEST 1 [PASSED] ==> HTTP WORKS\033[0m') update_json_results("Test 1: HTTP works", "Passed") else: @@ -235,7 +220,7 @@ def main(): test_utils.vxlan_firewall(sf1, port="80") logger.info("Test HTTP again") - if test_utils.is_http_blocked(srv_prv_ip, client_ip): + if test_utils.is_http_blocked(client_ip, srv_prv_ip): logger.info('\033[92mTEST 2 [PASSED] ==> HTTP Blocked\033[0m') update_json_results("Test 2: HTTP Blocked", "Passed") else: 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 92ef9f16..4117b237 100644 --- a/sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py +++ b/sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py @@ -190,7 +190,7 @@ def main(): t1.join() logger.info("Test SSH") - if test_utils.is_ssh_blocked(srv_prv_ip, client_ip): + if test_utils.is_ssh_blocked(client_ip, srv_prv_ip): results.add_to_summary(2, "PASS", "SSH Blocked") else: error = ('\033[91mTEST 1 [FAILED] ==> SSH NOT BLOCKED\033[0m') @@ -200,7 +200,7 @@ def main(): results.add_to_summary(2, "FAIL", "SSH Blocked") logger.info("Test HTTP") - if not test_utils.is_http_blocked(srv_prv_ip, client_ip): + if not test_utils.is_http_blocked(client_ip, srv_prv_ip): results.add_to_summary(2, "PASS", "HTTP works") else: error = ('\033[91mTEST 2 [FAILED] ==> HTTP BLOCKED\033[0m') @@ -243,7 +243,7 @@ def main(): t2.join() logger.info("Test HTTP") - if test_utils.is_http_blocked(srv_prv_ip, client_ip): + if test_utils.is_http_blocked(client_ip, srv_prv_ip): results.add_to_summary(2, "PASS", "HTTP Blocked") else: error = ('\033[91mTEST 3 [FAILED] ==> HTTP WORKS\033[0m') @@ -253,7 +253,7 @@ def main(): results.add_to_summary(2, "FAIL", "HTTP Blocked") logger.info("Test SSH") - if not test_utils.is_ssh_blocked(srv_prv_ip, client_ip): + if not test_utils.is_ssh_blocked(client_ip, srv_prv_ip): results.add_to_summary(2, "PASS", "SSH works") else: error = ('\033[91mTEST 4 [FAILED] ==> SSH BLOCKED\033[0m') diff --git a/sfc/tests/functest/vnfd-templates/test-vnfd-default-params.yaml b/sfc/tests/functest/vnfd-templates/test-vnfd-default-params.yaml new file mode 100644 index 00000000..5b052e5f --- /dev/null +++ b/sfc/tests/functest/vnfd-templates/test-vnfd-default-params.yaml @@ -0,0 +1 @@ +zone: nova diff --git a/sfc/tests/functest/vnfd-templates/test-vnfd1.yaml b/sfc/tests/functest/vnfd-templates/test-vnfd1.yaml index fd862ea0..79a625fa 100644 --- a/sfc/tests/functest/vnfd-templates/test-vnfd1.yaml +++ b/sfc/tests/functest/vnfd-templates/test-vnfd1.yaml @@ -20,7 +20,7 @@ vdus: management: true placement_policy: - availability_zone: nova + availability_zone: { get_input: zone } auto-scaling: noop monitoring_policy: noop diff --git a/sfc/tests/functest/vnfd-templates/test-vnfd2.yaml b/sfc/tests/functest/vnfd-templates/test-vnfd2.yaml index 5451358d..64f799e4 100644 --- a/sfc/tests/functest/vnfd-templates/test-vnfd2.yaml +++ b/sfc/tests/functest/vnfd-templates/test-vnfd2.yaml @@ -20,7 +20,7 @@ vdus: management: true placement_policy: - availability_zone: nova + availability_zone: { get_input: zone } auto-scaling: noop monitoring_policy: noop diff --git a/sfc/tests/functest/vnfd-templates/test2-vnfd1.yaml b/sfc/tests/functest/vnfd-templates/test2-vnfd1.yaml index 1d8da125..e8e0626b 100644 --- a/sfc/tests/functest/vnfd-templates/test2-vnfd1.yaml +++ b/sfc/tests/functest/vnfd-templates/test2-vnfd1.yaml @@ -22,7 +22,7 @@ vdus: placement_policy: # TODO: This availability zone is changed by the test case on the fly. # See JIRA SFC-73 for more info - availability_zone: nova + availability_zone: { get_input: zone } auto-scaling: noop monitoring_policy: noop diff --git a/sfc/tests/functest/vnfd-templates/test2-vnfd2.yaml b/sfc/tests/functest/vnfd-templates/test2-vnfd2.yaml index 280fc9e5..93a38acb 100644 --- a/sfc/tests/functest/vnfd-templates/test2-vnfd2.yaml +++ b/sfc/tests/functest/vnfd-templates/test2-vnfd2.yaml @@ -22,7 +22,7 @@ vdus: placement_policy: # TODO: This availability zone is changed by the test case on the fly. # See JIRA SFC-73 for more info - availability_zone: nova + availability_zone: { get_input: zone } auto-scaling: noop monitoring_policy: noop |