Fixed document for Grafana Port usage
[yardstick.git] / yardstick / tests / unit / benchmark / scenarios / storage / test_bonnie.py
1 #!/usr/bin/env python
2
3 ##############################################################################
4 # Copyright (c) 2017 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.storage.bonnie.Bonnie
13
14 from __future__ import absolute_import
15
16 import unittest
17
18 import mock
19
20 from yardstick.benchmark.scenarios.storage import bonnie
21
22
23 class BonnieTestCase(unittest.TestCase):
24
25     def setUp(self):
26         self.ctx = {
27             'host': {
28                 'ip': '172.16.0.137',
29                 'user': 'root',
30                 'key_filename': "mykey.key"
31             }
32         }
33
34         self.result = {}
35
36     @mock.patch('yardstick.benchmark.scenarios.storage.bonnie.ssh')
37     def test_bonnie_successful_setup(self, mock_ssh):
38
39         options = {
40             "file_size": "1024",
41             "ram_size": "512",
42             "test_dir": "/tmp",
43             "concurrency": "1",
44             "test_user": "root"
45         }
46         args = {"options": options}
47         b = bonnie.Bonnie(args, self.ctx)
48         mock_ssh.SSH.from_node().execute.return_value = (0, '', '')
49
50         b.setup()
51         self.assertIsNotNone(b.client)
52         self.assertTrue(b.setup_done, True)
53
54     @mock.patch('yardstick.benchmark.scenarios.storage.bonnie.ssh')
55     def test_bonnie_unsuccessful_script_error(self, mock_ssh):
56         options = {
57             "file_size": "1024",
58             "ram_size": "512",
59             "test_dir": "/tmp",
60             "concurrency": "1",
61             "test_user": "root"
62         }
63         args = {"options": options}
64         b = bonnie.Bonnie(args, self.ctx)
65
66         mock_ssh.SSH.from_node().execute.return_value = (1, '', 'FOOBAR')
67         self.assertRaises(RuntimeError, b.run, self.result)
68
69
70 def main():
71     unittest.main()
72
73
74 if __name__ == '__main__':
75     main()