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 self.client = ssh.SSH.from_node(node, defaults={
46 "user": "ubuntu", "password": "root"
48 self.client.wait(timeout=600)
51 self.client._put_file_shell(self.target_script, '~/computecapacity.sh')
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(jsonutils.loads(stdout))