aboutsummaryrefslogtreecommitdiffstats
path: root/sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py
diff options
context:
space:
mode:
authorGeorge Paraskevopoulos <geopar@intracom-telecom.com>2017-02-01 15:51:10 +0200
committerGeorge Paraskevopoulos <geopar@intracom-telecom.com>2017-02-01 16:28:43 +0200
commit58c118253a081f19a8a14a0a16895b04c6b8f222 (patch)
treef8c8367368a4909112c5ea26eeab7dfd215dab5f /sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py
parenta4f17c371efa443c190950337eefddd475558621 (diff)
Rename sfc.py
Rename sfc.py to sfc_two_chains_SSH_and_HTTP.py. Renaming the testcase is a functional requirement as well because otherwise it aliases sfc module inside sfc/sfc/tests/ directory Change-Id: Id505c22a8f278260aee8f76254b0e10f5ed7213a Signed-off-by: George Paraskevopoulos <geopar@intracom-telecom.com>
Diffstat (limited to 'sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py')
-rw-r--r--sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py268
1 files changed, 268 insertions, 0 deletions
diff --git a/sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py b/sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py
new file mode 100644
index 00000000..2383bb3e
--- /dev/null
+++ b/sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py
@@ -0,0 +1,268 @@
+#!/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_tacker as os_tacker
+import functest.utils.openstack_utils as os_utils
+import opnfv.utils.ovs_logger as ovs_log
+import sfc.lib.config as sfc_config
+import sfc.lib.utils as test_utils
+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()
+TESTCASE_CONFIG = sfc_config.TestcaseConfig('sfc_two_chains_SSH_and_HTTP')
+
+
+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='public')
+
+ 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.wait_for_classification_rules,
+ 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_ovs_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_ovs_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.wait_for_classification_rules,
+ 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_ovs_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_ovs_logs(
+ ovs_logger, controller_clients, compute_clients, error)
+ results.add_to_summary(2, "FAIL", "SSH works")
+
+ return results.compile_summary()
+
+
+if __name__ == '__main__':
+ main()