add yardstick iruya 9.0.0 release notes
[yardstick.git] / yardstick / benchmark / scenarios / compute / plugintest.py
1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
3 #
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
10
11 import logging
12
13 from oslo_serialization import jsonutils
14
15 import yardstick.ssh as ssh
16 from yardstick.benchmark.scenarios import base
17
18 LOG = logging.getLogger(__name__)
19
20
21 class PluginTest(base.Scenario):
22     """Sample scenario file for testing sample plugin"""
23     __scenario_type__ = "PluginTest"
24
25     def __init__(self, scenario_cfg, context_cfg):
26         self.scenario_cfg = scenario_cfg
27         self.context_cfg = context_cfg
28         self.setup_done = False
29
30     def setup(self):
31         """scenario setup"""
32
33         nodes = self.context_cfg['nodes']
34         node = nodes.get('host1', None)
35
36         self.client = ssh.SSH.from_node(node, defaults={
37             "user": "ubuntu", "password": "root"
38         })
39         self.client.wait(timeout=600)
40
41         self.setup_done = True
42
43     def run(self, result):
44         """execute the benchmark"""
45
46         if not self.setup_done:
47             self.setup()
48
49         cmd = "sudo bash test.sh"
50
51         LOG.debug("Executing command: %s", cmd)
52         status, stdout, stderr = self.client.execute(cmd)
53         if status:
54             raise RuntimeError(stderr)
55
56         result.update(jsonutils.loads(stdout))