5 import yardstick.ssh as ssh
6 from yardstick.benchmark.scenarios import base
8 LOG = logging.getLogger(__name__)
11 class Sfc(base.Scenario): # pragma: no cover
12 ''' SFC scenario class '''
14 __scenario_type__ = "sfc"
16 PRE_SETUP_SCRIPT = 'sfc_pre_setup.bash'
17 TACKER_SCRIPT = 'sfc_tacker.bash'
18 SERVER_SCRIPT = 'sfc_server.bash'
19 TEARDOWN_SCRIPT = "sfc_teardown.bash"
20 TACKER_CHANGECLASSI = "sfc_change_classi.bash"
22 def __init__(self, scenario_cfg, context_cfg): # pragma: no cover
23 self.scenario_cfg = scenario_cfg
24 self.context_cfg = context_cfg
25 self.setup_done = False
26 self.teardown_done = False
30 self.tacker_script = pkg_resources.resource_filename(
31 'yardstick.benchmark.scenarios.networking',
34 self.server_script = pkg_resources.resource_filename(
35 'yardstick.benchmark.scenarios.networking',
38 ''' calling Tacker to instantiate VNFs and Service Chains '''
39 cmd_tacker = "%s" % (self.tacker_script)
40 subprocess.call(cmd_tacker, shell=True)
42 target = self.context_cfg['target']
43 target_user = target.get('user', 'root')
44 target_ssh_port = target.get('ssh_port', ssh.DEFAULT_PORT)
45 target_pwd = target.get('password', 'opnfv')
46 target_ip = target.get('ip', None)
48 ''' webserver start automatically during the vm boot '''
49 LOG.info("user:%s, target:%s", target_user, target_ip)
50 self.server = ssh.SSH(target_user, target_ip, password=target_pwd,
52 self.server.wait(timeout=600)
53 self.server._put_file_shell(self.server_script, '~/server.sh')
54 cmd_server = "sudo bash server.sh"
55 LOG.debug("Executing command: %s", cmd_server)
56 status, stdout, stderr = self.server.execute(cmd_server)
57 LOG.debug("Output server command: %s", status)
59 ips = sfc_openstack.get_an_IP()
61 target = self.context_cfg['target']
62 SF1_user = target.get('user', 'root')
63 SF1_ssh_port = target.get('ssh_port', ssh.DEFAULT_PORT)
64 SF1_pwd = target.get('password', 'opnfv')
67 LOG.info("user:%s, host:%s", SF1_user, SF1_ip)
68 self.server = ssh.SSH(SF1_user, SF1_ip, password=SF1_pwd,
70 self.server.wait(timeout=600)
71 cmd_SF1 = ("nohup python vxlan_tool.py -i eth0 "
72 "-d forward -v off -b 80 &")
73 LOG.debug("Starting HTTP firewall in SF1")
74 status, stdout, stderr = self.server.execute(cmd_SF1)
75 result = self.server.execute("ps lax | grep python")
76 if "vxlan_tool.py" in result[1]: # pragma: no cover
77 LOG.debug("HTTP firewall started")
79 SF2_user = target.get('user', 'root')
80 SF2_ssh_port = target.get('ssh_port', ssh.DEFAULT_PORT)
81 SF2_pwd = target.get('password', 'opnfv')
84 LOG.info("user:%s, host:%s", SF2_user, SF2_ip)
85 self.server = ssh.SSH(SF2_user, SF2_ip, password=SF2_pwd,
87 self.server.wait(timeout=600)
88 cmd_SF2 = ("nohup python vxlan_tool.py -i eth0 "
89 "-d forward -v off -b 22 &")
90 LOG.debug("Starting SSH firewall in SF2")
91 status, stdout, stderr = self.server.execute(cmd_SF2)
93 result = self.server.execute("ps lax | grep python")
94 if "vxlan_tool.py" in result[1]: # pragma: no cover
95 LOG.debug("SSH firewall started")
97 self.setup_done = True
99 def run(self, result):
100 ''' Creating client and server VMs to perform the test'''
101 host = self.context_cfg['host']
102 host_user = host.get('user', 'root')
103 ssh_port = host.get("ssh_port", ssh.DEFAULT_PORT)
104 host_pwd = host.get('password', 'opnfv')
105 host_ip = host.get('ip', None)
107 LOG.info("user:%s, host:%s", host_user, host_ip)
108 self.client = ssh.SSH(host_user, host_ip, password=host_pwd,
110 self.client.wait(timeout=600)
112 if not self.setup_done: # pragma: no cover
115 target = self.context_cfg['target']
116 target_ip = target.get('ip', None)
118 cmd_client = "nc -w 5 -zv " + target_ip + " 22"
119 result = self.client.execute(cmd_client)
122 if "timed out" in result[2]: # pragma: no cover
123 LOG.info('\033[92m' + "TEST 1 [PASSED] "
124 "==> SSH BLOCKED" + '\033[0m')
126 else: # pragma: no cover
127 LOG.debug('\033[91m' + "TEST 1 [FAILED] "
128 "==> SSH NOT BLOCKED" + '\033[0m')
131 cmd_client = "nc -w 5 -zv " + target_ip + " 80"
132 LOG.info("Executing command: %s", cmd_client)
133 result = self.client.execute(cmd_client)
134 if "succeeded" in result[2]: # pragma: no cover
135 LOG.info('\033[92m' + "TEST 2 [PASSED] "
136 "==> HTTP WORKS" + '\033[0m')
138 else: # pragma: no cover
139 LOG.debug('\033[91m' + "TEST 2 [FAILED] "
140 "==> HTTP BLOCKED" + '\033[0m')
143 self.tacker_classi = pkg_resources.resource_filename(
144 'yardstick.benchmark.scenarios.networking',
145 Sfc.TACKER_CHANGECLASSI)
147 ''' calling Tacker to change the classifier '''
148 cmd_tacker = "%s" % (self.tacker_classi)
149 subprocess.call(cmd_tacker, shell=True)
151 cmd_client = "nc -w 5 -zv " + target_ip + " 80"
152 LOG.info("Executing command: %s", cmd_client)
153 result = self.client.execute(cmd_client)
154 LOG.info("Output client command: %s", result)
155 if "timed out" in result[2]: # pragma: no cover
156 LOG.info('\033[92m' + "TEST 3 [WORKS] "
157 "==> HTTP BLOCKED" + '\033[0m')
159 else: # pragma: no cover
160 LOG.debug('\033[91m' + "TEST 3 [FAILED] "
161 "==> HTTP NOT BLOCKED" + '\033[0m')
164 cmd_client = "nc -zv " + target_ip + " 22"
165 result = self.client.execute(cmd_client + " \r")
168 if "succeeded" in result[2]: # pragma: no cover
169 LOG.info('\033[92m' + "TEST 4 [WORKS] "
170 "==> SSH WORKS" + '\033[0m')
172 else: # pragma: no cover
173 LOG.debug('\033[91m' + "TEST 4 [FAILED] "
174 "==> SSH BLOCKED" + '\033[0m')
177 if i == 4: # pragma: no cover
178 for x in range(0, 5):
179 LOG.info('\033[92m' + "SFC TEST WORKED"
180 " :) \n" + '\033[0m')
183 ''' for scenario teardown remove tacker VNFs, chains and classifiers'''
184 self.teardown_script = pkg_resources.resource_filename(
185 "yardstick.benchmark.scenarios.networking",
187 subprocess.call(self.teardown_script, shell=True)
188 self.teardown_done = True
191 '''def _test(): # pragma: no cover
193 internal test function
194 logger = logging.getLogger("Sfc Yardstick")
195 logger.setLevel(logging.DEBUG)
199 sfc = Sfc(scenario_cfg, context_cfg)
205 if __name__ == '__main__': # pragma: no cover