aboutsummaryrefslogtreecommitdiffstats
path: root/sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py
diff options
context:
space:
mode:
authorPanagiotis Karalis <pkaralis@intracom-telecom.com>2018-02-14 15:28:02 +0200
committerPanagiotis Karalis <pkaralis@intracom-telecom.com>2018-05-15 11:42:44 +0300
commit23c9ae8fa5db3ea02077d97452ea503097cf985e (patch)
tree1e076dcabac20963465c7380eab4ba16d0b50f6a /sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py
parent5f8eb6bf01ca3ef240cfcdee297327b21b33f35a (diff)
Clean up Test Case code
Too much of duplicated code has been obeserved in test cases. With this patch a small refactoring is necessery to our test cases code. So they can be more generic and more flexible. To achieve that the addition of new parent class is essential, hence all the rest test case classes will inherit from the aforementioned parent class. Change-Id: I6a50d8330a06321742b3bb03cc999682d4a4e6a1 Signed-off-by: Panagiotis Karalis <pkaralis@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.py337
1 files changed, 68 insertions, 269 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
index a57fa745..a8b9d84a 100644
--- a/sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py
+++ b/sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py
@@ -8,305 +8,104 @@
# http://www.apache.org/licenses/LICENSE-2.0
#
-import os
-import sys
import threading
-import sfc.lib.openstack_utils as os_sfc_utils
import sfc.lib.odl_utils as odl_utils
-import opnfv.utils.ovs_logger as ovs_log
import sfc.lib.config as sfc_config
-import sfc.lib.test_utils as test_utils
-import sfc.lib.topology_shuffler as topo_shuffler
-
+from sfc.tests.functest import sfc_parent_function
from opnfv.utils import opnfv_logger as logger
-from sfc.lib.results import Results
-from opnfv.deployment.factory import Factory as DeploymentFactory
""" logging configuration """
logger = logger.Logger(__name__).getLogger()
-CLIENT = "client"
-SERVER = "server"
-COMMON_CONFIG = sfc_config.CommonConfig()
-TESTCASE_CONFIG = sfc_config.TestcaseConfig('sfc_two_chains_SSH_and_HTTP')
-
-
-def main():
- deploymentHandler = DeploymentFactory.get_handler(
- COMMON_CONFIG.installer_type,
- COMMON_CONFIG.installer_ip,
- COMMON_CONFIG.installer_user,
- COMMON_CONFIG.installer_password,
- COMMON_CONFIG.installer_key_file)
-
- installer_type = os.environ.get("INSTALLER_TYPE")
-
- supported_installers = ['fuel', 'apex', 'osa', 'compass']
-
- if installer_type not in supported_installers:
- logger.error(
- '\033[91mYour installer is not supported yet\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)
-
- cluster = COMMON_CONFIG.installer_cluster
- openstack_nodes = (deploymentHandler.get_nodes({'cluster': cluster})
- if cluster is not None
- else deploymentHandler.get_nodes())
-
- controller_nodes = [node for node in openstack_nodes
- if node.is_controller()]
- compute_nodes = [node for node in openstack_nodes
- if node.is_compute()]
-
- odl_ip, odl_port = odl_utils.get_odl_ip_port(openstack_nodes)
-
- for compute in compute_nodes:
- logger.info("This is a compute: %s" % compute.ip)
-
- results = Results(COMMON_CONFIG.line_length)
- results.add_to_summary(0, "=")
- results.add_to_summary(2, "STATUS", "SUBTEST")
- results.add_to_summary(0, "=")
-
- openstack_sfc = os_sfc_utils.OpenStackSFC()
-
- custom_flv = openstack_sfc.create_flavor(
- COMMON_CONFIG.flavor,
- COMMON_CONFIG.ram_size_in_mb,
- COMMON_CONFIG.disk_size_in_gb,
- COMMON_CONFIG.vcpu_count)
- if not custom_flv:
- logger.error("Failed to create custom flavor")
- sys.exit(1)
-
- logger.info("Fetching the ssh clients...")
- tacker_client = os_sfc_utils.get_tacker_client()
- controller_clients = test_utils.get_ssh_clients(controller_nodes)
- compute_clients = test_utils.get_ssh_clients(compute_nodes)
-
- ovs_logger = ovs_log.OVSLogger(
- os.path.join(COMMON_CONFIG.sfc_test_dir, 'ovs-logs'),
- COMMON_CONFIG.functest_results_dir)
-
- image_creator = openstack_sfc.register_glance_image(
- COMMON_CONFIG.image_name,
- COMMON_CONFIG.image_url,
- COMMON_CONFIG.image_format,
- 'public')
-
- network, router = openstack_sfc.create_network_infrastructure(
- TESTCASE_CONFIG.net_name,
- TESTCASE_CONFIG.subnet_name,
- TESTCASE_CONFIG.subnet_cidr,
- TESTCASE_CONFIG.router_name)
-
- sg = openstack_sfc.create_security_group(TESTCASE_CONFIG.secgroup_name)
- vnf_names = ['testVNF1', 'testVNF2']
-
- topo_seed = topo_shuffler.get_seed() # change to None for nova av zone
- testTopology = topo_shuffler.topology(vnf_names, openstack_sfc,
- seed=topo_seed)
-
- logger.info('This test is run with the topology {0}'
- .format(testTopology['id']))
- logger.info('Topology description: {0}'
- .format(testTopology['description']))
-
- client_instance, client_creator = openstack_sfc.create_instance(
- CLIENT, COMMON_CONFIG.flavor, image_creator, network, sg,
- av_zone=testTopology['client'])
-
- server_instance, server_creator = openstack_sfc.create_instance(
- SERVER, COMMON_CONFIG.flavor, image_creator, network, sg,
- av_zone=testTopology['server'])
-
- server_ip = server_instance.ports[0].ips[0]['ip_address']
-
- os_sfc_utils.register_vim(tacker_client, vim_file=COMMON_CONFIG.vim_file)
-
- tosca_red = os.path.join(COMMON_CONFIG.sfc_test_dir,
- COMMON_CONFIG.vnfd_dir,
- TESTCASE_CONFIG.test_vnfd_red)
- os_sfc_utils.create_vnfd(tacker_client,
- tosca_file=tosca_red,
- vnfd_name='test-vnfd1')
-
- tosca_blue = os.path.join(COMMON_CONFIG.sfc_test_dir,
- COMMON_CONFIG.vnfd_dir,
- TESTCASE_CONFIG.test_vnfd_blue)
-
- os_sfc_utils.create_vnfd(tacker_client,
- tosca_file=tosca_blue,
- vnfd_name='test-vnfd2')
+class SfcTwoChainsSSHandHTTP(sfc_parent_function.SfcCommonTestCase):
+ """We create one client and one server using nova.
+ Then, 2 SFs are created using tacker.
+ Two chains are created, having one SF each.
+ The vxlan tool is used on both SFs. The purpose is to
+ check different HTTP and SSH traffic combinations.
+ """
- default_param_file = os.path.join(
- COMMON_CONFIG.sfc_test_dir,
- COMMON_CONFIG.vnfd_dir,
- COMMON_CONFIG.vnfd_default_params_file)
+ def run(self):
- os_sfc_utils.create_vnf_in_av_zone(
- tacker_client, vnf_names[0], 'test-vnfd1', 'test-vim',
- default_param_file, testTopology[vnf_names[0]])
- os_sfc_utils.create_vnf_in_av_zone(
- tacker_client, vnf_names[1], 'test-vnfd2', 'test-vim',
- default_param_file, testTopology[vnf_names[1]])
+ logger.info("The test scenario %s is starting", __name__)
- vnf1_id = os_sfc_utils.wait_for_vnf(tacker_client, vnf_name=vnf_names[0])
- vnf2_id = os_sfc_utils.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)
+ self.create_custom_vnfd(self.testcase_config.test_vnfd_red,
+ 'test-vnfd1')
+ self.create_custom_vnfd(self.testcase_config.test_vnfd_blue,
+ 'test-vnfd2')
- tosca_file = os.path.join(COMMON_CONFIG.sfc_test_dir,
- COMMON_CONFIG.vnffgd_dir,
- TESTCASE_CONFIG.test_vnffgd_red)
+ self.create_custom_av(self.vnfs[0], 'test-vnfd1', 'test-vim')
+ self.create_custom_av(self.vnfs[1], 'test-vnfd2', 'test-vim')
- os_sfc_utils.create_vnffgd(tacker_client,
- tosca_file=tosca_file,
- vnffgd_name='red')
+ self.create_vnffg(self.testcase_config.test_vnffgd_red, 'red',
+ 'red_http')
- neutron_port = openstack_sfc.get_client_port(client_instance,
- client_creator)
- os_sfc_utils.create_vnffg_with_param_file(tacker_client, 'red',
- 'red_http',
- default_param_file,
- neutron_port.id)
+ t1 = threading.Thread(target=odl_utils.wait_for_classification_rules,
+ args=(self.ovs_logger, self.compute_nodes,
+ self.odl_ip, self.odl_port,
+ self.client_instance.compute_host,
+ [self.neutron_port],))
- # Start measuring the time it takes to implement the classification rules
- t1 = threading.Thread(target=odl_utils.wait_for_classification_rules,
- args=(ovs_logger, compute_nodes, odl_ip,
- odl_port, openstack_sfc.get_compute_client(),
- [neutron_port],))
+ try:
+ t1.start()
+ except Exception as e:
+ logger.error("Unable to start the thread that counts time %s" % e)
- try:
- t1.start()
- except Exception as e:
- logger.error("Unable to start the thread that counts time %s" % e)
+ logger.info("Assigning floating IPs to instances")
+ self.assign_floating_ip_client_server()
- logger.info("Assigning floating IPs to instances")
- client_floating_ip = openstack_sfc.assign_floating_ip(router,
- client_instance,
- client_creator)
- server_floating_ip = openstack_sfc.assign_floating_ip(router,
- server_instance,
- server_creator)
- fips_sfs = openstack_sfc.assign_floating_ip_vnfs(router)
- sf1_floating_ip = fips_sfs[0]
- sf2_floating_ip = fips_sfs[1]
+ self.assign_floating_ip_sfs()
- fips = [client_floating_ip, server_floating_ip, sf1_floating_ip,
- sf2_floating_ip]
+ self.check_floating_ips()
+ self.start_services_in_vm()
+ self.vxlan_blocking_start(self.fips_sfs[0], "22")
+ self.vxlan_blocking_start(self.fips_sfs[1], "80")
- for ip in fips:
- logger.info("Checking connectivity towards floating IP [%s]" % ip)
- if not test_utils.ping(ip, retries=50, retry_timeout=3):
- logger.error("Cannot ping floating IP [%s]" % ip)
- os_sfc_utils.get_tacker_items()
- odl_utils.get_odl_items(odl_ip, odl_port)
- sys.exit(1)
- logger.info("Successful ping to floating IP [%s]" % ip)
+ logger.info("Wait for ODL to update the classification rules in OVS")
+ t1.join()
- if not test_utils.check_ssh([sf1_floating_ip, sf2_floating_ip]):
- logger.error("Cannot establish SSH connection to the SFs")
- sys.exit(1)
+ results = self.present_results_ssh()
+ results = self.present_results_allowed_http()
- 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("Changing the classification")
- 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")
+ self.remove_vnffg('red_http', 'red')
- logger.info("Wait for ODL to update the classification rules in OVS")
- t1.join()
+ self.create_vnffg(self.testcase_config.test_vnffgd_blue, 'blue',
+ 'blue_ssh')
- logger.info("Test SSH")
- 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')
- logger.error(error)
- test_utils.capture_ovs_logs(
- ovs_logger, controller_clients, compute_clients, error)
- results.add_to_summary(2, "FAIL", "SSH Blocked")
+ # Start measuring the time it takes to implement the classification
+ # rules
+ t2 = threading.Thread(target=odl_utils.wait_for_classification_rules,
+ args=(self.ovs_logger, self.compute_nodes,
+ self.odl_ip, self.odl_port,
+ self.client_instance.compute_host,
+ self.neutron_port,))
+ try:
+ t2.start()
+ except Exception as e:
+ logger.error("Unable to start the thread that counts time %s" % e)
- logger.info("Test HTTP")
- 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')
- 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("Wait for ODL to update the classification rules in OVS")
+ t2.join()
- logger.info("Changing the classification")
+ results = self.present_results_http()
+ results = self.present_results_allowed_ssh()
- os_sfc_utils.delete_vnffg(tacker_client, vnffg_name='red_http_works')
+ if __name__ == '__main__':
+ return results.compile_summary(), self.creators
- os_sfc_utils.delete_vnffgd(tacker_client, vnffgd_name='red')
+ if __name__ == 'sfc.tests.functest.sfc_two_chains_SSH_and_HTTP':
+ return results.compile_summary(), self.creators
- tosca_file = os.path.join(COMMON_CONFIG.sfc_test_dir,
- COMMON_CONFIG.vnffgd_dir,
- TESTCASE_CONFIG.test_vnffgd_blue)
- os_sfc_utils.create_vnffgd(tacker_client,
- tosca_file=tosca_file,
- vnffgd_name='blue')
-
- os_sfc_utils.create_vnffg_with_param_file(tacker_client, 'blue',
- 'blue_ssh',
- default_param_file,
- neutron_port)
-
- # Start measuring the time it takes to implement the classification rules
- t2 = threading.Thread(target=odl_utils.wait_for_classification_rules,
- args=(ovs_logger, compute_nodes, odl_ip,
- odl_port, openstack_sfc.get_compute_client(),
- [neutron_port],))
- try:
- t2.start()
- except Exception as 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(client_floating_ip, server_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(client_floating_ip, server_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(), openstack_sfc.creators
+if __name__ == '__main__':
+ TESTCASE_CONFIG = sfc_config.TestcaseConfig('sfc_two_chains_SSH_and_HTTP')
+ supported_installers = ['fuel', 'apex', 'osa', 'compass']
+ vnf_names = ['testVNF1', 'testVNF2']
-if __name__ == '__main__':
- main()
+ test_run = SfcTwoChainsSSHandHTTP(TESTCASE_CONFIG, supported_installers,
+ vnf_names)
+ test_run.run()