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