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