-
Notifications
You must be signed in to change notification settings - Fork 25
/
test_disks.py
61 lines (52 loc) · 2.39 KB
/
test_disks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#
# Project Ginger Base
#
# Copyright IBM Corp, 2016
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import unittest
import mock
from wok.exception import NotFoundError
from wok.exception import OperationFailed
from wok.plugins.gingerbase.disks import _get_lsblk_devs
from wok.plugins.gingerbase.disks import pvs_with_vg_list
class DiskTests(unittest.TestCase):
@mock.patch('wok.plugins.gingerbase.disks.run_command')
def test_lsblk_returns_404_when_device_not_found(self, mock_run_command):
mock_run_command.return_value = ['', 'not a block device', 32]
fake_dev = '/not/a/true/block/dev'
keys = ['MOUNTPOINT']
with self.assertRaises(NotFoundError):
_get_lsblk_devs(keys, [fake_dev])
cmd = ['lsblk', '-Pbo', 'MOUNTPOINT', fake_dev]
mock_run_command.assert_called_once_with(cmd)
@mock.patch('wok.plugins.gingerbase.disks.run_command')
def test_lsblk_returns_500_when_unknown_error_occurs(
self, mock_run_command):
mock_run_command.return_value = ['', '', 1]
valid_dev = '/valid/block/dev'
keys = ['MOUNTPOINT']
with self.assertRaises(OperationFailed):
_get_lsblk_devs(keys, [valid_dev])
cmd = ['lsblk', '-Pbo', 'MOUNTPOINT', valid_dev]
mock_run_command.assert_called_once_with(cmd)
@mock.patch('wok.plugins.gingerbase.disks.run_command')
def test_pvs_with_vg_list(self, mock_run_command):
mock_run_command.return_value = ["""
/dev/mapper/36005076307ffc6a60000000000001f22 vpoolfclun2
/dev/mapper/36005076307ffc6a60000000000001f23 vpoolfclun
/dev/dasdb1""", '', 0]
outlist = pvs_with_vg_list()
self.assertEqual(outlist[0].get('/dev/dasdb1'), 'N/A')