Merge "Add a new runner to test end-to-end fast data path"
[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         host_user = node.get('user', 'ubuntu')
36         host_ssh_port = node.get('ssh_port', ssh.DEFAULT_PORT)
37         host_ip = node.get('ip', None)
38         host_pwd = node.get('password', 'root')
39         LOG.debug("user:%s, host:%s", host_user, host_ip)
40         self.client = ssh.SSH(host_user, host_ip, password=host_pwd,
41                               port=host_ssh_port)
42         self.client.wait(timeout=600)
43
44         self.setup_done = True
45
46     def run(self, result):
47         """execute the benchmark"""
48
49         if not self.setup_done:
50             self.setup()
51
52         cmd = "sudo bash test.sh"
53
54         LOG.debug("Executing command: %s", cmd)
55         status, stdout, stderr = self.client.execute(cmd)
56         if status:
57             raise RuntimeError(stderr)
58
59         result.update(jsonutils.loads(stdout))