root / test / py / cmdlib / test_unittest.py @ 3efa7659
History | View | Annotate | Download (3.4 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 |
"""Tests for LUTest*
|
23 |
|
24 |
"""
|
25 |
|
26 |
|
27 |
from ganeti import constants |
28 |
from ganeti import errors |
29 |
from ganeti import opcodes |
30 |
|
31 |
from testsupport import * |
32 |
|
33 |
import testutils |
34 |
|
35 |
DELAY_DURATION = 0.01
|
36 |
|
37 |
|
38 |
class TestLUTestDelay(CmdlibTestCase): |
39 |
def testRepeatedInvocation(self): |
40 |
op = opcodes.OpTestDelay(duration=DELAY_DURATION, |
41 |
repeat=3)
|
42 |
self.ExecOpCode(op)
|
43 |
|
44 |
self.assertLogContainsMessage(" - INFO: Test delay iteration 0/2") |
45 |
self.mcpu.assertLogContainsEntry(constants.ELOG_MESSAGE,
|
46 |
" - INFO: Test delay iteration 1/2")
|
47 |
self.assertLogContainsRegex("2/2$") |
48 |
|
49 |
def testInvalidDuration(self): |
50 |
op = opcodes.OpTestDelay(duration=-1)
|
51 |
|
52 |
self.assertRaises(errors.OpExecError, self.ExecOpCode, op) |
53 |
|
54 |
def testOnNodeUuid(self): |
55 |
node_uuids = [self.cfg.GetMasterNode()]
|
56 |
op = opcodes.OpTestDelay(duration=DELAY_DURATION, |
57 |
on_node_uuids=node_uuids) |
58 |
self.ExecOpCode(op)
|
59 |
|
60 |
self.rpc.call_test_delay.assert_called_once_with(node_uuids, DELAY_DURATION)
|
61 |
|
62 |
def testOnNodeName(self): |
63 |
op = opcodes.OpTestDelay(duration=DELAY_DURATION, |
64 |
on_nodes=[self.cfg.GetMasterNodeName()])
|
65 |
self.ExecOpCode(op)
|
66 |
|
67 |
self.rpc.call_test_delay.assert_called_once_with([self.cfg.GetMasterNode()], |
68 |
DELAY_DURATION) |
69 |
|
70 |
def testSuccessfulRpc(self): |
71 |
op = opcodes.OpTestDelay(duration=DELAY_DURATION, |
72 |
on_nodes=[self.cfg.GetMasterNodeName()])
|
73 |
|
74 |
self.rpc.call_test_delay.return_value = \
|
75 |
RpcResultsBuilder(cfg=self.cfg) \
|
76 |
.AddSuccessfulNode(self.cfg.GetMasterNode()) \
|
77 |
.Build() |
78 |
|
79 |
self.ExecOpCode(op)
|
80 |
|
81 |
self.rpc.call_test_delay.assert_called_once()
|
82 |
|
83 |
def testFailingRpc(self): |
84 |
op = opcodes.OpTestDelay(duration=DELAY_DURATION, |
85 |
on_nodes=[self.cfg.GetMasterNodeName()])
|
86 |
|
87 |
self.rpc.call_test_delay.return_value = \
|
88 |
RpcResultsBuilder(cfg=self.cfg) \
|
89 |
.AddFailedNode(self.cfg.GetMasterNode()) \
|
90 |
.Build() |
91 |
|
92 |
self.assertRaises(errors.OpExecError, self.ExecOpCode, op) |
93 |
|
94 |
def testMultipleNodes(self): |
95 |
node1 = self.cfg.AddNewNode()
|
96 |
node2 = self.cfg.AddNewNode()
|
97 |
op = opcodes.OpTestDelay(duration=DELAY_DURATION, |
98 |
on_nodes=[node1.name, node2.name]) |
99 |
|
100 |
self.rpc.call_test_delay.return_value = \
|
101 |
RpcResultsBuilder(cfg=self.cfg) \
|
102 |
.AddSuccessfulNode(node1) \ |
103 |
.AddSuccessfulNode(node2) \ |
104 |
.Build() |
105 |
|
106 |
self.ExecOpCode(op)
|
107 |
|
108 |
self.rpc.call_test_delay.assert_called_once_with([node1.uuid, node2.uuid],
|
109 |
DELAY_DURATION) |
110 |
|
111 |
|
112 |
if __name__ == "__main__": |
113 |
testutils.GanetiTestProgram() |