root / test / py / cmdlib / instance_storage_unittest.py @ f8f415a1
History | View | Annotate | Download (3.7 kB)
1 |
#!/usr/bin/python
|
---|---|
2 |
#
|
3 |
|
4 |
# Copyright (C) 2013 Google Inc.
|
5 |
#
|
6 |
# This program is free software; you can redistribute it and/or modify
|
7 |
# it under the terms of the GNU General Public License as published by
|
8 |
# the Free Software Foundation; either version 2 of the License, or
|
9 |
# (at your option) any later version.
|
10 |
#
|
11 |
# This program is distributed in the hope that it will be useful, but
|
12 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
# General Public License for more details.
|
15 |
#
|
16 |
# You should have received a copy of the GNU General Public License
|
17 |
# along with this program; if not, write to the Free Software
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 |
# 02110-1301, USA.
|
20 |
|
21 |
|
22 |
"""Script for unittesting the cmdlib module 'instance_storage'"""
|
23 |
|
24 |
|
25 |
import unittest |
26 |
|
27 |
from ganeti import constants |
28 |
from ganeti.cmdlib import instance_storage |
29 |
from ganeti import errors |
30 |
|
31 |
import testutils |
32 |
import mock |
33 |
|
34 |
|
35 |
class TestCheckNodesFreeDiskOnVG(unittest.TestCase): |
36 |
|
37 |
def setUp(self): |
38 |
self.node_uuid = "12345" |
39 |
self.node_uuids = [self.node_uuid] |
40 |
|
41 |
self.node_info = mock.Mock()
|
42 |
|
43 |
self.es = True |
44 |
self.ndparams = {constants.ND_EXCLUSIVE_STORAGE: self.es} |
45 |
|
46 |
mock_rpc = mock.Mock() |
47 |
mock_rpc.call_node_info = mock.Mock() |
48 |
|
49 |
mock_cfg = mock.Mock() |
50 |
mock_cfg.GetNodeInfo = mock.Mock(return_value=self.node_info)
|
51 |
mock_cfg.GetNdParams = mock.Mock(return_value=self.ndparams)
|
52 |
|
53 |
self.hvname = "myhv" |
54 |
self.hvparams = mock.Mock()
|
55 |
self.clusterinfo = mock.Mock()
|
56 |
self.clusterinfo.hvparams = {self.hvname: self.hvparams} |
57 |
|
58 |
mock_cfg.GetHypervisorType = mock.Mock(return_value=self.hvname)
|
59 |
mock_cfg.GetClusterInfo = mock.Mock(return_value=self.clusterinfo)
|
60 |
|
61 |
self.lu = mock.Mock()
|
62 |
self.lu.rpc = mock_rpc
|
63 |
self.lu.cfg = mock_cfg
|
64 |
|
65 |
self.vg = "myvg" |
66 |
|
67 |
self.node_name = "mynode" |
68 |
self.space_info = [{"type": constants.ST_LVM_VG, |
69 |
"name": self.vg, |
70 |
"storage_free": 125, |
71 |
"storage_size": 666}] |
72 |
|
73 |
def testPerformNodeInfoCall(self): |
74 |
expected_hv_arg = [(self.hvname, self.hvparams)] |
75 |
expected_storage_arg = {self.node_uuid:
|
76 |
[(constants.ST_LVM_VG, self.vg, [self.es]), |
77 |
(constants.ST_LVM_PV, self.vg, [self.es])]} |
78 |
instance_storage._PerformNodeInfoCall(self.lu, self.node_uuids, self.vg) |
79 |
self.lu.rpc.call_node_info.assert_called_with(
|
80 |
self.node_uuids, expected_storage_arg, expected_hv_arg)
|
81 |
|
82 |
def testCheckVgCapacityForNode(self): |
83 |
requested = 123
|
84 |
node_info = (None, self.space_info, None) |
85 |
instance_storage._CheckVgCapacityForNode(self.node_name, node_info,
|
86 |
self.vg, requested)
|
87 |
|
88 |
def testCheckVgCapacityForNodeNotEnough(self): |
89 |
requested = 250
|
90 |
node_info = (None, self.space_info, None) |
91 |
self.assertRaises(
|
92 |
errors.OpPrereqError, |
93 |
instance_storage._CheckVgCapacityForNode, |
94 |
self.node_name, node_info, self.vg, requested) |
95 |
|
96 |
def testCheckVgCapacityForNodeNoStorageData(self): |
97 |
node_info = (None, [], None) |
98 |
self.assertRaises(
|
99 |
errors.OpPrereqError, |
100 |
instance_storage._CheckVgCapacityForNode, |
101 |
self.node_name, node_info, self.vg, NotImplemented) |
102 |
|
103 |
def testCheckVgCapacityForNodeBogusSize(self): |
104 |
broken_space_info = [{"type": constants.ST_LVM_VG,
|
105 |
"name": self.vg, |
106 |
"storage_free": "greenbunny", |
107 |
"storage_size": "redbunny"}] |
108 |
node_info = (None, broken_space_info, None) |
109 |
self.assertRaises(
|
110 |
errors.OpPrereqError, |
111 |
instance_storage._CheckVgCapacityForNode, |
112 |
self.node_name, node_info, self.vg, NotImplemented) |
113 |
|
114 |
|
115 |
if __name__ == "__main__": |
116 |
testutils.GanetiTestProgram() |