1 from __future__ import absolute_import
7 from six.moves import range
9 import yardstick.ssh as ssh
10 from yardstick.benchmark.scenarios import base
11 from yardstick.benchmark.scenarios.networking import sfc_openstack
13 LOG = logging.getLogger(__name__)
16 class Sfc(base.Scenario): # pragma: no cover
17 """ SFC scenario class """
19 __scenario_type__ = "sfc"
21 PRE_SETUP_SCRIPT = 'sfc_pre_setup.bash'
22 TACKER_SCRIPT = 'sfc_tacker.bash'
23 SERVER_SCRIPT = 'sfc_server.bash'
24 TEARDOWN_SCRIPT = "sfc_teardown.bash"
25 TACKER_CHANGECLASSI = "sfc_change_classi.bash"
27 def __init__(self, scenario_cfg, context_cfg): # pragma: no cover
28 self.scenario_cfg = scenario_cfg
29 self.context_cfg = context_cfg
30 self.setup_done = False
31 self.teardown_done = False
35 self.tacker_script = pkg_resources.resource_filename(
36 'yardstick.benchmark.scenarios.networking',
39 self.server_script = pkg_resources.resource_filename(
40 'yardstick.benchmark.scenarios.networking',
43 """ calling Tacker to instantiate VNFs and Service Chains """
44 cmd_tacker = "%s" % (self.tacker_script)
45 subprocess.call(cmd_tacker, shell=True)
47 target = self.context_cfg['target']
48 target_user = target.get('user', 'root')
49 target_ssh_port = target.get('ssh_port', ssh.DEFAULT_PORT)
50 target_pwd = target.get('password', 'opnfv')
51 target_ip = target.get('ip', None)
53 """ webserver start automatically during the vm boot """
54 LOG.info("user:%s, target:%s", target_user, target_ip)
55 self.server = ssh.SSH(target_user, target_ip, password=target_pwd,
57 self.server.wait(timeout=600)
58 self.server._put_file_shell(self.server_script, '~/server.sh')
59 cmd_server = "sudo bash server.sh"
60 LOG.debug("Executing command: %s", cmd_server)
61 status, stdout, stderr = self.server.execute(cmd_server)
62 LOG.debug("Output server command: %s", status)
64 ips = sfc_openstack.get_an_IP()
66 target = self.context_cfg['target']
67 SF1_user = target.get('user', 'root')
68 SF1_ssh_port = target.get('ssh_port', ssh.DEFAULT_PORT)
69 SF1_pwd = target.get('password', 'opnfv')
72 LOG.info("user:%s, host:%s", SF1_user, SF1_ip)
73 self.server = ssh.SSH(SF1_user, SF1_ip, password=SF1_pwd,
75 self.server.wait(timeout=600)
76 cmd_SF1 = ("nohup python vxlan_tool.py -i eth0 "
77 "-d forward -v off -b 80 &")
78 LOG.debug("Starting HTTP firewall in SF1")
79 status, stdout, stderr = self.server.execute(cmd_SF1)
80 result = self.server.execute("ps lax | grep python")
81 if "vxlan_tool.py" in result[1]: # pragma: no cover
82 LOG.debug("HTTP firewall started")
84 SF2_user = target.get('user', 'root')
85 SF2_ssh_port = target.get('ssh_port', ssh.DEFAULT_PORT)
86 SF2_pwd = target.get('password', 'opnfv')
89 LOG.info("user:%s, host:%s", SF2_user, SF2_ip)
90 self.server = ssh.SSH(SF2_user, SF2_ip, password=SF2_pwd,
92 self.server.wait(timeout=600)
93 cmd_SF2 = ("nohup python vxlan_tool.py -i eth0 "
94 "-d forward -v off -b 22 &")
95 LOG.debug("Starting SSH firewall in SF2")
96 status, stdout, stderr = self.server.execute(cmd_SF2)
98 result = self.server.execute("ps lax | grep python")
99 if "vxlan_tool.py" in result[1]: # pragma: no cover
100 LOG.debug("SSH firewall started")
102 self.setup_done = True
104 def run(self, result):
105 """ Creating client and server VMs to perform the test"""
106 host = self.context_cfg['host']
107 host_user = host.get('user', 'root')
108 ssh_port = host.get("ssh_port", ssh.DEFAULT_PORT)
109 host_pwd = host.get('password', 'opnfv')
110 host_ip = host.get('ip', None)
112 LOG.info("user:%s, host:%s", host_user, host_ip)
113 self.client = ssh.SSH(host_user, host_ip, password=host_pwd,
115 self.client.wait(timeout=600)
117 if not self.setup_done: # pragma: no cover
120 target = self.context_cfg['target']
121 target_ip = target.get('ip', None)
123 cmd_client = "nc -w 5 -zv " + target_ip + " 22"
124 result = self.client.execute(cmd_client)
127 if "timed out" in result[2]: # pragma: no cover
128 LOG.info('\033[92m' + "TEST 1 [PASSED] "
129 "==> SSH BLOCKED" + '\033[0m')
131 else: # pragma: no cover
132 LOG.debug('\033[91m' + "TEST 1 [FAILED] "
133 "==> SSH NOT BLOCKED" + '\033[0m')
136 cmd_client = "nc -w 5 -zv " + target_ip + " 80"
137 LOG.info("Executing command: %s", cmd_client)
138 result = self.client.execute(cmd_client)
139 if "succeeded" in result[2]: # pragma: no cover
140 LOG.info('\033[92m' + "TEST 2 [PASSED] "
141 "==> HTTP WORKS" + '\033[0m')
143 else: # pragma: no cover
144 LOG.debug('\033[91m' + "TEST 2 [FAILED] "
145 "==> HTTP BLOCKED" + '\033[0m')
148 self.tacker_classi = pkg_resources.resource_filename(
149 'yardstick.benchmark.scenarios.networking',
150 Sfc.TACKER_CHANGECLASSI)
152 """ calling Tacker to change the classifier """
153 cmd_tacker = "%s" % (self.tacker_classi)
154 subprocess.call(cmd_tacker, shell=True)
156 cmd_client = "nc -w 5 -zv " + target_ip + " 80"
157 LOG.info("Executing command: %s", cmd_client)
158 result = self.client.execute(cmd_client)
159 LOG.info("Output client command: %s", result)
160 if "timed out" in result[2]: # pragma: no cover
161 LOG.info('\033[92m' + "TEST 3 [WORKS] "
162 "==> HTTP BLOCKED" + '\033[0m')
164 else: # pragma: no cover
165 LOG.debug('\033[91m' + "TEST 3 [FAILED] "
166 "==> HTTP NOT BLOCKED" + '\033[0m')
169 cmd_client = "nc -zv " + target_ip + " 22"
170 result = self.client.execute(cmd_client + " \r")
173 if "succeeded" in result[2]: # pragma: no cover
174 LOG.info('\033[92m' + "TEST 4 [WORKS] "
175 "==> SSH WORKS" + '\033[0m')
177 else: # pragma: no cover
178 LOG.debug('\033[91m' + "TEST 4 [FAILED] "
179 "==> SSH BLOCKED" + '\033[0m')
182 if i == 4: # pragma: no cover
183 for x in range(0, 5):
184 LOG.info('\033[92m' + "SFC TEST WORKED"
185 " :) \n" + '\033[0m')
188 """ for scenario teardown remove tacker VNFs, chains and classifiers"""
189 self.teardown_script = pkg_resources.resource_filename(
190 "yardstick.benchmark.scenarios.networking",
192 subprocess.call(self.teardown_script, shell=True)
193 self.teardown_done = True
196 """def _test(): # pragma: no cover
198 internal test function
199 logger = logging.getLogger("Sfc Yardstick")
200 logger.setLevel(logging.DEBUG)
204 sfc = Sfc(scenario_cfg, context_cfg)
210 if __name__ == '__main__': # pragma: no cover