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