Merge "add memory_load scenario"
authorliang gao <jean.gaoliang@huawei.com>
Tue, 24 May 2016 07:37:16 +0000 (07:37 +0000)
committerGerrit Code Review <gerrit@172.30.200.206>
Tue, 24 May 2016 07:37:16 +0000 (07:37 +0000)
18 files changed:
docs/userguide/03-installation.rst
run_tests.sh
samples/ramspeed.yaml [new file with mode: 0644]
tests/ci/apexlake-verify [moved from ci/apexlake-verify with 100% similarity]
tests/ci/cover.sh [moved from ci/cover.sh with 100% similarity]
tests/ci/docker/Makefile [moved from ci/docker/Makefile with 100% similarity]
tests/ci/docker/yardstick-ci/Dockerfile [moved from ci/docker/yardstick-ci/Dockerfile with 95% similarity]
tests/ci/docker/yardstick-ci/run_tests.sh [moved from ci/docker/yardstick-ci/run_tests.sh with 94% similarity]
tests/ci/prepare_env.sh [moved from ci/prepare_env.sh with 66% similarity]
tests/ci/requirements.txt [moved from ci/requirements.txt with 100% similarity]
tests/ci/yardstick-verify [moved from ci/yardstick-verify with 100% similarity]
tests/opnfv/test_suites/opnfv_lf-pod1_daily.yaml [moved from tests/opnfv/test_suites/opnfv_opnfv-jump-1_daily.yaml with 100% similarity]
tests/opnfv/test_suites/opnfv_lf-pod2_daily.yaml [moved from tests/opnfv/test_suites/opnfv_opnfv-jump-2_daily.yaml with 100% similarity]
tests/unit/benchmark/scenarios/compute/test_ramspeed.py [new file with mode: 0644]
tools/ubuntu-server-cloudimg-modify.sh
yardstick/benchmark/scenarios/compute/ramspeed.py [new file with mode: 0644]
yardstick/benchmark/scenarios/compute/ramspeed_mark_benchmark.bash [new file with mode: 0644]
yardstick/benchmark/scenarios/compute/ramspeed_mem_benchmark.bash [new file with mode: 0644]

index f68c1d9..1a74955 100644 (file)
@@ -1,7 +1,7 @@
 .. This work is licensed under a Creative Commons Attribution 4.0 International
 .. License.
 .. http://creativecommons.org/licenses/by/4.0
-.. (c) OPNFV, Ericsson AB and others.
+.. (c) OPNFV, Ericsson AB, Huawei Technologies Co.,Ltd and others.
 
 Yardstick Installation
 ======================
@@ -155,7 +155,10 @@ Pull the Yardstick-CI Docker image from Docker hub:
 
 ::
 
-  docker pull opnfv/yardstick-ci
+  docker pull opnfv/yardstick:$DOCKER_TAG
+
+Where ``$DOCKER_TAG`` is latest for master branch, as for the release branches,
+this coincides with its release name, such as brahmaputra.1.0.
 
 Run the Docker image:
 
@@ -167,11 +170,15 @@ Run the Docker image:
     -t \
     -e "INSTALLER_TYPE=${INSTALLER_TYPE}" \
     -e "INSTALLER_IP=${INSTALLER_IP}" \
-    opnfv/yardstick-ci \
-    run_benchmarks
-
-Where ``${INSTALLER_TYPE}`` can be fuel, foreman or compass and ``${INSTALLER_IP}``
-is the installer master node IP address (i.e. 10.20.0.2 is default for fuel).
+    opnfv/yardstick \
+    run_tests.sh ${YARDSTICK_DB_BACKEND} ${YARDSTICK_SUITE_NAME}
+
+Where ``${INSTALLER_TYPE}`` can be apex, compass, fuel or joid, ``${INSTALLER_IP}``
+is the installer master node IP address (i.e. 10.20.0.2 is default for fuel). ``${YARDSTICK_DB_BACKEND}``
+is the IP and port number of DB, ``${YARDSTICK_SUITE_NAME}`` is the test suite you want to run.
+For more details, please refer to the Jenkins job defined in Releng project, labconfig information
+and sshkey are required. See the link
+https://git.opnfv.org/cgit/releng/tree/jjb/yardstick/yardstick-ci-jobs.yml.
 
 Basic steps performed by the **Yardstick-CI** container:
 
index e093a20..82c8251 100755 (executable)
@@ -54,7 +54,7 @@ run_tests() {
 }
 
 run_coverage() {
-    source ci/cover.sh
+    source tests/ci/cover.sh
     run_coverage_test
 }
 
diff --git a/samples/ramspeed.yaml b/samples/ramspeed.yaml
new file mode 100644 (file)
index 0000000..7e1b1aa
--- /dev/null
@@ -0,0 +1,38 @@
+---
+# Sample benchmark task config file
+# measure cache and memory bandwidth using Ramspeed
+
+schema: "yardstick:task:0.1"
+
+scenarios:
+-
+  type: Ramspeed
+  options:
+    type_id: 1
+    load: 16
+    block_size: 32
+    iteration: 1
+
+  host: kratos.demo
+
+  runner:
+    type: Iteration
+    iterations: 1
+
+  sla:
+    min_bandwidth: 6000
+    action: monitor
+
+context:
+  name: demo
+  image: yardstick-trusty-server
+  flavor: yardstick-flavor
+  user: ubuntu
+
+  servers:
+    kratos:
+      floating_ip: true
+
+  networks:
+    test:
+      cidr: '10.0.1.0/24'
similarity index 100%
rename from ci/apexlake-verify
rename to tests/ci/apexlake-verify
similarity index 100%
rename from ci/cover.sh
rename to tests/ci/cover.sh
similarity index 100%
rename from ci/docker/Makefile
rename to tests/ci/docker/Makefile
similarity index 95%
rename from ci/docker/yardstick-ci/Dockerfile
rename to tests/ci/docker/yardstick-ci/Dockerfile
index 91d29da..a2164a8 100644 (file)
@@ -44,7 +44,7 @@ RUN git clone https://gerrit.opnfv.org/gerrit/releng ${RELENG_REPO_DIR}
 
 # install yardstick + dependencies
 RUN cd ${YARDSTICK_REPO_DIR} && easy_install -U pip
-RUN cd ${YARDSTICK_REPO_DIR} && pip install -r ci/requirements.txt
+RUN cd ${YARDSTICK_REPO_DIR} && pip install -r tests/ci/requirements.txt
 RUN cd ${YARDSTICK_REPO_DIR} && pip install .
 
 ADD http://download.cirros-cloud.net/0.3.3/cirros-0.3.3-x86_64-disk.img /home/opnfv/images/
similarity index 94%
rename from ci/docker/yardstick-ci/run_tests.sh
rename to tests/ci/docker/yardstick-ci/run_tests.sh
index 3b7cea3..680a329 100755 (executable)
@@ -49,7 +49,7 @@ git checkout master && git pull
 git_checkout $YARDSTICK_BRANCH $YARDSTICK_REPO
 
 # setup the environment
-source $YARDSTICK_REPO_DIR/ci/prepare_env.sh
+source $YARDSTICK_REPO_DIR/tests/ci/prepare_env.sh
 
 # run tests
-$YARDSTICK_REPO_DIR/ci/yardstick-verify $@
+$YARDSTICK_REPO_DIR/tests/ci/yardstick-verify $@
similarity index 66%
rename from ci/prepare_env.sh
rename to tests/ci/prepare_env.sh
index 8f9f580..ed832bc 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/bash
 ##############################################################################
-# Copyright (c) 2015 Ericsson AB and others.
+# Copyright (c) 2015 Ericsson AB, 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
@@ -10,8 +10,6 @@
 
 # Perepare the environment to run yardstick ci
 
-: ${INSTALLER_TYPE:='fuel'}
-: ${INSTALLER_IP:='10.20.0.2'}
 : ${DEPLOY_TYPE:='bm'} # Can be any of 'bm' (Bare Metal) or 'virt' (Virtual)
 
 : ${NODE_NAME:='unknown'}
 #  e.g. EXTERNAL_NETWORK='ext-net;flat;192.168.0.2;192.168.0.253;192.168.0.1;192.168.0.0/24'
 export EXTERNAL_NETWORK=$(echo $EXTERNAL_NETWORK | cut -f1 -d \;)
 
-echo
-echo "INFO: Creating openstack credentials .."
-
 # Create openstack credentials
+echo "INFO: Creating openstack credentials .."
 OPENRC=/home/opnfv/openrc
+INSTALLERS=(apex compass fuel joid)
+
 if [ ! -f $OPENRC ]; then
+    # credentials file is not given, check if environment variables are set
+    # to get the creds using fetch_os_creds.sh later on
+    echo "INFO: Checking environment variables INSTALLER_TYPE and INSTALLER_IP"
+    if [ -z ${INSTALLER_TYPE} ]; then
+        echo "environment variable 'INSTALLER_TYPE' is not defined."
+        exit 1
+    elif [[ ${INSTALLERS[@]} =~ ${INSTALLER_TYPE} ]]; then
+        echo "INSTALLER_TYPE env variable found: ${INSTALLER_TYPE}"
+    else
+        echo "Invalid env variable INSTALLER_TYPE=${INSTALLER_TYPE}"
+        exit 1
+    fi
+
     if [ "$DEPLOY_TYPE" == "virt" ]; then
         FETCH_CRED_ARG="-v -d $OPENRC -i ${INSTALLER_TYPE} -a ${INSTALLER_IP}"
     else
diff --git a/tests/unit/benchmark/scenarios/compute/test_ramspeed.py b/tests/unit/benchmark/scenarios/compute/test_ramspeed.py
new file mode 100644 (file)
index 0000000..3de84c7
--- /dev/null
@@ -0,0 +1,239 @@
+#!/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.ramspeed.Ramspeed
+
+import mock
+import unittest
+import json
+
+from yardstick.benchmark.scenarios.compute import ramspeed
+
+
+@mock.patch('yardstick.benchmark.scenarios.compute.ramspeed.ssh')
+class RamspeedTestCase(unittest.TestCase):
+
+    def setUp(self):
+        self.ctx = {
+            'host': {
+                'ip': '172.16.0.137',
+                'user': 'root',
+                'key_filename': "mykey.key"
+            }
+        }
+
+        self.result = {}
+
+    def test_ramspeed_successful_setup(self, mock_ssh):
+
+        r = ramspeed.Ramspeed({}, self.ctx)
+        mock_ssh.SSH().execute.return_value = (0, '', '')
+
+        r.setup()
+        self.assertIsNotNone(r.client)
+        self.assertTrue(r.setup_done, True)
+
+    def test_ramspeed_successful__run_no_sla(self, mock_ssh):
+
+        options = {
+            "test_id": 1,
+            "load": 16,
+            "block_size": 32
+        }
+        args = {"options": options}
+        r = ramspeed.Ramspeed(args, self.ctx)
+
+        sample_output = '{"Result": [{"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 1, "Bandwidth(MBps)": 19909.18}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 2, "Bandwidth(MBps)": 19873.89},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4, "Bandwidth(MBps)":\
+ 19907.56}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 8,\
+ "Bandwidth(MBps)": 19906.94}, {"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 16, "Bandwidth(MBps)": 19881.74}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 32, "Bandwidth(MBps)": 19395.65},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 64, "Bandwidth(MBps)":\
+ 17623.14}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 128,\
+ "Bandwidth(MBps)": 17677.36}, {"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 256, "Bandwidth(MBps)": 16113.49}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 512, "Bandwidth(MBps)": 14659.19},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 1024, "Bandwidth(MBps)":\
+ 14680.75}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 2048,\
+ "Bandwidth(MBps)": 14756.45}, {"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 4096, "Bandwidth(MBps)": 14604.44}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 8192, "Bandwidth(MBps)": 14159.86},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 16384, "Bandwidth(MBps)":\
+ 14128.94}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 32768,\
+ "Bandwidth(MBps)": 8340.85}]}'
+        mock_ssh.SSH().execute.return_value = (0, sample_output, '')
+        r.run(self.result)
+        expected_result = json.loads(sample_output)
+        self.assertEqual(self.result, expected_result)
+
+    def test_ramspeed_successful_run_sla(self, mock_ssh):
+
+        options = {
+            "test_id": 1,
+            "load": 16,
+            "block_size": 32
+        }
+        args = {"options": options, "sla": {"min_bandwidth": 6000}}
+        r = ramspeed.Ramspeed(args, self.ctx)
+
+        sample_output = '{"Result": [{"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 1, "Bandwidth(MBps)": 19909.18}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 2, "Bandwidth(MBps)": 19873.89},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4, "Bandwidth(MBps)":\
+ 19907.56}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 8,\
+ "Bandwidth(MBps)": 19906.94}, {"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 16, "Bandwidth(MBps)": 19881.74}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 32, "Bandwidth(MBps)": 19395.65},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 64, "Bandwidth(MBps)":\
+ 17623.14}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 128,\
+ "Bandwidth(MBps)": 17677.36}, {"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 256, "Bandwidth(MBps)": 16113.49}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 512, "Bandwidth(MBps)": 14659.19},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 1024, "Bandwidth(MBps)":\
+ 14680.75}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 2048,\
+ "Bandwidth(MBps)": 14756.45}, {"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 4096, "Bandwidth(MBps)": 14604.44}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 8192, "Bandwidth(MBps)": 14159.86},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 16384, "Bandwidth(MBps)":\
+ 14128.94}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 32768,\
+ "Bandwidth(MBps)": 8340.85}]}'
+        mock_ssh.SSH().execute.return_value = (0, sample_output, '')
+        r.run(self.result)
+        expected_result = json.loads(sample_output)
+        self.assertEqual(self.result, expected_result)
+
+    def test_ramspeed_unsuccessful_run_sla(self, mock_ssh):
+        options = {
+            "test_id": 1,
+            "load": 8,
+            "block_size": 64
+        }
+        args = {"options": options, "sla": {"min_bandwidth": 100000}}
+        r = ramspeed.Ramspeed(args, self.ctx)
+
+        sample_output = '{"Result": [{"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 1, "Bandwidth(MBps)": 5000.18}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 2, "Bandwidth(MBps)": 5000.89},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4,\
+ "Bandwidth(MBps)": 5000.56}, {"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 8, "Bandwidth(MBps)": 19906.94}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 16, "Bandwidth(MBps)": 19881.74},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 32,\
+ "Bandwidth(MBps)": 19395.65}, {"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 64, "Bandwidth(MBps)": 17623.14}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 128, "Bandwidth(MBps)": 17677.36},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 256, "Bandwidth(MBps)":\
+ 16113.49}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 512,\
+ "Bandwidth(MBps)": 14659.19}, {"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 1024, "Bandwidth(MBps)": 14680.75}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 2048, "Bandwidth(MBps)": 14756.45},\
+ {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 4096, "Bandwidth(MBps)":\
+ 14604.44}, {"Test_type": "INTEGER & WRITING", "Block_size(kb)": 8192,\
+ "Bandwidth(MBps)": 14159.86}, {"Test_type": "INTEGER & WRITING",\
+ "Block_size(kb)": 16384, "Bandwidth(MBps)": 14128.94}, {"Test_type":\
+ "INTEGER & WRITING", "Block_size(kb)": 32768, "Bandwidth(MBps)": 8340.85}]}'
+        mock_ssh.SSH().execute.return_value = (0, sample_output, '')
+        self.assertRaises(AssertionError, r.run, self.result)
+
+    def test_ramspeed_unsuccessful_script_error(self, mock_ssh):
+        options = {
+            "test_id": 1,
+            "load": 16,
+            "block_size": 32
+        }
+        args = {"options": options}
+        r = ramspeed.Ramspeed(args, self.ctx)
+
+        mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
+        self.assertRaises(RuntimeError, r.run, self.result)
+
+    def test_ramspeed_mem_successful_run_no_sla(self, mock_ssh):
+        options = {
+            "test_id": 3,
+            "load": 16,
+            "block_size": 32,
+            "iteration": 1
+        }
+        args = {"options": options}
+        r = ramspeed.Ramspeed(args, self.ctx)
+
+        sample_output = '{"Result": [{"Test_type": "INTEGER Copy:",\
+ "Bandwidth(MBps)": 8353.97}, {"Test_type": "INTEGER Scale:",\
+ "Bandwidth(MBps)": 9078.59}, {"Test_type": "INTEGER Add:",\
+ "Bandwidth(MBps)": 10057.48}, {"Test_type": "INTEGER Triad:",\
+ "Bandwidth(MBps)": 10116.27}, {"Test_type": "INTEGER AVERAGE:",\
+ "Bandwidth(MBps)": 9401.58}]}'
+        mock_ssh.SSH().execute.return_value = (0, sample_output, '')
+        r.run(self.result)
+        expected_result = json.loads(sample_output)
+        self.assertEqual(self.result, expected_result)
+
+    def test_ramspeed_mem_successful_run_sla(self, mock_ssh):
+        options = {
+            "test_id": 3,
+            "load": 16,
+            "block_size": 32,
+            "iteration": 1
+        }
+        args = {"options": options, "sla": {"min_bandwidth": 6000}}
+        r = ramspeed.Ramspeed(args, self.ctx)
+
+        sample_output = '{"Result": [{"Test_type": "INTEGER Copy:",\
+ "Bandwidth(MBps)": 8353.97}, {"Test_type": "INTEGER Scale:",\
+ "Bandwidth(MBps)": 9078.59}, {"Test_type": "INTEGER Add:",\
+ "Bandwidth(MBps)": 10057.48}, {"Test_type": "INTEGER Triad:",\
+ "Bandwidth(MBps)": 10116.27}, {"Test_type": "INTEGER AVERAGE:",\
+ "Bandwidth(MBps)": 9401.58}]}'
+        mock_ssh.SSH().execute.return_value = (0, sample_output, '')
+        r.run(self.result)
+        expected_result = json.loads(sample_output)
+        self.assertEqual(self.result, expected_result)
+
+    def test_ramspeed_mem_unsuccessful_run_sla(self, mock_ssh):
+        options = {
+            "test_id": 3,
+            "load": 16,
+            "block_size": 32,
+            "iteration": 1
+        }
+        args = {"options": options, "sla": {"min_bandwidth": 86000}}
+        r = ramspeed.Ramspeed(args, self.ctx)
+
+        sample_output = '{"Result": [{"Test_type": "INTEGER Copy:",\
+ "Bandwidth(MBps)": 4000.97}, {"Test_type": "INTEGER Scale:",\
+ "Bandwidth(MBps)": 4400.59}, {"Test_type": "INTEGER Add:",\
+ "Bandwidth(MBps)": 4300.48}, {"Test_type": "INTEGER Triad:",\
+ "Bandwidth(MBps)": 1300.27}, {"Test_type": "INTEGER AVERAGE:",\
+ "Bandwidth(MBps)": 2401.58}]}'
+        mock_ssh.SSH().execute.return_value = (0, sample_output, '')
+        self.assertRaises(AssertionError, r.run, self.result)
+
+    def test_ramspeed_unsuccessful_unknown_type_run(self, mock_ssh):
+        options = {
+            "test_id": 30,
+            "load": 16,
+            "block_size": 32
+        }
+        args = {'options': options}
+        r = ramspeed.Ramspeed(args, self.ctx)
+
+        mock_ssh.SSH().execute.return_value = (1, '', 'No such type_id: 30 for Ramspeed scenario')
+        self.assertRaises(RuntimeError, r.run, self.result)
+
+
+def main():
+    unittest.main()
+
+if __name__ == '__main__':
+    main()
index 78bf098..f9e0a2c 100755 (executable)
@@ -62,5 +62,12 @@ apt-get install -y \
 
 git clone https://github.com/kdlucas/byte-unixbench.git /opt/tempT
 make --directory /opt/tempT/UnixBench/
+
+
+git clone https://github.com/beefyamoeba5/ramspeed.git /opt/tempT2
+cd /opt/tempT2/ramspeed-2.6.0
+mkdir temp
+bash build.sh
+
 # restore symlink
 ln -sf /run/resolvconf/resolv.conf /etc/resolv.conf
diff --git a/yardstick/benchmark/scenarios/compute/ramspeed.py b/yardstick/benchmark/scenarios/compute/ramspeed.py
new file mode 100644 (file)
index 0000000..819ef76
--- /dev/null
@@ -0,0 +1,142 @@
+##############################################################################
+# 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 Ramspeed(base.Scenario):
+    """Execute ramspeed benchmark in a host
+    The ramspeed script takes a number of options which you can use to
+    customise a test.  The full run time usage
+    is:
+
+    ramspeed -b ID [-g size] [-m size] [-l runs] [-r speed-format]
+
+    -b  runs a specified benchmark (by an ID number):
+       1 -- INTmark [writing]          4 -- FLOATmark [writing]
+       2 -- INTmark [reading]          5 -- FLOATmark [reading]
+       3 -- INTmem                     6 -- FLOATmem
+       7 -- MMXmark [writing]          10 -- SSEmark [writing]
+       8 -- MMXmark [reading]          11 -- SSEmark [reading]
+       9 -- MMXmem                     12 -- SSEmem
+       13 -- MMXmark (nt) [writing]    16 -- SSEmark (nt) [writing]
+       14 -- MMXmark (nt) [reading]    17 -- SSEmark (nt) [reading]
+       15 -- MMXmem (nt)               18 -- SSEmem (nt)
+    In this scenario, only the first 6 test type will be used for testing.
+
+    -g  specifies a # of Gbytes per pass (default is 8)
+    -m  specifies a # of Mbytes per array (default is 32)
+    -l  enables the BatchRun mode (for *mem benchmarks only),
+       and specifies a # of runs (suggested is 5)
+    -r  displays speeds in real megabytes per second (default: decimal)
+
+    The -b option is required, others are recommended.
+
+    Parameters
+        type_id - specifies whether to run *mark benchmark or *mem benchmark
+                  the type_id can be any number from 1 to 19
+            type:       int
+            unit:       n/a
+            default:    1
+        load - specifies a # of Gbytes per pass
+            type:       int
+            unit:       gigabyte
+            default:    8
+        block_size - specifies a # of Mbytes per array
+            type:       int
+            unit:       megabyte
+            default:    32
+
+    Parameters for *mem benchmark
+        iteration - specifies a # of runs for each test
+            type:       int
+            unit:       n/a
+            default:    1
+    more info http://alasir.com/software/ramspeed
+    """
+    __scenario_type__ = "Ramspeed"
+
+    RAMSPEED_MARK_SCRIPT = "ramspeed_mark_benchmark.bash"
+    RAMSPEED_MEM_SCRIPT = "ramspeed_mem_benchmark.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.mark_target_script = pkg_resources.resource_filename(
+            "yardstick.benchmark.scenarios.compute",
+            Ramspeed.RAMSPEED_MARK_SCRIPT)
+        self.mem_target_script = pkg_resources.resource_filename(
+            "yardstick.benchmark.scenarios.compute",
+            Ramspeed.RAMSPEED_MEM_SCRIPT)
+
+        host = self.context_cfg["host"]
+        user = host.get("user", "ubuntu")
+        ip = host.get("ip", None)
+        key_filename = host.get('key_filename', "~/.ssh/id_rsa")
+
+        LOG.info("user:%s, host:%s", user, ip)
+        self.client = ssh.SSH(user, ip, key_filename=key_filename)
+        self.client.wait(timeout=600)
+
+        # copy scripts to host
+        self.client.run("cat > ~/ramspeed_mark_benchmark.sh",
+                        stdin=open(self.mark_target_script, 'rb'))
+        self.client.run("cat > ~/ramspeed_mem_benchmark.sh",
+                        stdin=open(self.mem_target_script, 'rb'))
+        self.setup_done = True
+
+    def run(self, result):
+        """execute the benchmark"""
+
+        if not self.setup_done:
+            self.setup()
+
+        options = self.scenario_cfg['options']
+        test_id = options.get('type_id', 1)
+        load = options.get('load', 8)
+        block_size = options.get('block_size', 32)
+
+        if test_id == 3 or test_id == 6:
+            iteration = options.get('iteration', 1)
+            cmd = "sudo bash ramspeed_mem_benchmark.sh %d %d %d %d" % \
+                  (test_id, load, block_size, iteration)
+        elif 0 < test_id <= 5:
+            cmd = "sudo bash ramspeed_mark_benchmark.sh %d %d %d" % \
+                  (test_id, load, block_size)
+        # only the test_id 1-6 will be used in this scenario
+        else:
+            raise RuntimeError("No such type_id: %s for Ramspeed scenario",
+                               test_id)
+
+        LOG.debug("Executing command: %s", cmd)
+        status, stdout, stderr = self.client.execute(cmd)
+        if status:
+            raise RuntimeError(stderr)
+
+        result.update(json.loads(stdout))
+
+        if "sla" in self.scenario_cfg:
+            sla_error = ""
+            sla_min_bw = int(self.scenario_cfg['sla']['min_bandwidth'])
+            for i in result["Result"]:
+                bw = i["Bandwidth(MBps)"]
+                if bw < sla_min_bw:
+                    sla_error += "Bandwidth %f < " \
+                        "sla:min_bandwidth(%f)" % (bw, sla_min_bw)
+            assert sla_error == "", sla_error
diff --git a/yardstick/benchmark/scenarios/compute/ramspeed_mark_benchmark.bash b/yardstick/benchmark/scenarios/compute/ramspeed_mark_benchmark.bash
new file mode 100644 (file)
index 0000000..fcb6559
--- /dev/null
@@ -0,0 +1,46 @@
+#!/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
+##############################################################################
+
+# Run a ramspeed memory bandwidth benchmark in a host and
+# output in json format the memory bandwidth in megabytes per second
+
+set -e
+
+TYPE_ID=$1
+LOAD=$2
+BLOCK_SIZE=$3
+OUTPUT_FILE=/tmp/ramspeed-out.log
+
+run_ramspeed()
+{
+    cd /opt/tempT2/ramspeed-2.6.0/
+    ./ramspeed -b $TYPE_ID -g $LOAD -m $BLOCK_SIZE > $OUTPUT_FILE
+}
+
+# write the result to stdout in json format
+output_json()
+{
+   SCORE=$(awk '/  /{printf "{\"Test_type\": \"%s %s %s\", \"Block_size(kb)\": %s, \"Bandwidth(MBps)\": %s},", $1, $2, $3, $4, $7}' $OUTPUT_FILE)
+   echo -e "{ \
+       \"Result\":[${SCORE%?}] \
+   }"
+}
+
+main()
+{
+    # run the test
+    run_ramspeed
+
+    #output result
+    output_json
+}
+
+main
diff --git a/yardstick/benchmark/scenarios/compute/ramspeed_mem_benchmark.bash b/yardstick/benchmark/scenarios/compute/ramspeed_mem_benchmark.bash
new file mode 100644 (file)
index 0000000..69c2934
--- /dev/null
@@ -0,0 +1,47 @@
+#!/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
+##############################################################################
+
+# Run a ramspeed memory bandwidth benchmark in a host and
+# output in json format the memory bandwidth in megabytes per second
+
+set -e
+
+TYPE_ID=$1
+LOAD=$2
+BLOCK_SIZE=$3
+ITERATION=$4
+OUTPUT_FILE=/tmp/ramspeed-out.log
+
+run_ramspeed()
+{
+    cd /opt/tempT2/ramspeed-2.6.0/
+    ./ramspeed -b $TYPE_ID -g $LOAD -m $BLOCK_SIZE -l $ITERATION > $OUTPUT_FILE
+}
+
+# write the result to stdout in json format
+output_json()
+{
+   SCORE=$(awk '/  /{printf "{\"Test_type\": \"%s %s\", \"Bandwidth(MBps)\": %s},", $1, $2, $3}' $OUTPUT_FILE)
+   echo -e "{ \
+      \"Result\":[${SCORE%?}] \
+   }"
+}
+
+main()
+{
+    # run the test
+    run_ramspeed
+
+    # output result
+    output_json
+}
+
+main