aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--samples/computecapacity.yaml24
-rw-r--r--tests/unit/benchmark/scenarios/compute/test_computecapacity.py63
-rw-r--r--yardstick/benchmark/scenarios/compute/computecapacity.bash55
-rw-r--r--yardstick/benchmark/scenarios/compute/computecapacity.py68
4 files changed, 210 insertions, 0 deletions
diff --git a/samples/computecapacity.yaml b/samples/computecapacity.yaml
new file mode 100644
index 000000000..0c6d46bf1
--- /dev/null
+++ b/samples/computecapacity.yaml
@@ -0,0 +1,24 @@
+---
+# Sample benchmark task config file
+# Measure compute capacity and scale.
+# Including number of cores, number of threads, available memory size and
+# cache size.
+
+schema: "yardstick:task:0.1"
+
+scenarios:
+-
+ type: ComputeCapacity
+ options:
+
+ nodes:
+ host1: node5.LF
+
+ runner:
+ type: Iteration
+ iterations: 1
+
+context:
+ type: Node
+ name: LF
+ file: /root/yardstick/etc/yardstick/nodes/compass_sclab_virtual/pod.yaml
diff --git a/tests/unit/benchmark/scenarios/compute/test_computecapacity.py b/tests/unit/benchmark/scenarios/compute/test_computecapacity.py
new file mode 100644
index 000000000..5745b7ec9
--- /dev/null
+++ b/tests/unit/benchmark/scenarios/compute/test_computecapacity.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# Unittest for yardstick.benchmark.scenarios.compute.computecapacity.ComputeCapacity
+
+import mock
+import unittest
+import os
+import json
+
+from yardstick.benchmark.scenarios.compute import computecapacity
+
+SAMPLE_OUTPUT = '{"Cpu_number": "2", "Core_number": "24",\
+ "Memory_size": "263753976 kB", "Thread_number": "48",\
+ "Cache_size": "30720 KB"}'
+
+
+@mock.patch('yardstick.benchmark.scenarios.compute.computecapacity.ssh')
+class ComputeCapacityTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.ctx = {
+ 'nodes': {
+ 'host1': {
+ 'ip': '172.16.0.137',
+ 'user': 'cirros',
+ 'key_filename': "mykey.key",
+ 'password': "root"
+ },
+ }
+ }
+
+ self.result = {}
+
+ def test_capacity_successful_setup(self, mock_ssh):
+ c = computecapacity.ComputeCapacity({}, self.ctx)
+ mock_ssh.SSH().execute.return_value = (0, '', '')
+
+ c.setup()
+ self.assertIsNotNone(c.client)
+ self.assertTrue(c.setup_done)
+
+ def test_capacity_successful(self, mock_ssh):
+ c = computecapacity.ComputeCapacity({}, self.ctx)
+
+ mock_ssh.SSH().execute.return_value = (0, SAMPLE_OUTPUT, '')
+ c.run(self.result)
+ expected_result = json.loads(SAMPLE_OUTPUT)
+ self.assertEqual(self.result, expected_result)
+
+ def test_capacity_unsuccessful_script_error(self, mock_ssh):
+ c = computecapacity.ComputeCapacity({}, self.ctx)
+
+ mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
+ self.assertRaises(RuntimeError, c.run, self.result)
diff --git a/yardstick/benchmark/scenarios/compute/computecapacity.bash b/yardstick/benchmark/scenarios/compute/computecapacity.bash
new file mode 100644
index 000000000..98d4b8fb5
--- /dev/null
+++ b/yardstick/benchmark/scenarios/compute/computecapacity.bash
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+# Measure compute capacity and scale of a host
+
+set -e
+
+# run capacity test
+run_capacity()
+{
+ # Number of CPUs
+ CPU=$(grep 'physical id' /proc/cpuinfo | sort -u | wc -l)
+ # Number of physical cores in a single CPU
+ CORE=$(grep 'core id' /proc/cpuinfo | sort -u | wc -l)
+ # Total physical core number
+ CORES=$[$CPU * $CORE]
+ # Number of logical cores
+ THREAD=$(grep 'processor' /proc/cpuinfo | sort -u | wc -l)
+ # Total memory size
+ MEMORY=$(grep 'MemTotal' /proc/meminfo | sort -u)
+ ME=$(echo $MEMORY | awk '/ /{printf "%s %s", $2, $3}')
+ # Cache size per CPU
+ CACHE=$(grep 'cache size' /proc/cpuinfo | sort -u)
+ CA=$(echo $CACHE | awk '/ /{printf "%s", $4}')
+ CACHES=$[$CA * $CPU]
+}
+
+# write the result to stdout in json format
+output_json()
+{
+ echo -e "{ \
+ \"Cpu_number\":\"$CPU\", \
+ \"Core_number\":\"$CORES\", \
+ \"Thread_number\":\"$THREAD\", \
+ \"Memory_size\": \"$ME\", \
+ \"Cache_size\": \"$CACHES KB\" \
+ }"
+}
+
+main()
+{
+ run_capacity
+
+ output_json
+}
+
+main
diff --git a/yardstick/benchmark/scenarios/compute/computecapacity.py b/yardstick/benchmark/scenarios/compute/computecapacity.py
new file mode 100644
index 000000000..366b470e8
--- /dev/null
+++ b/yardstick/benchmark/scenarios/compute/computecapacity.py
@@ -0,0 +1,68 @@
+##############################################################################
+# Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+import pkg_resources
+import logging
+import json
+
+import yardstick.ssh as ssh
+from yardstick.benchmark.scenarios import base
+
+LOG = logging.getLogger(__name__)
+
+
+class ComputeCapacity(base.Scenario):
+ """Measure compute capacity and scale.
+
+ This scenario reads hardware specification, including number of cpus,
+ number of cores, number of threads, available memory size and total cache
+ size of a host.
+ """
+ __scenario_type__ = "ComputeCapacity"
+ TARGET_SCRIPT = "computecapacity.bash"
+
+ def __init__(self, scenario_cfg, context_cfg):
+ self.scenario_cfg = scenario_cfg
+ self.context_cfg = context_cfg
+ self.setup_done = False
+
+ def setup(self):
+ """scenario setup"""
+ self.target_script = pkg_resources.resource_filename(
+ "yardstick.benchmark.scenarios.compute",
+ ComputeCapacity.TARGET_SCRIPT)
+
+ nodes = self.context_cfg['nodes']
+ node = nodes.get('host1', None)
+ host_user = node.get('user', 'ubuntu')
+ host_ip = node.get('ip', None)
+ host_pwd = node.get('password', 'root')
+ LOG.debug("user:%s, host:%s", host_user, host_ip)
+ self.client = ssh.SSH(host_user, host_ip, password=host_pwd)
+ self.client.wait(timeout=600)
+
+ # copy script to host
+ self.client.run("cat > ~/computecapacity.sh",
+ stdin=open(self.target_script, 'rb'))
+
+ self.setup_done = True
+
+ def run(self, result):
+ """execute the benchmark"""
+
+ if not self.setup_done:
+ self.setup()
+
+ cmd = "sudo bash computecapacity.sh"
+
+ LOG.debug("Executing command: %s", cmd)
+ status, stdout, stderr = self.client.execute(cmd)
+ if status:
+ raise RuntimeError(stderr)
+
+ result.update(json.loads(stdout))