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