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