1 ##############################################################################
\r
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
\r
4 # All rights reserved. This program and the accompanying materials
\r
5 # are made available under the terms of the Apache License, Version 2.0
\r
6 # which accompanies this distribution, and is available at
\r
7 # http://www.apache.org/licenses/LICENSE-2.0
\r
8 ##############################################################################
\r
13 import yardstick.ssh as ssh
\r
14 from yardstick.benchmark.scenarios import base
\r
16 LOG = logging.getLogger(__name__)
\r
19 class NetworkCapacity(base.Scenario):
\r
20 """Measure Network capacity and scale.
\r
22 This scenario reads network status including number of connections,
\r
23 number of frames sent/received.
\r
25 __scenario_type__ = "NetworkCapacity"
\r
26 TARGET_SCRIPT = "networkcapacity.bash"
\r
28 def __init__(self, scenario_cfg, context_cfg):
\r
29 self.scenario_cfg = scenario_cfg
\r
30 self.context_cfg = context_cfg
\r
31 self.setup_done = False
\r
34 """scenario setup"""
\r
35 self.target_script = pkg_resources.resource_filename(
\r
36 "yardstick.benchmark.scenarios.networking",
\r
37 NetworkCapacity.TARGET_SCRIPT)
\r
39 host = self.context_cfg['host']
\r
41 raise RuntimeError('No right node.please check the configuration')
\r
42 host_user = host.get('user', 'ubuntu')
\r
43 ssh_port = host.get("ssh_port", ssh.DEFAULT_PORT)
\r
44 host_ip = host.get('ip', None)
\r
45 host_pwd = host.get('password', None)
\r
47 LOG.debug("user:%s, host:%s", host_user, host_ip)
\r
48 self.client = ssh.SSH(host_user, host_ip, password=host_pwd,
\r
50 self.client.wait(timeout=600)
\r
52 # copy script to host
\r
53 self.client.run("cat > ~/networkcapacity.sh",
\r
54 stdin=open(self.target_script, 'rb'))
\r
56 self.setup_done = True
\r
58 def run(self, result):
\r
59 """execute the benchmark"""
\r
61 if not self.setup_done:
\r
64 cmd = "sudo bash networkcapacity.sh"
\r
66 LOG.debug("Executing command: %s", cmd)
\r
67 status, stdout, stderr = self.client.execute(cmd)
\r
69 raise RuntimeError(stderr)
\r
71 result.update(json.loads(stdout))
\r