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 ##############################################################################
13 import yardstick.ssh as ssh
14 from yardstick.benchmark.scenarios import base
16 LOG = logging.getLogger(__name__)
19 class ComputeCapacity(base.Scenario):
20 """Measure compute capacity and scale.
22 This scenario reads hardware specification, including number of cpus,
23 number of cores, number of threads, available memory size and total cache
26 __scenario_type__ = "ComputeCapacity"
27 TARGET_SCRIPT = "computecapacity.bash"
29 def __init__(self, scenario_cfg, context_cfg):
30 self.scenario_cfg = scenario_cfg
31 self.context_cfg = context_cfg
32 self.setup_done = False
36 self.target_script = pkg_resources.resource_filename(
37 "yardstick.benchmark.scenarios.compute",
38 ComputeCapacity.TARGET_SCRIPT)
40 nodes = self.context_cfg['nodes']
41 node = nodes.get('host', None)
42 host_user = node.get('user', 'ubuntu')
43 host_ip = node.get('ip', None)
44 host_pwd = node.get('password', 'root')
45 LOG.debug("user:%s, host:%s", host_user, host_ip)
46 self.client = ssh.SSH(host_user, host_ip, password=host_pwd)
47 self.client.wait(timeout=600)
50 self.client.run("cat > ~/computecapacity.sh",
51 stdin=open(self.target_script, 'rb'))
53 self.setup_done = True
55 def run(self, result):
56 """execute the benchmark"""
58 if not self.setup_done:
61 cmd = "sudo bash computecapacity.sh"
63 LOG.debug("Executing command: %s", cmd)
64 status, stdout, stderr = self.client.execute(cmd)
66 raise RuntimeError(stderr)
68 result.update(json.loads(stdout))