Change copyright for base scenario
[yardstick.git] / yardstick / benchmark / scenarios / networking / sfc.py
1 import pkg_resources
2 import logging
3 import subprocess
4
5 import yardstick.ssh as ssh
6 from yardstick.benchmark.scenarios import base
7
8 LOG = logging.getLogger(__name__)
9
10
11 class Sfc(base.Scenario):
12     ''' SFC scenario class '''
13
14     __scenario_type__ = "sfc"
15
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
21     def __init__(self, scenario_cfg, context_cfg):
22         self.scenario_cfg = scenario_cfg
23         self.context_cfg = context_cfg
24         self.setup_done = False
25         self.teardown_done = False
26
27     def setup(self):
28         '''scenario setup'''
29         self.tacker_script = pkg_resources.resource_filename(
30             'yardstick.benchmark.scenarios.networking',
31             Sfc.TACKER_SCRIPT)
32
33         self.server_script = pkg_resources.resource_filename(
34             'yardstick.benchmark.scenarios.networking',
35             Sfc.SERVER_SCRIPT)
36
37         ''' calling Tacker to instantiate VNFs and Service Chains '''
38         cmd_tacker = "%s" % (self.tacker_script)
39         subprocess.call(cmd_tacker, shell=True)
40
41         target = self.context_cfg['target']
42         target_user = target.get('user', 'root')
43         target_pwd = target.get('password', 'octopus')
44         target_ip = target.get('ip', None)
45
46         ''' webserver start automatically during the vm boot '''
47         LOG.info("user:%s, target:%s", target_user, target_ip)
48         self.server = ssh.SSH(target_user, target_ip, password=target_pwd)
49         self.server.wait(timeout=600)
50         self.server.run("cat > ~/server.sh",
51                         stdin=open(self.server_script, "rb"))
52         cmd_server = "sudo bash server.sh"
53         LOG.debug("Executing command: %s", cmd_server)
54         status, stdout, stderr = self.server.execute(cmd_server)
55         LOG.debug("Output server command: %s", status)
56
57         self.setup_done = True
58
59     def run(self, result):
60         ''' Creating client and server VMs to perform the test'''
61         host = self.context_cfg['host']
62         host_user = host.get('user', 'cirros')
63         host_pwd = host.get('password', 'cubswin:)')
64         host_ip = host.get('ip', None)
65
66         LOG.info("user:%s, host:%s", host_user, host_ip)
67         self.client = ssh.SSH(host_user, host_ip, password=host_pwd)
68         self.client.wait(timeout=600)
69
70         if not self.setup_done:
71             self.setup()
72
73         target = self.context_cfg['target']
74         target_ip = target.get('ip', None)
75
76         cmd_client = "curl %s", target_ip
77         LOG.debug("Executing command: %s", cmd_client)
78         result = self.client.execute(cmd_client)
79         LOG.debug("Output client command: %s", result)
80
81     def teardown(self):
82         ''' for scenario teardown remove tacker VNFs, chains and classifiers'''
83         self.teardown_script = pkg_resources.resource_filename(
84             "yardstick.benchmark.scenarios.sfc",
85             Sfc.TEARDOWN_SCRIPT)
86         subprocess.call(self.teardown_script, shell=True)
87         self.teardown_done = True
88
89
90 '''def _test():
91
92     internal test function
93     logger = logging.getLogger("Sfc Yardstick")
94     logger.setLevel(logging.DEBUG)
95
96     result = {}
97
98     sfc = Sfc()
99     sfc.setup()
100     sfc.run(result)
101     print result
102     sfc.teardown()
103
104 if __name__ == '__main__':
105     _test()'''