add option to connect to non-standard ssh port
[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 import logging
10 import json
11
12 import yardstick.ssh as ssh
13 from yardstick.benchmark.scenarios import base
14
15 LOG = logging.getLogger(__name__)
16
17
18 class PluginTest(base.Scenario):
19     """Sample scenario file for testing sample plugin"""
20     __scenario_type__ = "PluginTest"
21
22     def __init__(self, scenario_cfg, context_cfg):
23         self.scenario_cfg = scenario_cfg
24         self.context_cfg = context_cfg
25         self.setup_done = False
26
27     def setup(self):
28         """scenario setup"""
29
30         nodes = self.context_cfg['nodes']
31         node = nodes.get('host1', None)
32         host_user = node.get('user', 'ubuntu')
33         host_ssh_port = node.get('ssh_port', ssh.DEFAULT_PORT)
34         host_ip = node.get('ip', None)
35         host_pwd = node.get('password', 'root')
36         LOG.debug("user:%s, host:%s", host_user, host_ip)
37         self.client = ssh.SSH(host_user, host_ip, password=host_pwd,
38                               port=host_ssh_port)
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(json.loads(stdout))