diff options
Diffstat (limited to 'sfc/lib')
-rw-r--r-- | sfc/lib/utils.py | 56 |
1 files changed, 35 insertions, 21 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): |