441116a2513ebbace932f746a06dc3481d2794d2
[yardstick.git] / tests / unit / benchmark / core / test_plugin.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.core.plugin
13
14 import mock
15 import unittest
16
17 from yardstick.benchmark.core import plugin
18
19
20 class Arg(object):
21     def __init__(self):
22         self.input_file = ('plugin/sample_config.yaml',)
23
24
25 @mock.patch('yardstick.benchmark.core.plugin.ssh')
26 class pluginTestCase(unittest.TestCase):
27
28     def setUp(self):
29         self.result = {}
30
31     def test_install(self, mock_ssh):
32         p = plugin.Plugin()
33         mock_ssh.SSH().execute.return_value = (0, '', '')
34         input_file = Arg()
35         p.install(input_file)
36         expected_result = {}
37         self.assertEqual(self.result, expected_result)
38
39     def test_remove(self, mock_ssh):
40         p = plugin.Plugin()
41         mock_ssh.SSH().execute.return_value = (0, '', '')
42         input_file = Arg()
43         p.remove(input_file)
44         expected_result = {}
45         self.assertEqual(self.result, expected_result)
46
47     def test_install_setup_run(self, mock_ssh):
48         p = plugin.Plugin()
49         mock_ssh.SSH().execute.return_value = (0, '', '')
50         plugins = {
51             "name": "sample"
52         }
53         deployment = {
54             "ip": "10.1.0.50",
55             "user": "root",
56             "password": "root"
57         }
58         plugin_name = plugins.get("name")
59         p._install_setup(plugin_name, deployment)
60         self.assertIsNotNone(p.client)
61
62         p._run(plugin_name)
63         expected_result = {}
64         self.assertEqual(self.result, expected_result)
65
66     def test_remove_setup_run(self, mock_ssh):
67         p = plugin.Plugin()
68         mock_ssh.SSH().execute.return_value = (0, '', '')
69         plugins = {
70             "name": "sample"
71         }
72         deployment = {
73             "ip": "10.1.0.50",
74             "user": "root",
75             "password": "root"
76         }
77         plugin_name = plugins.get("name")
78         p._remove_setup(plugin_name, deployment)
79         self.assertIsNotNone(p.client)
80
81         p._run(plugin_name)
82         expected_result = {}
83         self.assertEqual(self.result, expected_result)
84
85
86 def main():
87     unittest.main()
88
89
90 if __name__ == '__main__':
91     main()