Add Cyclictest scenario and sample 10/1410/7
authorQiLiang <liangqi1@huawei.com>
Mon, 7 Sep 2015 13:55:29 +0000 (21:55 +0800)
committerQiLiang <liangqi1@huawei.com>
Thu, 15 Oct 2015 01:59:34 +0000 (09:59 +0800)
Support measuring operating system's high resolution by using Cyclictest.

JIRA: YARDSTICK-122

Change-Id: I2e00ce117e263deaaf52cd2d663b845bd5b65432
Signed-off-by: QiLiang <liangqi1@huawei.com>
samples/cyclictest.yaml [new file with mode: 0644]
tests/unit/benchmark/scenarios/compute/__init__.py [new file with mode: 0644]
tests/unit/benchmark/scenarios/compute/test_cyclictest.py [new file with mode: 0644]
tools/ubuntu-server-cloudimg-modify.sh
yardstick/benchmark/scenarios/compute/cyclictest.py [new file with mode: 0644]
yardstick/benchmark/scenarios/compute/cyclictest_benchmark.bash [new file with mode: 0644]

diff --git a/samples/cyclictest.yaml b/samples/cyclictest.yaml
new file mode 100644 (file)
index 0000000..6a16bd2
--- /dev/null
@@ -0,0 +1,44 @@
+---
+# Sample benchmark task config file
+# Measure system high resolution by using Cyclictest
+#
+# For this sample just like running the command below on the test vm and
+# getting latencies info back to the yardstick.
+#
+# sudo bash cyclictest -a 1 -i 1000 -p 99 -l 1000 -t 1 -h 90 -m -n -q
+#
+
+schema: "yardstick:task:0.1"
+
+scenarios:
+-
+  type: Cyclictest
+  options:
+    affinity: 1
+    interval: 1000
+    priority: 99
+    loops: 1000
+    threads: 1
+    histogram: 90
+  host: kvm.demo
+  runner:
+    type: Duration
+    duration: 60
+    interval: 1
+  sla:
+    max_min_latency: 50
+    max_avg_latency: 100
+    max_max_latency: 1000
+    action: monitor
+
+context:
+  name: demo
+  image: yardstick-trusty-server
+  flavor: yardstick-flavor
+  user: ec2-user
+  servers:
+    kvm:
+      floating_ip: true
+  networks:
+    test:
+      cidr: "10.0.1.0/24"
diff --git a/tests/unit/benchmark/scenarios/compute/__init__.py b/tests/unit/benchmark/scenarios/compute/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/unit/benchmark/scenarios/compute/test_cyclictest.py b/tests/unit/benchmark/scenarios/compute/test_cyclictest.py
new file mode 100644 (file)
index 0000000..3791b4a
--- /dev/null
@@ -0,0 +1,161 @@
+#!/usr/bin/env python
+
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and other.
+#
+# 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.cyclictest.Cyclictest
+
+import mock
+import unittest
+import json
+
+from yardstick.benchmark.scenarios.compute import cyclictest
+
+
+@mock.patch('yardstick.benchmark.scenarios.compute.cyclictest.ssh')
+class CyclictestTestCase(unittest.TestCase):
+
+    def setUp(self):
+        self.ctx = {
+            "host": "192.168.50.28",
+            "user": "root",
+            "key_filename": "mykey.key"
+        }
+
+    def test_cyclictest_successful_setup(self, mock_ssh):
+
+        c = cyclictest.Cyclictest(self.ctx)
+        c.setup()
+
+        mock_ssh.SSH().execute.return_value = (0, '', '')
+        self.assertIsNotNone(c.client)
+        self.assertEqual(c.setup_done, True)
+
+    def test_cyclictest_successful_no_sla(self, mock_ssh):
+
+        c = cyclictest.Cyclictest(self.ctx)
+        options = {
+            "affinity": 2,
+            "interval": 100,
+            "priority": 88,
+            "loops": 10000,
+            "threads": 2,
+            "histogram": 80
+        }
+        args = {
+            "options": options,
+        }
+        c.server = mock_ssh.SSH()
+
+        sample_output = '{"min": 100, "avg": 500, "max": 1000}'
+        mock_ssh.SSH().execute.return_value = (0, sample_output, '')
+
+        result = c.run(args)
+        expected_result = json.loads(sample_output)
+        self.assertEqual(result, expected_result)
+
+    def test_cyclictest_successful_sla(self, mock_ssh):
+
+        c = cyclictest.Cyclictest(self.ctx)
+        options = {
+            "affinity": 2,
+            "interval": 100,
+            "priority": 88,
+            "loops": 10000,
+            "threads": 2,
+            "histogram": 80
+        }
+        sla = {
+            "max_min_latency": 100,
+            "max_avg_latency": 500,
+            "max_max_latency": 1000,
+        }
+        args = {
+            "options": options,
+            "sla": sla
+        }
+        c.server = mock_ssh.SSH()
+
+        sample_output = '{"min": 100, "avg": 500, "max": 1000}'
+        mock_ssh.SSH().execute.return_value = (0, sample_output, '')
+
+        result = c.run(args)
+        expected_result = json.loads(sample_output)
+        self.assertEqual(result, expected_result)
+
+    def test_cyclictest_unsuccessful_sla_min_latency(self, mock_ssh):
+
+        c = cyclictest.Cyclictest(self.ctx)
+        args = {
+            "options": {},
+            "sla": {"max_min_latency": 10}
+        }
+        c.server = mock_ssh.SSH()
+        sample_output = '{"min": 100, "avg": 500, "max": 1000}'
+
+        mock_ssh.SSH().execute.return_value = (0, sample_output, '')
+        self.assertRaises(AssertionError, c.run, args)
+
+    def test_cyclictest_unsuccessful_sla_avg_latency(self, mock_ssh):
+
+        c = cyclictest.Cyclictest(self.ctx)
+        args = {
+            "options": {},
+            "sla": {"max_avg_latency": 10}
+        }
+        c.server = mock_ssh.SSH()
+        sample_output = '{"min": 100, "avg": 500, "max": 1000}'
+
+        mock_ssh.SSH().execute.return_value = (0, sample_output, '')
+        self.assertRaises(AssertionError, c.run, args)
+
+    def test_cyclictest_unsuccessful_sla_max_latency(self, mock_ssh):
+
+        c = cyclictest.Cyclictest(self.ctx)
+        args = {
+            "options": {},
+            "sla": {"max_max_latency": 10}
+        }
+        c.server = mock_ssh.SSH()
+        sample_output = '{"min": 100, "avg": 500, "max": 1000}'
+
+        mock_ssh.SSH().execute.return_value = (0, sample_output, '')
+        self.assertRaises(AssertionError, c.run, args)
+
+    def test_cyclictest_unsuccessful_script_error(self, mock_ssh):
+
+        c = cyclictest.Cyclictest(self.ctx)
+        options = {
+            "affinity": 2,
+            "interval": 100,
+            "priority": 88,
+            "loops": 10000,
+            "threads": 2,
+            "histogram": 80
+        }
+        sla = {
+            "max_min_latency": 100,
+            "max_avg_latency": 500,
+            "max_max_latency": 1000,
+        }
+        args = {
+            "options": options,
+            "sla": sla
+        }
+        c.server = mock_ssh.SSH()
+
+        mock_ssh.SSH().execute.return_value = (1, '', 'FOOBAR')
+        self.assertRaises(RuntimeError, c.run, args)
+
+
+def main():
+    unittest.main()
+
+if __name__ == '__main__':
+    main()
index 93f2d30..06579ff 100755 (executable)
@@ -40,6 +40,7 @@ apt-get install -y \
     linux-tools-generic \
     lmbench \
     netperf \
+    rt-tests \
     stress
 
 # restore symlink
diff --git a/yardstick/benchmark/scenarios/compute/cyclictest.py b/yardstick/benchmark/scenarios/compute/cyclictest.py
new file mode 100644 (file)
index 0000000..aaa98b8
--- /dev/null
@@ -0,0 +1,157 @@
+##############################################################################
+# Copyright (c) 2015 Huawei Technologies Co.,Ltd and other.
+#
+# 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__)
+LOG.setLevel(logging.DEBUG)
+
+
+class Cyclictest(base.Scenario):
+    """Execute cyclictest benchmark on guest vm
+
+  Parameters
+    affinity - run thread #N on processor #N, if possible
+        type:    int
+        unit:    na
+        default: 1
+    interval - base interval of thread
+        type:    int
+        unit:    us
+        default: 1000
+    loops - number of loops, 0 for endless
+        type:    int
+        unit:    na
+        default: 1000
+    priority - priority of highest prio thread
+        type:    int
+        unit:    na
+        default: 99
+    threads - number of threads
+        type:    int
+        unit:    na
+        default: 1
+    histogram - dump a latency histogram to stdout after the run
+                here set the max time to be tracked
+        type:    int
+        unit:    ms
+        default: 90
+
+    Read link below for more fio args description:
+        https://rt.wiki.kernel.org/index.php/Cyclictest
+    """
+    __scenario_type__ = "Cyclictest"
+
+    TARGET_SCRIPT = "cyclictest_benchmark.bash"
+
+    def __init__(self, context):
+        self.context = context
+        self.setup_done = False
+
+    def setup(self):
+        '''scenario setup'''
+        self.target_script = pkg_resources.resource_filename(
+            "yardstick.benchmark.scenarios.compute",
+            Cyclictest.TARGET_SCRIPT)
+        user = self.context.get("user", "root")
+        host = self.context.get("host", None)
+        key_filename = self.context.get("key_filename", "~/.ssh/id_rsa")
+
+        LOG.debug("user:%s, host:%s", user, host)
+        print "key_filename:" + key_filename
+        self.client = ssh.SSH(user, host, key_filename=key_filename)
+        self.client.wait(timeout=600)
+
+        # copy script to host
+        self.client.run("cat > ~/cyclictest_benchmark.sh",
+                        stdin=open(self.target_script, "rb"))
+
+        self.setup_done = True
+
+    def run(self, args):
+        """execute the benchmark"""
+        default_args = "-m -n -q"
+
+        if not self.setup_done:
+            self.setup()
+
+        options = args["options"]
+        affinity = options.get("affinity", 1)
+        interval = options.get("interval", 1000)
+        priority = options.get("priority", 99)
+        loops = options.get("loops", 1000)
+        threads = options.get("threads", 1)
+        histogram = options.get("histogram", 90)
+
+        cmd_args = "-a %s -i %s -p %s -l %s -t %s -h %s %s" \
+                   % (affinity, interval, priority, loops,
+                      threads, histogram, default_args)
+        cmd = "sudo bash cyclictest_benchmark.sh %s" % (cmd_args)
+        LOG.debug("Executing command: %s", cmd)
+        status, stdout, stderr = self.client.execute(cmd)
+        if status:
+            raise RuntimeError(stderr)
+
+        data = json.loads(stdout)
+
+        if "sla" in args:
+            for t, latency in data.items():
+                if 'max_%s_latency' % t not in args['sla']:
+                    continue
+
+                sla_latency = int(args['sla']['max_%s_latency' % t])
+                latency = int(latency)
+                assert latency <= sla_latency, "%s latency %d > " \
+                    "sla:max_%s_latency(%d)" % (t, latency, t, sla_latency)
+
+        return data
+
+
+def _test():
+    '''internal test function'''
+    key_filename = pkg_resources.resource_filename("yardstick.resources",
+                                                   "files/yardstick_key")
+    ctx = {
+        "host": "192.168.50.28",
+        "user": "root",
+        "key_filename": key_filename
+    }
+
+    logger = logging.getLogger("yardstick")
+    logger.setLevel(logging.DEBUG)
+
+    cyclictest = Cyclictest(ctx)
+
+    options = {
+        "affinity": 2,
+        "interval": 100,
+        "priority": 88,
+        "loops": 10000,
+        "threads": 2,
+        "histogram": 80
+    }
+    sla = {
+        "max_min_latency": 100,
+        "max_avg_latency": 500,
+        "max_max_latency": 1000,
+    }
+    args = {
+        "options": options,
+        "sla": sla
+    }
+
+    result = cyclictest.run(args)
+    print result
+
+if __name__ == '__main__':
+    _test()
diff --git a/yardstick/benchmark/scenarios/compute/cyclictest_benchmark.bash b/yardstick/benchmark/scenarios/compute/cyclictest_benchmark.bash
new file mode 100644 (file)
index 0000000..5da3e17
--- /dev/null
@@ -0,0 +1,48 @@
+#!/bin/bash
+
+##############################################################################
+# Copyright (c) 2015 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
+##############################################################################
+
+set -e
+
+# Commandline arguments
+OPTIONS="$@"
+OUTPUT_FILE=/tmp/cyclictest-out.log
+
+# run cyclictest test
+run_cyclictest()
+{
+    cyclictest $OPTIONS > $OUTPUT_FILE
+}
+
+# write the result to stdout in json format
+output_json()
+{
+    min=$(awk '/# Min Latencies:/{print $4}' $OUTPUT_FILE)
+    avg=$(awk '/# Avg Latencies:/{print $4}' $OUTPUT_FILE)
+    max=$(awk '/# Max Latencies:/{print $4}' $OUTPUT_FILE)
+    echo -e "{ \
+        \"min\":\"$min\", \
+        \"avg\":\"$avg\", \
+        \"max\":\"$max\" \
+    }"
+}
+
+# main entry
+main()
+{
+    # run the test
+    run_cyclictest
+
+    # output result
+    output_json
+}
+
+main
+