aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/benchmark/scenarios/compute/test_spec_cpu.py
blob: 40423b9da2eb2bf3c57fede5d17db450447316de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python

##############################################################################
# Copyright (c) 2017 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.spec_cpu.SpecCPU

from __future__ import absolute_import

import unittest

import mock

from yardstick.common import utils
from yardstick.benchmark.scenarios.compute import spec_cpu


@mock.patch('yardstick.benchmark.scenarios.compute.spec_cpu.ssh')
class SpecCPUTestCase(unittest.TestCase):

    def setUp(self):
        self.ctx = {
            'host': {
                'ip': '172.16.0.137',
                'user': 'root',
                'key_filename': "mykey.key"
            }
        }

        self.result = {}

    def test_spec_cpu_successful_setup(self, mock_ssh):

        options = {
            "SPECint_benchmark": "perlbench",
            "runspec_tune": "all",
            "output_format": "all",
            "runspec_iterations": "1",
            "runspec_tune": "base",
            "runspec_size": "test"
        }
        args = {"options": options}
        s = spec_cpu.SpecCPU(args, self.ctx)
        mock_ssh.SSH.from_node().execute.return_value = (0, '', '')

        s.setup()
        self.assertIsNotNone(s.client)
        self.assertTrue(s.setup_done, True)

    def test_spec_cpu_successful__run_no_sla(self, mock_ssh):

        options = {
            "SPECint_benchmark": "perlbench",
            "runspec_tune": "all",
            "output_format": "all"
        }
        args = {"options": options}
        s = spec_cpu.SpecCPU(args, self.ctx)

        sample_output = ''
        mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
        s.run(self.result)
        expected_result = {}
        self.assertEqual(self.result, expected_result)

    def test_ramspeed_unsuccessful_script_error(self, mock_ssh):
        options = {
            "benchmark_subset": "int"
        }
        args = {"options": options}
        s = spec_cpu.SpecCPU(args, self.ctx)

        mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
        self.assertRaises(RuntimeError, s.run, self.result)

def main():
    unittest.main()

if __name__ == '__main__':
    main()
by CI when running. **IMPORTANT NOTE**: To apply a new configuration, you need to kill the running container an start a new one (see below) Run ^^^ To run the container, you have to map folder located on the host to folders in the container (config, logs):: docker run -d --name energy-collector --restart=always -v /etc/energyrecorder:/usr/local/energyrecorder/server-collector/conf -v /var/log/energyrecorder:/var/log/energyrecorder energyrecorder/collector Energy Recording API -------------------- An event API to insert contextual information when monitoring energy (e.g. start Functest, start Tempest, destroy VM, ..) It is associated with an influxDB to store the power consumption measures It is hosted on a shared environment with the folling access points: +------------------------------------+----------------------------------------+ | Component | Connectivity | +====================================+========================================+ | Energy recording API documentation | http://energy.opnfv.fr/resources/doc/ | +------------------------------------+----------------------------------------+ | influxDB (data) | http://energy.opnfv.fr:8086 | +------------------------------------+----------------------------------------+ In you need, you can also host your own version of the Energy recording API (in such case, the Python SDK may requires a settings update) If you plan to use the default shared API, following steps are not required. Image creation ^^^^^^^^^^^^^^ First, you need to buid an image:: curl -s https://raw.githubusercontent.com/bherard/energyrecorder/master/docker/recording-api.dockerfile|docker build -t energyrecorder/api - Setup ^^^^^ Create local folder on your host for logs and config files:: mkdir -p /etc/energyrecorder mkdir -p /var/log/energyrecorder mkdir -p /var/lib/influxdb In /etc/energyrecorder create a configuration for logging in a file named webapp-logging.conf:: curl -s https://raw.githubusercontent.com/bherard/energyrecorder/master/recording-api/conf/webapp-logging.conf.sample > /etc/energyrecorder/webapp-logging.conf Check configuration for this file (folders, log levels.....) In /etc/energyrecorder create a configuration for the collector in a file named webapp-settings.yaml:: curl -s https://raw.githubusercontent.com/bherard/energyrecorder/master/recording-api/conf/webapp-settings.yaml.sample > /etc/energyrecorder/webapp-settings.yaml Normaly included configuration is ready to use except username/passwer for influx (see run-container.sh bellow). Use here the admin user. **IMPORTANT NOTE**: To apply a new configuration, you need to kill the running container an start a new one (see bellow) Run ^^^ To run the container, you have to map folder located on the host to folders in the container (config, logs):: docker run -d --name energyrecorder-api -p 8086:8086 -p 8888:8888 -v /etc/energyrecorder:/usr/local/energyrecorder/web.py/conf -v /var/log/energyrecorder/:/var/log/energyrecorder -v /var/lib/influxdb:/var/lib/influxdb energyrecorder/webapp admin-influx-user-name admin-password readonly-influx-user-name user-password with +---------------------------+--------------------------------------------+ | Parameter name | Description | +===========================+============================================+ | admin-influx-user-name | Influx user with admin grants to create | |---------------------------+--------------------------------------------+ | admin-password | Influx password to set to admin user | |---------------------------+--------------------------------------------+ | readonly-influx-user-name | Influx user with readonly grants to create | |---------------------------+--------------------------------------------+ | user-password | Influx password to set to readonly user | +---------------------------+--------------------------------------------+ **NOTE**: Local folder /var/lib/influxdb is the location web influx data are stored. You may used anything else at your convience. Just remember to define this mapping properly when running the container. Power consumption Python SDK ---------------------------- a Python SDK - almost not intrusive, based on python decorator to trigger call to the event API. It is currently hosted in Functest repo but if other projects adopt it, a dedicated project could be created and/or it could be hosted in Releng. How to use the SDK ^^^^^^^^^^^^^^^^^^ import the energy library:: import functest.energy.energy as energy Notify that you want power recording in your testcase:: @energy.enable_recording def run(self): self.do_some_stuff1() self.do_some_stuff2() If you want to register additional steps during the scenarios you can to it in 2 different ways. Notify step on method definition:: @energy.set_step("step1") def do_some_stuff1(self): ... @energy.set_step("step2") def do_some_stuff2(self): Notify directly from code:: @energy.enable_recording def run(self): Energy.set_step("step1") self.do_some_stuff1() ... Energy.set_step("step2") self.do_some_stuff2() SDK Setting ^^^^^^^^^^^ Settings delivered in the project git are ready to use and assume that you will use the sahre energy recording API. If you want to use an other instance, you have to update the key "energy_recorder.api_url" in <FUNCTEST>/functest/ci/config_functest.yaml" by setting the proper hostname/IP Results ------- Here is an example of result comming from LF POD2. This sequence represents several CI runs in a raw. (0 power corresponds to hard reboot of the servers) You may connect http://energy.opnfv.fr:3000 for more results (ask for credentials to infra team). .. figure:: ../../images/energy_LF2.png :align: center :alt: Energy monitoring of LF POD2