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']
57 """ webserver start automatically during the vm boot """
58 LOG.info("user:%s, target:%s", target['user'], target['ip'])
59 self.server = ssh.SSH.from_node(target, defaults={
60 "user": "root", "password": "opnfv"
62 self.server.wait(timeout=600)
63 self.server._put_file_shell(self.server_script, '~/server.sh')
64 cmd_server = "sudo bash server.sh"
65 LOG.debug("Executing command: %s", cmd_server)
66 status, stdout, stderr = self.server.execute(cmd_server)
67 LOG.debug("Output server command: %s", status)
69 ips = sfc_openstack.get_an_IP()
71 target = self.context_cfg['target']
73 LOG.info("user:%s, target:%s", target['user'], target['ip'])
74 self.server = ssh.SSH.from_node(
76 defaults={"user": "root", "password": "opnfv"},
78 overrides={"ip": ips[0]}
80 self.server.wait(timeout=600)
81 cmd_SF1 = ("nohup python vxlan_tool.py -i eth0 "
82 "-d forward -v off -b 80 &")
83 LOG.debug("Starting HTTP firewall in SF1")
84 self.server.execute(cmd_SF1)
85 result = self.server.execute("ps lax | grep python")
86 if "vxlan_tool.py" in result[1]: # pragma: no cover
87 LOG.debug("HTTP firewall started")
89 LOG.info("user:%s, target:%s", target['user'], target['ip'])
90 self.server = ssh.SSH.from_node(
92 defaults={"user": "root", "password": "opnfv"},
94 overrides={"ip": ips[1]}
96 self.server.wait(timeout=600)
97 cmd_SF2 = ("nohup python vxlan_tool.py -i eth0 "
98 "-d forward -v off -b 22 &")
99 LOG.debug("Starting SSH firewall in SF2")
100 self.server.execute(cmd_SF2)
102 result = self.server.execute("ps lax | grep python")
103 if "vxlan_tool.py" in result[1]: # pragma: no cover
104 LOG.debug("SSH firewall started")
106 self.setup_done = True
108 def run(self, result):
109 """ Creating client and server VMs to perform the test"""
110 host = self.context_cfg['host']
112 LOG.info("user:%s, host:%s", host['user'], host['ip'])
113 self.client = ssh.SSH.from_node(host, defaults={
114 "user": "root", "password": "opnfv"
116 self.client.wait(timeout=600)
118 if not self.setup_done: # pragma: no cover
121 target = self.context_cfg['target']
122 target_ip = target.get('ip', None)
124 cmd_client = "nc -w 5 -zv " + target_ip + " 22"
125 result = self.client.execute(cmd_client)
128 if "timed out" in result[2]: # pragma: no cover
129 LOG.info('\033[92m' + "TEST 1 [PASSED] "
130 "==> SSH BLOCKED" + '\033[0m')
132 else: # pragma: no cover
133 LOG.debug('\033[91m' + "TEST 1 [FAILED] "
134 "==> SSH NOT BLOCKED" + '\033[0m')
137 cmd_client = "nc -w 5 -zv " + target_ip + " 80"
138 LOG.info("Executing command: %s", cmd_client)
139 result = self.client.execute(cmd_client)
140 if "succeeded" in result[2]: # pragma: no cover
141 LOG.info('\033[92m' + "TEST 2 [PASSED] "
142 "==> HTTP WORKS" + '\033[0m')
144 else: # pragma: no cover
145 LOG.debug('\033[91m' + "TEST 2 [FAILED] "
146 "==> HTTP BLOCKED" + '\033[0m')
149 self.tacker_classi = pkg_resources.resource_filename(
150 'yardstick.benchmark.scenarios.networking',
151 Sfc.TACKER_CHANGECLASSI)
153 """ calling Tacker to change the classifier """
154 cmd_tacker = "%s" % (self.tacker_classi)
155 subprocess.call(cmd_tacker, shell=True)
157 cmd_client = "nc -w 5 -zv " + target_ip + " 80"
158 LOG.info("Executing command: %s", cmd_client)
159 result = self.client.execute(cmd_client)
160 LOG.info("Output client command: %s", result)
161 if "timed out" in result[2]: # pragma: no cover
162 LOG.info('\033[92m' + "TEST 3 [WORKS] "
163 "==> HTTP BLOCKED" + '\033[0m')
165 else: # pragma: no cover
166 LOG.debug('\033[91m' + "TEST 3 [FAILED] "
167 "==> HTTP NOT BLOCKED" + '\033[0m')
170 cmd_client = "nc -zv " + target_ip + " 22"
171 result = self.client.execute(cmd_client + " \r")
174 if "succeeded" in result[2]: # pragma: no cover
175 LOG.info('\033[92m' + "TEST 4 [WORKS] "
176 "==> SSH WORKS" + '\033[0m')
178 else: # pragma: no cover
179 LOG.debug('\033[91m' + "TEST 4 [FAILED] "
180 "==> SSH BLOCKED" + '\033[0m')
183 if i == 4: # pragma: no cover
184 for x in range(0, 5):
185 LOG.info('\033[92m' + "SFC TEST WORKED"
186 " :) \n" + '\033[0m')
189 """ for scenario teardown remove tacker VNFs, chains and classifiers"""
190 self.teardown_script = pkg_resources.resource_filename(
191 "yardstick.benchmark.scenarios.networking",
193 subprocess.call(self.teardown_script, shell=True)
194 self.teardown_done = True
197 """def _test(): # pragma: no cover
199 internal test function
200 logger = logging.getLogger("Sfc Yardstick")
201 logger.setLevel(logging.DEBUG)
205 sfc = Sfc(scenario_cfg, context_cfg)
211 if __name__ == '__main__': # pragma: no cover