Fixed document for Grafana Port usage
[yardstick.git] / tests / unit / benchmark / scenarios / compute / test_plugintest.py
1 #!/usr/bin/env python
2
3 ##############################################################################
4 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 # Unittest for yardstick.benchmark.scenarios.compute.plugintest.PluginTest
13
14 from __future__ import absolute_import
15
16 import unittest
17
18 import mock
19 from oslo_serialization import jsonutils
20
21 from yardstick.benchmark.scenarios.compute import plugintest
22
23
24 @mock.patch('yardstick.benchmark.scenarios.compute.plugintest.ssh')
25 class PluginTestTestCase(unittest.TestCase):
26
27     def setUp(self):
28         self.ctx = {
29             'nodes': {
30                 'host1': {
31                     'ip': '172.16.0.137',
32                     'user': 'cirros',
33                     'key_filename': "mykey.key",
34                     'password': "root"
35                 },
36             }
37         }
38
39         self.result = {}
40
41     def test_sample_successful_setup(self, mock_ssh):
42         s = plugintest.PluginTest({}, self.ctx)
43         mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
44
45         s.setup()
46         self.assertIsNotNone(s.client)
47         self.assertTrue(s.setup_done)
48
49     def test_sample_successful(self, mock_ssh):
50         s = plugintest.PluginTest({}, self.ctx)
51
52         sample_output = '{"Test Output": "Hello world!"}'
53         mock_ssh.SSH.from_node().execute.return_value = (0, sample_output, '')
54         s.run(self.result)
55         expected_result = jsonutils.loads(sample_output)
56         self.assertEqual(self.result, expected_result)
57
58     def test_sample_unsuccessful_script_error(self, mock_ssh):
59         s = plugintest.PluginTest({}, self.ctx)
60
61         mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
62         self.assertRaises(RuntimeError, s.run, self.result)