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.run("cat > ~/server.sh",
54 stdin=open(self.server_script, "rb"))
55 cmd_server = "sudo bash server.sh"
56 LOG.debug("Executing command: %s", cmd_server)
57 status, stdout, stderr = self.server.execute(cmd_server)
58 LOG.debug("Output server command: %s", status)
60 ips = sfc_openstack.get_an_IP()
62 target = self.context_cfg['target']
63 SF1_user = target.get('user', 'root')
64 SF1_ssh_port = target.get('ssh_port', ssh.DEFAULT_PORT)
65 SF1_pwd = target.get('password', 'opnfv')
68 LOG.info("user:%s, host:%s", SF1_user, SF1_ip)
69 self.server = ssh.SSH(SF1_user, SF1_ip, password=SF1_pwd,
71 self.server.wait(timeout=600)
72 cmd_SF1 = ("nohup python vxlan_tool.py -i eth0 "
73 "-d forward -v off -b 80 &")
74 LOG.debug("Starting HTTP firewall in SF1")
75 status, stdout, stderr = self.server.execute(cmd_SF1)
76 result = self.server.execute("ps lax | grep python")
77 if "vxlan_tool.py" in result[1]: # pragma: no cover
78 LOG.debug("HTTP firewall started")
80 SF2_user = target.get('user', 'root')
81 SF2_ssh_port = target.get('ssh_port', ssh.DEFAULT_PORT)
82 SF2_pwd = target.get('password', 'opnfv')
85 LOG.info("user:%s, host:%s", SF2_user, SF2_ip)
86 self.server = ssh.SSH(SF2_user, SF2_ip, password=SF2_pwd,
88 self.server.wait(timeout=600)
89 cmd_SF2 = ("nohup python vxlan_tool.py -i eth0 "
90 "-d forward -v off -b 22 &")
91 LOG.debug("Starting SSH firewall in SF2")
92 status, stdout, stderr = self.server.execute(cmd_SF2)
94 result = self.server.execute("ps lax | grep python")
95 if "vxlan_tool.py" in result[1]: # pragma: no cover
96 LOG.debug("SSH firewall started")
98 self.setup_done = True
100 def run(self, result):
101 ''' Creating client and server VMs to perform the test'''
102 host = self.context_cfg['host']
103 host_user = host.get('user', 'root')
104 ssh_port = host.get("ssh_port", ssh.DEFAULT_PORT)
105 host_pwd = host.get('password', 'opnfv')
106 host_ip = host.get('ip', None)
108 LOG.info("user:%s, host:%s", host_user, host_ip)
109 self.client = ssh.SSH(host_user, host_ip, password=host_pwd,
111 self.client.wait(timeout=600)
113 if not self.setup_done: # pragma: no cover
116 target = self.context_cfg['target']
117 target_ip = target.get('ip', None)
119 cmd_client = "nc -w 5 -zv " + target_ip + " 22"
120 result = self.client.execute(cmd_client)
123 if "timed out" in result[2]: # pragma: no cover
124 LOG.info('\033[92m' + "TEST 1 [PASSED] "
125 "==> SSH BLOCKED" + '\033[0m')
127 else: # pragma: no cover
128 LOG.debug('\033[91m' + "TEST 1 [FAILED] "
129 "==> SSH NOT BLOCKED" + '\033[0m')
132 cmd_client = "nc -w 5 -zv " + target_ip + " 80"
133 LOG.info("Executing command: %s", cmd_client)
134 result = self.client.execute(cmd_client)
135 if "succeeded" in result[2]: # pragma: no cover
136 LOG.info('\033[92m' + "TEST 2 [PASSED] "
137 "==> HTTP WORKS" + '\033[0m')
139 else: # pragma: no cover
140 LOG.debug('\033[91m' + "TEST 2 [FAILED] "
141 "==> HTTP BLOCKED" + '\033[0m')
144 self.tacker_classi = pkg_resources.resource_filename(
145 'yardstick.benchmark.scenarios.networking',
146 Sfc.TACKER_CHANGECLASSI)
148 ''' calling Tacker to change the classifier '''
149 cmd_tacker = "%s" % (self.tacker_classi)
150 subprocess.call(cmd_tacker, shell=True)
152 cmd_client = "nc -w 5 -zv " + target_ip + " 80"
153 LOG.info("Executing command: %s", cmd_client)
154 result = self.client.execute(cmd_client)
155 LOG.info("Output client command: %s", result)
156 if "timed out" in result[2]: # pragma: no cover
157 LOG.info('\033[92m' + "TEST 3 [WORKS] "
158 "==> HTTP BLOCKED" + '\033[0m')
160 else: # pragma: no cover
161 LOG.debug('\033[91m' + "TEST 3 [FAILED] "
162 "==> HTTP NOT BLOCKED" + '\033[0m')
165 cmd_client = "nc -zv " + target_ip + " 22"
166 result = self.client.execute(cmd_client + " \r")
169 if "succeeded" in result[2]: # pragma: no cover
170 LOG.info('\033[92m' + "TEST 4 [WORKS] "
171 "==> SSH WORKS" + '\033[0m')
173 else: # pragma: no cover
174 LOG.debug('\033[91m' + "TEST 4 [FAILED] "
175 "==> SSH BLOCKED" + '\033[0m')
178 if i == 4: # pragma: no cover
179 for x in range(0, 5):
180 LOG.info('\033[92m' + "SFC TEST WORKED"
181 " :) \n" + '\033[0m')
184 ''' for scenario teardown remove tacker VNFs, chains and classifiers'''
185 self.teardown_script = pkg_resources.resource_filename(
186 "yardstick.benchmark.scenarios.networking",
188 subprocess.call(self.teardown_script, shell=True)
189 self.teardown_done = True
192 '''def _test(): # pragma: no cover
194 internal test function
195 logger = logging.getLogger("Sfc Yardstick")
196 logger.setLevel(logging.DEBUG)
200 sfc = Sfc(scenario_cfg, context_cfg)
206 if __name__ == '__main__': # pragma: no cover