1 ##############################################################################
2 # Copyright (c) 2017 Ericsson AB and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 from __future__ import absolute_import
15 from six.moves import range
17 import yardstick.ssh as ssh
18 from yardstick.benchmark.scenarios import base
19 from yardstick.benchmark.scenarios.networking import sfc_openstack
21 LOG = logging.getLogger(__name__)
24 class Sfc(base.Scenario): # pragma: no cover
25 """ SFC scenario class """
27 __scenario_type__ = "sfc"
29 PRE_SETUP_SCRIPT = 'sfc_pre_setup.bash'
30 TACKER_SCRIPT = 'sfc_tacker.bash'
31 SERVER_SCRIPT = 'sfc_server.bash'
32 TEARDOWN_SCRIPT = "sfc_teardown.bash"
33 TACKER_CHANGECLASSI = "sfc_change_classi.bash"
35 def __init__(self, scenario_cfg, context_cfg): # pragma: no cover
36 self.scenario_cfg = scenario_cfg
37 self.context_cfg = context_cfg
38 self.setup_done = False
39 self.teardown_done = False
43 self.tacker_script = pkg_resources.resource_filename(
44 'yardstick.benchmark.scenarios.networking',
47 self.server_script = pkg_resources.resource_filename(
48 'yardstick.benchmark.scenarios.networking',
51 """ calling Tacker to instantiate VNFs and Service Chains """
52 cmd_tacker = "%s" % (self.tacker_script)
53 subprocess.call(cmd_tacker, shell=True)
55 target = self.context_cfg['target']
56 target_user = target.get('user', 'root')
57 target_ssh_port = target.get('ssh_port', ssh.DEFAULT_PORT)
58 target_pwd = target.get('password', 'opnfv')
59 target_ip = target.get('ip', None)
61 """ webserver start automatically during the vm boot """
62 LOG.info("user:%s, target:%s", target_user, target_ip)
63 self.server = ssh.SSH(target_user, target_ip, password=target_pwd,
65 self.server.wait(timeout=600)
66 self.server._put_file_shell(self.server_script, '~/server.sh')
67 cmd_server = "sudo bash server.sh"
68 LOG.debug("Executing command: %s", cmd_server)
69 status, stdout, stderr = self.server.execute(cmd_server)
70 LOG.debug("Output server command: %s", status)
72 ips = sfc_openstack.get_an_IP()
74 target = self.context_cfg['target']
75 SF1_user = target.get('user', 'root')
76 SF1_ssh_port = target.get('ssh_port', ssh.DEFAULT_PORT)
77 SF1_pwd = target.get('password', 'opnfv')
80 LOG.info("user:%s, host:%s", SF1_user, SF1_ip)
81 self.server = ssh.SSH(SF1_user, SF1_ip, password=SF1_pwd,
83 self.server.wait(timeout=600)
84 cmd_SF1 = ("nohup python vxlan_tool.py -i eth0 "
85 "-d forward -v off -b 80 &")
86 LOG.debug("Starting HTTP firewall in SF1")
87 status, stdout, stderr = self.server.execute(cmd_SF1)
88 result = self.server.execute("ps lax | grep python")
89 if "vxlan_tool.py" in result[1]: # pragma: no cover
90 LOG.debug("HTTP firewall started")
92 SF2_user = target.get('user', 'root')
93 SF2_ssh_port = target.get('ssh_port', ssh.DEFAULT_PORT)
94 SF2_pwd = target.get('password', 'opnfv')
97 LOG.info("user:%s, host:%s", SF2_user, SF2_ip)
98 self.server = ssh.SSH(SF2_user, SF2_ip, password=SF2_pwd,
100 self.server.wait(timeout=600)
101 cmd_SF2 = ("nohup python vxlan_tool.py -i eth0 "
102 "-d forward -v off -b 22 &")
103 LOG.debug("Starting SSH firewall in SF2")
104 status, stdout, stderr = self.server.execute(cmd_SF2)
106 result = self.server.execute("ps lax | grep python")
107 if "vxlan_tool.py" in result[1]: # pragma: no cover
108 LOG.debug("SSH firewall started")
110 self.setup_done = True
112 def run(self, result):
113 """ Creating client and server VMs to perform the test"""
114 host = self.context_cfg['host']
115 host_user = host.get('user', 'root')
116 ssh_port = host.get("ssh_port", ssh.DEFAULT_PORT)
117 host_pwd = host.get('password', 'opnfv')
118 host_ip = host.get('ip', None)
120 LOG.info("user:%s, host:%s", host_user, host_ip)
121 self.client = ssh.SSH(host_user, host_ip, password=host_pwd,
123 self.client.wait(timeout=600)
125 if not self.setup_done: # pragma: no cover
128 target = self.context_cfg['target']
129 target_ip = target.get('ip', None)
131 cmd_client = "nc -w 5 -zv " + target_ip + " 22"
132 result = self.client.execute(cmd_client)
135 if "timed out" in result[2]: # pragma: no cover
136 LOG.info('\033[92m' + "TEST 1 [PASSED] "
137 "==> SSH BLOCKED" + '\033[0m')
139 else: # pragma: no cover
140 LOG.debug('\033[91m' + "TEST 1 [FAILED] "
141 "==> SSH NOT BLOCKED" + '\033[0m')
144 cmd_client = "nc -w 5 -zv " + target_ip + " 80"
145 LOG.info("Executing command: %s", cmd_client)
146 result = self.client.execute(cmd_client)
147 if "succeeded" in result[2]: # pragma: no cover
148 LOG.info('\033[92m' + "TEST 2 [PASSED] "
149 "==> HTTP WORKS" + '\033[0m')
151 else: # pragma: no cover
152 LOG.debug('\033[91m' + "TEST 2 [FAILED] "
153 "==> HTTP BLOCKED" + '\033[0m')
156 self.tacker_classi = pkg_resources.resource_filename(
157 'yardstick.benchmark.scenarios.networking',
158 Sfc.TACKER_CHANGECLASSI)
160 """ calling Tacker to change the classifier """
161 cmd_tacker = "%s" % (self.tacker_classi)
162 subprocess.call(cmd_tacker, shell=True)
164 cmd_client = "nc -w 5 -zv " + target_ip + " 80"
165 LOG.info("Executing command: %s", cmd_client)
166 result = self.client.execute(cmd_client)
167 LOG.info("Output client command: %s", result)
168 if "timed out" in result[2]: # pragma: no cover
169 LOG.info('\033[92m' + "TEST 3 [WORKS] "
170 "==> HTTP BLOCKED" + '\033[0m')
172 else: # pragma: no cover
173 LOG.debug('\033[91m' + "TEST 3 [FAILED] "
174 "==> HTTP NOT BLOCKED" + '\033[0m')
177 cmd_client = "nc -zv " + target_ip + " 22"
178 result = self.client.execute(cmd_client + " \r")
181 if "succeeded" in result[2]: # pragma: no cover
182 LOG.info('\033[92m' + "TEST 4 [WORKS] "
183 "==> SSH WORKS" + '\033[0m')
185 else: # pragma: no cover
186 LOG.debug('\033[91m' + "TEST 4 [FAILED] "
187 "==> SSH BLOCKED" + '\033[0m')
190 if i == 4: # pragma: no cover
191 for x in range(0, 5):
192 LOG.info('\033[92m' + "SFC TEST WORKED"
193 " :) \n" + '\033[0m')
196 """ for scenario teardown remove tacker VNFs, chains and classifiers"""
197 self.teardown_script = pkg_resources.resource_filename(
198 "yardstick.benchmark.scenarios.networking",
200 subprocess.call(self.teardown_script, shell=True)
201 self.teardown_done = True
204 """def _test(): # pragma: no cover
206 internal test function
207 logger = logging.getLogger("Sfc Yardstick")
208 logger.setLevel(logging.DEBUG)
212 sfc = Sfc(scenario_cfg, context_cfg)
218 if __name__ == '__main__': # pragma: no cover