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 ComputeCapacity(base.Scenario):
23 """Measure compute capacity and scale.
25 This scenario reads hardware specification, including number of cpus,
26 number of cores, number of threads, available memory size and total cache
29 __scenario_type__ = "ComputeCapacity"
30 TARGET_SCRIPT = "computecapacity.bash"
32 def __init__(self, scenario_cfg, context_cfg):
33 self.scenario_cfg = scenario_cfg
34 self.context_cfg = context_cfg
35 self.setup_done = False
39 self.target_script = pkg_resources.resource_filename(
40 "yardstick.benchmark.scenarios.compute",
41 ComputeCapacity.TARGET_SCRIPT)
43 nodes = self.context_cfg['nodes']
44 node = nodes.get('host', None)
45 host_user = node.get('user', 'ubuntu')
46 ssh_port = node.get('ssh_port', ssh.DEFAULT_PORT)
47 host_ip = node.get('ip', None)
48 host_pwd = node.get('password', 'root')
49 LOG.debug("user:%s, host:%s", host_user, host_ip)
50 self.client = ssh.SSH(host_user, host_ip, password=host_pwd,
52 self.client.wait(timeout=600)
55 self.client._put_file_shell(self.target_script, '~/computecapacity.sh')
57 self.setup_done = True
59 def run(self, result):
60 """execute the benchmark"""
62 if not self.setup_done:
65 cmd = "sudo bash computecapacity.sh"
67 LOG.debug("Executing command: %s", cmd)
68 status, stdout, stderr = self.client.execute(cmd)
70 raise RuntimeError(stderr)
72 result.update(jsonutils.loads(stdout))