aboutsummaryrefslogtreecommitdiffstats
path: root/sfc/tests
diff options
context:
space:
mode:
authorjose.lausuch <jose.lausuch@ericsson.com>2016-12-13 12:31:39 +0100
committerjose.lausuch <jose.lausuch@ericsson.com>2016-12-15 12:37:52 +0100
commitacf339f2840d0fe7a46187a0597704cf5b486214 (patch)
treede114d6482bcd7cfd9d057f756d8b6f8864911cb /sfc/tests
parent1350624dbcf49c27ae0333719c2d7dda86ca7b0e (diff)
Make SFC installable as a python module
New directory structure: <root>/sfc <root>/sfc/lib/ <root>/sfc/tests <root>/sfc/tests/functest JIRA: SFC-60 After installing sfc, the imports would be: import sfc.tests.functest.x import sfc.lib.x Change-Id: Ib15172239aefdef65056d6598210a1b28a4b2eff Signed-off-by: jose.lausuch <jose.lausuch@ericsson.com>
Diffstat (limited to 'sfc/tests')
-rw-r--r--sfc/tests/NAME_tests.py11
-rw-r--r--sfc/tests/__init__.py0
-rw-r--r--sfc/tests/functest/README.sfc-test-211
-rw-r--r--sfc/tests/functest/__init__.py0
-rw-r--r--sfc/tests/functest/config.yaml45
-rw-r--r--sfc/tests/functest/run_tests.py131
-rw-r--r--sfc/tests/functest/setup_scripts/__init__.py0
-rw-r--r--sfc/tests/functest/setup_scripts/compute_presetup_CI.bash27
-rw-r--r--sfc/tests/functest/setup_scripts/delete.sh16
-rw-r--r--sfc/tests/functest/setup_scripts/prepare_odl_sfc.py90
-rw-r--r--sfc/tests/functest/setup_scripts/server_presetup_CI.bash13
-rw-r--r--sfc/tests/functest/setup_scripts/tacker_client_install.sh43
-rw-r--r--sfc/tests/functest/sfc.py270
-rw-r--r--sfc/tests/functest/sfc_one_chain_two_service_functions_different_computes.py271
-rw-r--r--sfc/tests/functest/sfc_tacker_test2.bash29
-rw-r--r--sfc/tests/functest/vnfd-templates/test-vnfd1.yaml31
-rw-r--r--sfc/tests/functest/vnfd-templates/test-vnfd2.yaml31
-rw-r--r--sfc/tests/functest/vnfd-templates/test2-vnfd1.yaml31
-rw-r--r--sfc/tests/functest/vnfd-templates/test2-vnfd2.yaml31
19 files changed, 1081 insertions, 0 deletions
diff --git a/sfc/tests/NAME_tests.py b/sfc/tests/NAME_tests.py
new file mode 100644
index 00000000..e95004bc
--- /dev/null
+++ b/sfc/tests/NAME_tests.py
@@ -0,0 +1,11 @@
+
+def setup():
+ print "SETUP!"
+
+
+def teardown():
+ print "TEAR DOWN!"
+
+
+def test_basic():
+ print "I RAN!"
diff --git a/sfc/tests/__init__.py b/sfc/tests/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/sfc/tests/__init__.py
diff --git a/sfc/tests/functest/README.sfc-test-2 b/sfc/tests/functest/README.sfc-test-2
new file mode 100644
index 00000000..5a9f2ebe
--- /dev/null
+++ b/sfc/tests/functest/README.sfc-test-2
@@ -0,0 +1,11 @@
+### ODL-SFC TEST2 DESCRIPTION ###
+
+This is a simple description of the test case
+
+We create one client and one server using nova. Then, 2 SFs are created using
+tacker. The SFs are deployed in two different compute nodes. A chain is created
+where both SFs are included.
+
+vxlan_tool is started in both SFs and HTTP traffic is sent from the client to
+the server. If it works, the vxlan_tool is modified to block HTTP traffic.
+It is tried again and it should fail because packets are dropped
diff --git a/sfc/tests/functest/__init__.py b/sfc/tests/functest/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/sfc/tests/functest/__init__.py
diff --git a/sfc/tests/functest/config.yaml b/sfc/tests/functest/config.yaml
new file mode 100644
index 00000000..78cf42fb
--- /dev/null
+++ b/sfc/tests/functest/config.yaml
@@ -0,0 +1,45 @@
+defaults:
+ #odl-sfc uses custom flavors as per below params
+ flavor: custom
+ ram_size_in_mb: 1500
+ disk_size_in_gb: 10
+ vcpu_count: 1
+ image_name: sf_nsh_colorado
+ image_file_name: sf_nsh_colorado.qcow2
+ fuel_master_ip: 10.20.0.2
+ fuel_master_uname: root
+ fuel_master_passwd: r00tme
+ image_format: qcow2
+ url: "http://artifacts.opnfv.org/sfc/demo"
+ vnfd-dir: "vnfd-templates"
+
+testcases:
+# this change requires sfc.py to be renamed as sfc_two_chains_SSH_and_HTTP
+# for run_tests.py integration. Rename of sfc.py will be submitted in
+# separate patch for better review clarity and name will be changed back to
+# sfc_two_chains_SSH_and_HTTP once sfc.py is renamed
+ sfc:
+ enabled: true
+ description: "ODL-SFC tests"
+ testname_db: "sfc_two_chains_SSH_and_HTTP"
+ net_name: example-net
+ subnet_name: example-subnet
+ router_name: example-router
+ subnet_cidr: "11.0.0.0/24"
+ secgroup_name: "example-sg"
+ secgroup_descr: "Example Security group"
+ test_vnfd_red: "test-vnfd1.yaml"
+ test_vnfd_blue: "test-vnfd2.yaml"
+
+ sfc_one_chain_two_service_functions_different_computes:
+ enabled: true
+ description: "ODL-SFC Testing SFs in different computes"
+ testname_db: "sfc_one_chain_two_service_functions_different_computes"
+ net_name: example-net
+ subnet_name: example-subnet
+ router_name: example-router
+ subnet_cidr: "11.0.0.0/24"
+ secgroup_name: "example-sg"
+ secgroup_descr: "Example Security group"
+ test_vnfd_red: "test2-vnfd1.yaml"
+ test_vnfd_blue: "test2-vnfd2.yaml"
diff --git a/sfc/tests/functest/run_tests.py b/sfc/tests/functest/run_tests.py
new file mode 100644
index 00000000..e66e4c11
--- /dev/null
+++ b/sfc/tests/functest/run_tests.py
@@ -0,0 +1,131 @@
+#!/bin/python
+#
+# Copyright (c) 2015 All rights reserved
+# This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+
+import argparse
+import config as sfc_config
+import importlib
+import os
+import sys
+import time
+import yaml
+
+import functest.utils.functest_logger as ft_logger
+import functest.utils.functest_utils as ft_utils
+import opnfv.utils.ovs_logger as ovs_log
+import opnfv.utils.SSHUtils as ssh_utils
+import sfc.lib.utils as utils
+
+
+parser = argparse.ArgumentParser()
+parser.add_argument("-r", "--report",
+ help="Create json result file",
+ action="store_true")
+args = parser.parse_args()
+
+logger = ft_logger.Logger("sfc-run-tests").getLogger()
+COMMON_CONFIG = sfc_config.CommonConfig()
+
+
+def push_results(testname, start_time, end_time, criteria, details):
+ logger.info("Push testcase '%s' results into the DB...\n" % testname)
+ ft_utils.push_results_to_db("sfc",
+ testname,
+ start_time,
+ end_time,
+ criteria,
+ details)
+
+
+def get_tackerc_file():
+ rc_file = os.path.join(COMMON_CONFIG.sfc_test_dir, 'tackerc')
+ if not os.path.exists(rc_file):
+ logger.info("tackerc file not found, getting it from controller")
+ ip = utils.get_openstack_node_ips("controller")
+ ssh_conn = ssh_utils.get_ssh_client(ip[0], 'root',
+ proxy=COMMON_CONFIG.fuel_proxy)
+ ssh_utils.get_file(ssh_conn, "tackerc", rc_file)
+ else:
+ logger.info("found tackerc file")
+
+ return rc_file
+
+
+def set_tacker_rc_file_env():
+ rc_file = get_tackerc_file()
+ with open(rc_file) as f:
+ for line in f.readlines():
+ if not (line.startswith('#') or len(line) == 1):
+ filtered = line.strip().split(' ')
+ kv = filtered[1].split('=')
+ logger.info("Set shell env %s=%s" % (kv[0], kv[1]))
+ os.environ[kv[0]] = kv[1].strip("'")
+
+
+def main():
+ set_tacker_rc_file_env()
+ ovs_logger = ovs_log.OVSLogger(
+ os.path.join(COMMON_CONFIG.sfc_test_dir, 'ovs-logs'),
+ COMMON_CONFIG.functest_results_dir)
+
+ config_file = os.path.join(COMMON_CONFIG.config_file)
+ with open(config_file) as f:
+ config_yaml = yaml.safe_load(f)
+
+ testcases = config_yaml.get("testcases")
+ overall_details = {}
+ overall_status = "FAIL"
+ overall_start_time = time.time()
+ for testcase in testcases:
+ if testcases[testcase]['enabled']:
+ test_name = testcase
+ test_descr = testcases[testcase]['description']
+ test_name_db = testcases[testcase]['testname_db']
+ title = ("Running '%s - %s'" %
+ (test_name, test_descr))
+ logger.info(title)
+ logger.info("%s\n" % ("=" * len(title)))
+ t = importlib.import_module(testcase, package=None)
+ start_time = time.time()
+ result = t.main()
+ end_time = time.time()
+ duration = end_time - start_time
+ status = "FAIL"
+ if result != 0:
+ overall_details.update({test_name_db: "execution error."})
+ else:
+ status = result.get("status")
+ if status == "FAIL":
+ overall_status = "FAIL"
+ ovs_logger.create_artifact_archive()
+
+ logger.info("Results of test case '%s - %s':\n%s\n" %
+ (test_name, test_descr, result))
+
+ dic = {"duration": duration, "status": overall_status}
+ overall_details.update({test_name_db: dic})
+ if args.report:
+ details = result.get("details")
+ push_results(
+ test_name_db, start_time, end_time, status, details)
+
+ overall_end_time = time.time()
+ if args.report:
+ push_results(
+ "odl-sfc", overall_start_time, overall_end_time,
+ overall_status, overall_details)
+
+ if overall_status == "FAIL":
+ sys.exit(-1)
+
+ sys.exit(0)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/sfc/tests/functest/setup_scripts/__init__.py b/sfc/tests/functest/setup_scripts/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/sfc/tests/functest/setup_scripts/__init__.py
diff --git a/sfc/tests/functest/setup_scripts/compute_presetup_CI.bash b/sfc/tests/functest/setup_scripts/compute_presetup_CI.bash
new file mode 100644
index 00000000..36148aa1
--- /dev/null
+++ b/sfc/tests/functest/setup_scripts/compute_presetup_CI.bash
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+# This script must be use with vxlan-gpe + nsh. Once we have eth + nsh support
+# in ODL, we will not need it anymore
+
+set -e
+ssh_options='-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
+BASEDIR=`dirname $0`
+INSTALLER_IP=${INSTALLER_IP:-10.20.0.2}
+
+pushd $BASEDIR
+#ip=`sshpass -p r00tme ssh $ssh_options root@${INSTALLER_IP} 'fuel node'|grep compute|\
+#awk '{print $10}' | head -1`
+
+ip=$1
+echo $ip
+#sshpass -p r00tme scp $ssh_options correct_classifier.bash ${INSTALLER_IP}:/root
+#sshpass -p r00tme ssh $ssh_options root@${INSTALLER_IP} 'scp correct_classifier.bash '"$ip"':/root'
+
+sshpass -p r00tme ssh $ssh_options root@${INSTALLER_IP} 'ssh root@'"$ip"' ifconfig br-int up'
+output=$(sshpass -p r00tme ssh $ssh_options root@${INSTALLER_IP} 'ssh root@'"$ip"' ip route | \
+cut -d" " -f1 | grep 11.0.0.0' ; exit 0)
+
+if [ -z "$output" ]; then
+sshpass -p r00tme ssh $ssh_options root@${INSTALLER_IP} 'ssh root@'"$ip"' ip route add 11.0.0.0/24 \
+dev br-int'
+fi
diff --git a/sfc/tests/functest/setup_scripts/delete.sh b/sfc/tests/functest/setup_scripts/delete.sh
new file mode 100644
index 00000000..2c9de04b
--- /dev/null
+++ b/sfc/tests/functest/setup_scripts/delete.sh
@@ -0,0 +1,16 @@
+source ${repos_dir}/sfc/sfc/tests/functest/tackerc
+tacker sfc-classifier-delete red_http
+tacker sfc-classifier-delete blue_ssh
+tacker sfc-classifier-delete red_ssh
+tacker sfc-classifier-delete blue_http
+tacker sfc-delete red
+tacker sfc-delete blue
+tacker vnf-delete testVNF1
+tacker vnf-delete testVNF2
+tacker vnfd-delete test-vnfd1
+tacker vnfd-delete test-vnfd2
+openstack stack delete sfc --y
+openstack stack delete sfc_test1 --y
+openstack stack delete sfc_test2 --y
+nova delete client
+nova delete server
diff --git a/sfc/tests/functest/setup_scripts/prepare_odl_sfc.py b/sfc/tests/functest/setup_scripts/prepare_odl_sfc.py
new file mode 100644
index 00000000..280977bf
--- /dev/null
+++ b/sfc/tests/functest/setup_scripts/prepare_odl_sfc.py
@@ -0,0 +1,90 @@
+#
+# Author: George Paraskevopoulos (geopar@intracom-telecom.com)
+# Manuel Buil (manuel.buil@ericsson.com)
+# Prepares the controller and the compute nodes for the odl-sfc testcase
+#
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+
+import os
+import sys
+import subprocess
+import paramiko
+import functest.utils.functest_logger as ft_logger
+
+logger = ft_logger.Logger("ODL_SFC").getLogger()
+
+SFC_REPO_DIR = "/home/opnfv/repos/sfc"
+
+try:
+ INSTALLER_IP = os.environ['INSTALLER_IP']
+except:
+ logger.debug("INSTALLER_IP does not exist. We create 10.20.0.2")
+ INSTALLER_IP = "10.20.0.2"
+
+os.environ['ODL_SFC_LOG'] = "/home/opnfv/functest/results/sfc.log"
+os.environ['ODL_SFC_DIR'] = os.path.join(SFC_REPO_DIR,
+ "sfc/tests/functest")
+SETUP_SCRIPTS_DIR = os.path.join(os.environ['ODL_SFC_DIR'], 'setup_scripts')
+
+command = SETUP_SCRIPTS_DIR + ("/server_presetup_CI.bash | "
+ "tee -a ${ODL_SFC_LOG} 1>/dev/null 2>&1")
+
+output = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
+
+# This code is for debugging purposes
+# for line in iter(output.stdout.readline, ''):
+# i = line.rstrip()
+# print(i)
+
+# Make sure the process is finished before checking the returncode
+if not output.poll():
+ output.wait()
+
+# Get return value
+if output.returncode:
+ print("The presetup of the server did not work")
+ sys.exit(output.returncode)
+
+logger.info("The presetup of the server worked ")
+
+ssh_options = "-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
+ssh = paramiko.SSHClient()
+ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
+
+try:
+ ssh.connect(INSTALLER_IP, username="root",
+ password="r00tme", timeout=2)
+ command = "fuel node | grep compute | awk '{print $10}'"
+ logger.info("Executing ssh to collect the compute IPs")
+ (stdin, stdout, stderr) = ssh.exec_command(command)
+except:
+ logger.debug("Something went wrong in the ssh to collect the computes IP")
+
+output = stdout.readlines()
+for ip in output:
+ command = SETUP_SCRIPTS_DIR + ("/compute_presetup_CI.bash " + ip.rstrip() +
+ "| tee -a ${ODL_SFC_LOG} 1>/dev/null 2>&1")
+
+ output = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
+
+# This code is for debugging purposes
+# for line in iter(output.stdout.readline, ''):
+# print(line)
+# sys.stdout.flush()
+
+ output.stdout.close()
+
+ if not (output.poll()):
+ output.wait()
+
+ # Get return value
+ if output.returncode:
+ print("The compute config did not work on compute %s" % ip)
+ sys.exit(output.returncode)
+
+sys.exit(0)
diff --git a/sfc/tests/functest/setup_scripts/server_presetup_CI.bash b/sfc/tests/functest/setup_scripts/server_presetup_CI.bash
new file mode 100644
index 00000000..240353f5
--- /dev/null
+++ b/sfc/tests/functest/setup_scripts/server_presetup_CI.bash
@@ -0,0 +1,13 @@
+#!/bin/bash
+set -e
+ssh_options='-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
+BASEDIR=`dirname $0`
+INSTALLER_IP=${INSTALLER_IP:-10.20.0.2}
+
+pushd $BASEDIR
+ip=$(sshpass -p r00tme ssh $ssh_options root@${INSTALLER_IP} 'fuel node'|grep controller|awk '{print $10}' | head -1)
+echo $ip
+
+sshpass -p r00tme scp $ssh_options delete.sh ${INSTALLER_IP}:/root
+sshpass -p r00tme ssh $ssh_options root@${INSTALLER_IP} 'scp '"$ip"':/root/tackerc .'
+sshpass -p r00tme scp $ssh_options ${INSTALLER_IP}:/root/tackerc $BASEDIR
diff --git a/sfc/tests/functest/setup_scripts/tacker_client_install.sh b/sfc/tests/functest/setup_scripts/tacker_client_install.sh
new file mode 100644
index 00000000..adb9a44b
--- /dev/null
+++ b/sfc/tests/functest/setup_scripts/tacker_client_install.sh
@@ -0,0 +1,43 @@
+MYDIR=$(dirname $(readlink -f "$0"))
+CLIENT=$(echo python-python-tackerclient_*_all.deb)
+CLIREPO="tacker-client"
+
+# Function checks whether a python egg is available, if not, installs
+function chkPPkg() {
+ PKG="$1"
+ IPPACK=$(python - <<'____EOF'
+import pip
+from os.path import join
+for package in pip.get_installed_distributions():
+ print(package.location)
+ print(join(package.location, *package._get_metadata("top_level.txt")))
+____EOF
+)
+ echo "$IPPACK" | grep -q "$PKG"
+ if [ $? -ne 0 ];then
+ pip install "$PKG"
+ fi
+}
+
+function envSetup() {
+ apt-get install -y python-all debhelper fakeroot
+ #pip install --upgrade python-keystoneclient==1.7.4
+ chkPPkg stdeb
+}
+
+# Function installs python-tackerclient from github
+function deployTackerClient() {
+ cd $MYDIR
+ git clone -b 'SFC_refactor' https://github.com/trozet/python-tackerclient.git $CLIREPO
+ cd $CLIREPO
+ python setup.py --command-packages=stdeb.command bdist_deb
+ cd "deb_dist"
+ CLIENT=$(echo python-python-tackerclient_*_all.deb)
+ cp $CLIENT $MYDIR
+ dpkg -i "${MYDIR}/${CLIENT}"
+ apt-get -f -y install
+ dpkg -i "${MYDIR}/${CLIENT}"
+}
+
+envSetup
+deployTackerClient
diff --git a/sfc/tests/functest/sfc.py b/sfc/tests/functest/sfc.py
new file mode 100644
index 00000000..45fb9b0f
--- /dev/null
+++ b/sfc/tests/functest/sfc.py
@@ -0,0 +1,270 @@
+#!/bin/python
+#
+# Copyright (c) 2015 All rights reserved
+# This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+
+import argparse
+import os
+import sys
+import threading
+
+import functest.utils.functest_logger as ft_logger
+import functest.utils.openstack_utils as os_utils
+import functest.utils.openstack_tacker as os_tacker
+import opnfv.utils.ovs_logger as ovs_log
+import sfc.lib.utils as test_utils
+import sfc.lib.config as sfc_config
+from sfc.lib.results import Results
+
+
+parser = argparse.ArgumentParser()
+
+parser.add_argument("-r", "--report",
+ help="Create json result file",
+ action="store_true")
+
+args = parser.parse_args()
+
+""" logging configuration """
+logger = ft_logger.Logger("ODL_SFC").getLogger()
+
+CLIENT = "client"
+SERVER = "server"
+COMMON_CONFIG = sfc_config.CommonConfig()
+# TestcaseConfig sfc name will be changed once
+# we rename sfc.py with appropriate name
+TESTCASE_CONFIG = sfc_config.TestcaseConfig('sfc')
+
+
+def main():
+ results = Results(COMMON_CONFIG.line_length)
+ results.add_to_summary(0, "=")
+ results.add_to_summary(2, "STATUS", "SUBTEST")
+ results.add_to_summary(0, "=")
+
+ installer_type = os.environ.get("INSTALLER_TYPE")
+ if installer_type != "fuel":
+ logger.error(
+ '\033[91mCurrently supported only Fuel Installer type\033[0m')
+ sys.exit(1)
+
+ installer_ip = os.environ.get("INSTALLER_IP")
+ if not installer_ip:
+ logger.error(
+ '\033[91minstaller ip is not set\033[0m')
+ logger.error(
+ '\033[91mexport INSTALLER_IP=<ip>\033[0m')
+ sys.exit(1)
+
+ test_utils.setup_compute_node(TESTCASE_CONFIG.subnet_cidr)
+ test_utils.configure_iptables()
+ test_utils.download_image(COMMON_CONFIG.url,
+ COMMON_CONFIG.image_path)
+ _, custom_flv_id = os_utils.get_or_create_flavor(
+ COMMON_CONFIG.flavor,
+ COMMON_CONFIG.ram_size_in_mb,
+ COMMON_CONFIG.disk_size_in_gb,
+ COMMON_CONFIG.vcpu_count, public=True)
+ if not custom_flv_id:
+ logger.error("Failed to create custom flavor")
+ sys.exit(1)
+
+ glance_client = os_utils.get_glance_client()
+ neutron_client = os_utils.get_neutron_client()
+ nova_client = os_utils.get_nova_client()
+ tacker_client = os_tacker.get_tacker_client()
+
+ controller_clients = test_utils.get_ssh_clients("controller",
+ COMMON_CONFIG.fuel_proxy)
+ compute_clients = test_utils.get_ssh_clients("compute",
+ COMMON_CONFIG.fuel_proxy)
+
+ ovs_logger = ovs_log.OVSLogger(
+ os.path.join(COMMON_CONFIG.sfc_test_dir, 'ovs-logs'),
+ COMMON_CONFIG.functest_results_dir)
+
+ image_id = os_utils.create_glance_image(glance_client,
+ COMMON_CONFIG.image_name,
+ COMMON_CONFIG.image_path,
+ COMMON_CONFIG.image_format,
+ public=True)
+
+ network_id = test_utils.setup_neutron(neutron_client,
+ TESTCASE_CONFIG.net_name,
+ TESTCASE_CONFIG.subnet_name,
+ TESTCASE_CONFIG.router_name,
+ TESTCASE_CONFIG.subnet_cidr)
+
+ sg_id = test_utils.create_security_groups(neutron_client,
+ TESTCASE_CONFIG.secgroup_name,
+ TESTCASE_CONFIG.secgroup_descr)
+
+ test_utils.create_instance(
+ nova_client, CLIENT, COMMON_CONFIG.flavor, image_id,
+ network_id, sg_id)
+ srv_instance = test_utils.create_instance(
+ nova_client, SERVER, COMMON_CONFIG.flavor, image_id,
+ network_id, sg_id)
+
+ srv_prv_ip = srv_instance.networks.get(TESTCASE_CONFIG.net_name)[0]
+
+ tosca_file = os.path.join(COMMON_CONFIG.sfc_test_dir,
+ COMMON_CONFIG.vnfd_dir,
+ TESTCASE_CONFIG.test_vnfd_red)
+ os_tacker.create_vnfd(
+ tacker_client,
+ tosca_file=tosca_file)
+
+ tosca_file = os.path.join(COMMON_CONFIG.sfc_test_dir,
+ COMMON_CONFIG.vnfd_dir,
+ TESTCASE_CONFIG.test_vnfd_blue)
+ os_tacker.create_vnfd(
+ 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')
+
+ try:
+ os_tacker.wait_for_vnf(tacker_client, vnf_name='testVNF1')
+ os_tacker.wait_for_vnf(tacker_client, vnf_name='testVNF2')
+ except:
+ logger.error('ERROR while booting vnfs')
+ sys.exit(1)
+
+ os_tacker.create_sfc(tacker_client, 'red', chain_vnf_names=['testVNF1'])
+ os_tacker.create_sfc(tacker_client, 'blue', chain_vnf_names=['testVNF2'])
+
+ os_tacker.create_sfc_classifier(
+ tacker_client, 'red_http', sfc_name='red',
+ match={
+ 'source_port': 0,
+ 'dest_port': 80,
+ 'protocol': 6
+ })
+
+ os_tacker.create_sfc_classifier(
+ tacker_client, 'red_ssh', sfc_name='red',
+ match={
+ 'source_port': 0,
+ 'dest_port': 22,
+ 'protocol': 6
+ })
+
+ logger.info(test_utils.run_cmd('tacker sfc-list'))
+ logger.info(test_utils.run_cmd('tacker sfc-classifier-list'))
+
+ # Start measuring the time it takes to implement the classification rules
+ t1 = threading.Thread(target=test_utils.capture_time_log,
+ args=(ovs_logger, compute_clients,))
+ try:
+ t1.start()
+ 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.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)
+ sys.exit(1)
+
+ logger.info("Starting HTTP firewall on %s" % sf2)
+ test_utils.vxlan_firewall(sf2, port="80")
+ logger.info("Starting SSH firewall on %s" % sf1)
+ test_utils.vxlan_firewall(sf1, port="22")
+
+ logger.info("Wait for ODL to update the classification rules in OVS")
+ t1.join()
+
+ logger.info("Test SSH")
+ if test_utils.is_ssh_blocked(srv_prv_ip, client_ip):
+ results.add_to_summary(2, "PASS", "SSH Blocked")
+ else:
+ error = ('\033[91mTEST 1 [FAILED] ==> SSH NOT BLOCKED\033[0m')
+ logger.error(error)
+ test_utils.capture_err_logs(
+ ovs_logger, controller_clients, compute_clients, error)
+ results.add_to_summary(2, "FAIL", "SSH Blocked")
+
+ logger.info("Test HTTP")
+ if not test_utils.is_http_blocked(srv_prv_ip, client_ip):
+ results.add_to_summary(2, "PASS", "HTTP works")
+ else:
+ error = ('\033[91mTEST 2 [FAILED] ==> HTTP BLOCKED\033[0m')
+ logger.error(error)
+ test_utils.capture_err_logs(
+ ovs_logger, controller_clients, compute_clients, error)
+ results.add_to_summary(2, "FAIL", "HTTP works")
+
+ logger.info("Changing the classification")
+ os_tacker.delete_sfc_classifier(tacker_client, sfc_clf_name='red_http')
+ os_tacker.delete_sfc_classifier(tacker_client, sfc_clf_name='red_ssh')
+
+ os_tacker.create_sfc_classifier(
+ tacker_client, 'blue_http', sfc_name='blue',
+ match={
+ 'source_port': 0,
+ 'dest_port': 80,
+ 'protocol': 6
+ })
+
+ os_tacker.create_sfc_classifier(
+ tacker_client, 'blue_ssh', sfc_name='blue',
+ match={
+ 'source_port': 0,
+ 'dest_port': 22,
+ 'protocol': 6
+ })
+
+ logger.info(test_utils.run_cmd('tacker sfc-classifier-list'))
+
+ # Start measuring the time it takes to implement the classification rules
+ t2 = threading.Thread(target=test_utils.capture_time_log,
+ args=(ovs_logger, compute_clients,))
+ try:
+ t2.start()
+ except Exception, e:
+ logger.error("Unable to start the thread that counts time %s" % e)
+
+ logger.info("Wait for ODL to update the classification rules in OVS")
+ t2.join()
+
+ logger.info("Test HTTP")
+ if test_utils.is_http_blocked(srv_prv_ip, client_ip):
+ results.add_to_summary(2, "PASS", "HTTP Blocked")
+ else:
+ error = ('\033[91mTEST 3 [FAILED] ==> HTTP WORKS\033[0m')
+ logger.error(error)
+ test_utils.capture_err_logs(
+ ovs_logger, controller_clients, compute_clients, error)
+ results.add_to_summary(2, "FAIL", "HTTP Blocked")
+
+ logger.info("Test SSH")
+ if not test_utils.is_ssh_blocked(srv_prv_ip, client_ip):
+ results.add_to_summary(2, "PASS", "SSH works")
+ else:
+ error = ('\033[91mTEST 4 [FAILED] ==> SSH BLOCKED\033[0m')
+ logger.error(error)
+ test_utils.capture_err_logs(
+ ovs_logger, controller_clients, compute_clients, error)
+ results.add_to_summary(2, "FAIL", "SSH works")
+
+ return results.compile_summary()
+
+
+if __name__ == '__main__':
+ main()
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
new file mode 100644
index 00000000..f901a041
--- /dev/null
+++ b/sfc/tests/functest/sfc_one_chain_two_service_functions_different_computes.py
@@ -0,0 +1,271 @@
+#!/bin/python
+#
+# Copyright (c) 2015 All rights reserved
+# This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+
+import argparse
+import os
+import re
+import sys
+import time
+
+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
+import opnfv.utils.ovs_logger as ovs_log
+import sfc.lib.utils as test_utils
+import sfc.lib.config as sfc_config
+
+
+parser = argparse.ArgumentParser()
+
+parser.add_argument("-r", "--report",
+ help="Create json result file",
+ action="store_true")
+
+args = parser.parse_args()
+
+""" logging configuration """
+logger = ft_logger.Logger("ODL_SFC").getLogger()
+
+REPO_PATH = os.path.join(os.environ['REPOS_DIR'], 'sfc/')
+SFC_TEST_DIR = os.path.join(REPO_PATH, "sfc/tests/functest")
+TACKER_SCRIPT = os.path.join(SFC_TEST_DIR, "sfc_tacker_test2.bash")
+TACKER_VNFD1 = os.path.join(SFC_TEST_DIR, "vnfd-templates", "test2-vnfd1.yaml")
+TACKER_VNFD2 = os.path.join(SFC_TEST_DIR, "vnfd-templates", "test2-vnfd2.yaml")
+CLIENT = "client"
+SERVER = "server"
+ssh_options = '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
+json_results = {"tests": 4, "failures": 0}
+COMMON_CONFIG = sfc_config.CommonConfig()
+TESTCASE_CONFIG = sfc_config.TestcaseConfig('sfc_one_chain_two_service'
+ '_functions_different_computes')
+
+PROXY = {
+ 'ip': COMMON_CONFIG.fuel_master_ip,
+ 'username': COMMON_CONFIG.fuel_master_uname,
+ 'password': COMMON_CONFIG.fuel_master_passwd
+}
+
+
+def update_json_results(name, result):
+ json_results.update({name: result})
+ if result is not "Passed":
+ json_results["failures"] += 1
+ return
+
+
+# JIRA: SFC-52 new function
+def setup_availability_zones(nova_client):
+ computes = os_utils.get_hypervisors(nova_client)
+ az = ["nova::" + computes[0], "nova::" + computes[1]]
+ logger.debug("These are the availability zones %s" % az)
+ 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":
+ logger.error(
+ '\033[91mCurrently supported only Fuel Installer type\033[0m')
+ sys.exit(1)
+
+ installer_ip = os.environ.get("INSTALLER_IP")
+ if not installer_ip:
+ logger.error(
+ '\033[91minstaller ip is not set\033[0m')
+ logger.error(
+ '\033[91mexport INSTALLER_IP=<ip>\033[0m')
+ sys.exit(1)
+
+ start_time = time.time()
+ status = "PASS"
+ test_utils.configure_iptables()
+ test_utils.download_image(COMMON_CONFIG.url,
+ COMMON_CONFIG.image_path)
+ _, custom_flv_id = os_utils.get_or_create_flavor(
+ COMMON_CONFIG.flavor, 1500, 10, 1, public=True)
+ if not custom_flv_id:
+ logger.error("Failed to create custom flavor")
+ sys.exit(1)
+
+ glance_client = os_utils.get_glance_client()
+ neutron_client = os_utils.get_neutron_client()
+ nova_client = os_utils.get_nova_client()
+ tacker_client = os_tacker.get_tacker_client()
+
+ controller_clients = test_utils.get_ssh_clients("controller", PROXY)
+ compute_clients = test_utils.get_ssh_clients("compute", PROXY)
+
+ ovs_logger = ovs_log.OVSLogger(
+ os.path.join(COMMON_CONFIG.sfc_test_dir, 'ovs-logs'),
+ COMMON_CONFIG.functest_results_dir)
+
+ image_id = os_utils.create_glance_image(glance_client,
+ COMMON_CONFIG.image_name,
+ COMMON_CONFIG.image_path,
+ COMMON_CONFIG.image_format,
+ public=True)
+
+ network_id = test_utils.setup_neutron(neutron_client,
+ TESTCASE_CONFIG.net_name,
+ TESTCASE_CONFIG.subnet_name,
+ TESTCASE_CONFIG.router_name,
+ TESTCASE_CONFIG.subnet_cidr)
+
+ sg_id = test_utils.create_security_groups(neutron_client,
+ TESTCASE_CONFIG.secgroup_name,
+ TESTCASE_CONFIG.secgroup_descr)
+
+ prepare_tacker_vnfd(nova_client)
+
+ test_utils.create_instance(
+ nova_client, CLIENT, COMMON_CONFIG.flavor,
+ image_id, network_id, sg_id)
+
+ srv_instance = test_utils.create_instance(
+ nova_client, SERVER, COMMON_CONFIG.flavor, image_id,
+ network_id, sg_id)
+
+ srv_prv_ip = srv_instance.networks.get(TESTCASE_CONFIG.net_name)[0]
+
+ tosca_file = os.path.join(COMMON_CONFIG.sfc_test_dir,
+ COMMON_CONFIG.vnfd_dir,
+ TESTCASE_CONFIG.test_vnfd_red)
+
+ os_tacker.create_vnfd(
+ tacker_client,
+ tosca_file=tosca_file)
+
+ tosca_file = os.path.join(COMMON_CONFIG.sfc_test_dir,
+ COMMON_CONFIG.vnfd_dir,
+ TESTCASE_CONFIG.test_vnfd_blue)
+ os_tacker.create_vnfd(
+ 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')
+
+ try:
+ os_tacker.wait_for_vnf(tacker_client, vnf_name='testVNF1')
+ os_tacker.wait_for_vnf(tacker_client, vnf_name='testVNF2')
+ except:
+ logger.error('ERROR while booting vnfs')
+ sys.exit(1)
+
+ os_tacker.create_sfc(tacker_client, 'red',
+ chain_vnf_names=['testVNF1', 'testVNF2'])
+
+ os_tacker.create_sfc_classifier(
+ tacker_client, 'red_http', sfc_name='red',
+ match={
+ 'source_port': 0,
+ 'dest_port': 80,
+ 'protocol': 6
+ })
+
+ logger.info(test_utils.run_cmd('tacker sfc-list'))
+ logger.info(test_utils.run_cmd('tacker sfc-classifier-list'))
+
+ server_ip, client_ip, sf1, sf2 = test_utils.get_floating_ips(
+ nova_client, neutron_client)
+
+ if not test_utils.check_ssh([sf1, sf2]):
+ 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)
+ sys.exit(1)
+
+ logger.info("Starting vxlan_tool on %s" % sf2)
+ test_utils.vxlan_firewall(sf2, block=False)
+ logger.info("Starting vxlan_tool on %s" % sf1)
+ test_utils.vxlan_firewall(sf1, block=False)
+
+ logger.info("Wait for ODL to update the classification rules in OVS")
+ time.sleep(100)
+
+ logger.info("Test HTTP")
+ if not test_utils.is_http_blocked(srv_prv_ip, client_ip):
+ logger.info('\033[92mTEST 1 [PASSED] ==> HTTP WORKS\033[0m')
+ update_json_results("Test 1: HTTP works", "Passed")
+ else:
+ error = ('\033[91mTEST 1 [FAILED] ==> HTTP BLOCKED\033[0m')
+ logger.error(error)
+ test_utils.capture_err_logs(
+ ovs_logger, controller_clients, compute_clients, error)
+ update_json_results("Test 1: HTTP works", "Failed")
+
+ logger.info("Changing the vxlan_tool to block HTTP traffic")
+
+ # Make SF1 block now http traffic
+ test_utils.vxlan_tool_stop(sf1)
+ test_utils.vxlan_firewall(sf1, port="80")
+
+ logger.info("Test HTTP again")
+ if test_utils.is_http_blocked(srv_prv_ip, client_ip):
+ logger.info('\033[92mTEST 2 [PASSED] ==> HTTP Blocked\033[0m')
+ update_json_results("Test 2: HTTP Blocked", "Passed")
+ else:
+ error = ('\033[91mTEST 2 [FAILED] ==> HTTP WORKS\033[0m')
+ logger.error(error)
+ test_utils.capture_err_logs(
+ ovs_logger, controller_clients, compute_clients, error)
+ update_json_results("Test 2: HTTP Blocked", "Failed")
+
+ if json_results["failures"]:
+ status = "FAIL"
+ logger.error('\033[91mSFC TESTS: %s :( FOUND %s FAIL \033[0m' % (
+ status, json_results["failures"]))
+
+ if args.report:
+ stop_time = time.time()
+ logger.debug("Promise Results json: " + str(json_results))
+ ft_utils.push_results_to_db("sfc",
+ "sfc_one_chain_two_service_functions"
+ "_different_computes",
+ start_time,
+ stop_time,
+ status,
+ json_results)
+
+ if status == "PASS":
+ logger.info('\033[92mSFC ALL TESTS: %s :)\033[0m' % status)
+ sys.exit(0)
+
+ sys.exit(1)
+
+if __name__ == '__main__':
+ main()
diff --git a/sfc/tests/functest/sfc_tacker_test2.bash b/sfc/tests/functest/sfc_tacker_test2.bash
new file mode 100644
index 00000000..156b19cb
--- /dev/null
+++ b/sfc/tests/functest/sfc_tacker_test2.bash
@@ -0,0 +1,29 @@
+#!/bin/bash
+BASEDIR=`dirname $0`
+
+#import VNF descriptor
+tacker vnfd-create --vnfd-file ${BASEDIR}/vnfd-templates/test2-vnfd1.yaml
+tacker vnfd-create --vnfd-file ${BASEDIR}/vnfd-templates/test2-vnfd2.yaml
+
+#create instances of the imported VNF
+tacker vnf-create --name testVNF1 --vnfd-name test-vnfd1
+tacker vnf-create --name testVNF2 --vnfd-name test-vnfd2
+
+key=true
+while $key;do
+ sleep 3
+ active=`tacker vnf-list | grep -E 'PENDING|ERROR'`
+ echo -e "checking if SFs are up: $active"
+ if [ -z "$active" ]; then
+ key=false
+ fi
+done
+
+#create service chain
+tacker sfc-create --name red --chain testVNF1,testVNF2
+
+#create classifier
+tacker sfc-classifier-create --name red_http --chain red --match source_port=0,dest_port=80,protocol=6
+
+tacker sfc-list
+tacker sfc-classifier-list
diff --git a/sfc/tests/functest/vnfd-templates/test-vnfd1.yaml b/sfc/tests/functest/vnfd-templates/test-vnfd1.yaml
new file mode 100644
index 00000000..5c672e38
--- /dev/null
+++ b/sfc/tests/functest/vnfd-templates/test-vnfd1.yaml
@@ -0,0 +1,31 @@
+template_name: test-vnfd1
+description: firewall1-example
+
+service_properties:
+ Id: firewall1-vnfd
+ vendor: tacker
+ version: 1
+ type:
+ - firewall1
+vdus:
+ vdu1:
+ id: vdu1
+ vm_image: sf_nsh_colorado
+ instance_type: custom
+ service_type: firewall1
+
+ network_interfaces:
+ management:
+ network: example-net
+ management: true
+
+ placement_policy:
+ availability_zone: nova
+
+ auto-scaling: noop
+ monitoring_policy: noop
+ failure_policy: respawn
+
+ config:
+ param0: key0
+ param1: key1
diff --git a/sfc/tests/functest/vnfd-templates/test-vnfd2.yaml b/sfc/tests/functest/vnfd-templates/test-vnfd2.yaml
new file mode 100644
index 00000000..8a570ab9
--- /dev/null
+++ b/sfc/tests/functest/vnfd-templates/test-vnfd2.yaml
@@ -0,0 +1,31 @@
+template_name: test-vnfd2
+description: firewall2-example
+
+service_properties:
+ Id: firewall2-vnfd
+ vendor: tacker
+ version: 1
+ type:
+ - firewall2
+vdus:
+ vdu1:
+ id: vdu1
+ vm_image: sf_nsh_colorado
+ instance_type: custom
+ service_type: firewall2
+
+ network_interfaces:
+ management:
+ network: example-net
+ management: true
+
+ placement_policy:
+ availability_zone: nova
+
+ auto-scaling: noop
+ monitoring_policy: noop
+ failure_policy: respawn
+
+ config:
+ param0: key0
+ param1: key1
diff --git a/sfc/tests/functest/vnfd-templates/test2-vnfd1.yaml b/sfc/tests/functest/vnfd-templates/test2-vnfd1.yaml
new file mode 100644
index 00000000..5c672e38
--- /dev/null
+++ b/sfc/tests/functest/vnfd-templates/test2-vnfd1.yaml
@@ -0,0 +1,31 @@
+template_name: test-vnfd1
+description: firewall1-example
+
+service_properties:
+ Id: firewall1-vnfd
+ vendor: tacker
+ version: 1
+ type:
+ - firewall1
+vdus:
+ vdu1:
+ id: vdu1
+ vm_image: sf_nsh_colorado
+ instance_type: custom
+ service_type: firewall1
+
+ network_interfaces:
+ management:
+ network: example-net
+ management: true
+
+ placement_policy:
+ availability_zone: nova
+
+ auto-scaling: noop
+ monitoring_policy: noop
+ failure_policy: respawn
+
+ config:
+ param0: key0
+ param1: key1
diff --git a/sfc/tests/functest/vnfd-templates/test2-vnfd2.yaml b/sfc/tests/functest/vnfd-templates/test2-vnfd2.yaml
new file mode 100644
index 00000000..8a570ab9
--- /dev/null
+++ b/sfc/tests/functest/vnfd-templates/test2-vnfd2.yaml
@@ -0,0 +1,31 @@
+template_name: test-vnfd2
+description: firewall2-example
+
+service_properties:
+ Id: firewall2-vnfd
+ vendor: tacker
+ version: 1
+ type:
+ - firewall2
+vdus:
+ vdu1:
+ id: vdu1
+ vm_image: sf_nsh_colorado
+ instance_type: custom
+ service_type: firewall2
+
+ network_interfaces:
+ management:
+ network: example-net
+ management: true
+
+ placement_policy:
+ availability_zone: nova
+
+ auto-scaling: noop
+ monitoring_policy: noop
+ failure_policy: respawn
+
+ config:
+ param0: key0
+ param1: key1