|
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 LUBackup*"""
|
|
23 |
|
|
24 |
import mock
|
|
25 |
|
|
26 |
from ganeti import constants
|
|
27 |
from ganeti import opcodes
|
|
28 |
from ganeti import query
|
|
29 |
|
|
30 |
from testsupport import *
|
|
31 |
|
|
32 |
import testutils
|
|
33 |
|
|
34 |
|
|
35 |
class TestLUBackupQuery(CmdlibTestCase):
|
|
36 |
def setUp(self):
|
|
37 |
super(TestLUBackupQuery, self).setUp()
|
|
38 |
|
|
39 |
self.fields = query._BuildExportFields().keys()
|
|
40 |
|
|
41 |
def testFailingExportList(self):
|
|
42 |
self.rpc.call_export_list.return_value = \
|
|
43 |
self.RpcResultsBuilder() \
|
|
44 |
.AddFailedNode(self.master) \
|
|
45 |
.Build()
|
|
46 |
op = opcodes.OpBackupQuery(nodes=[self.master.name])
|
|
47 |
ret = self.ExecOpCode(op)
|
|
48 |
self.assertEqual({self.master.name: False}, ret)
|
|
49 |
|
|
50 |
def testQueryOneNode(self):
|
|
51 |
self.rpc.call_export_list.return_value = \
|
|
52 |
self.RpcResultsBuilder() \
|
|
53 |
.AddSuccessfulNode(self.master,
|
|
54 |
["mock_export1", "mock_export2"]) \
|
|
55 |
.Build()
|
|
56 |
op = opcodes.OpBackupQuery(nodes=[self.master.name])
|
|
57 |
ret = self.ExecOpCode(op)
|
|
58 |
self.assertEqual({self.master.name: ["mock_export1", "mock_export2"]}, ret)
|
|
59 |
|
|
60 |
def testQueryAllNodes(self):
|
|
61 |
node = self.cfg.AddNewNode()
|
|
62 |
self.rpc.call_export_list.return_value = \
|
|
63 |
self.RpcResultsBuilder() \
|
|
64 |
.AddSuccessfulNode(self.master, ["mock_export1"]) \
|
|
65 |
.AddSuccessfulNode(node, ["mock_export2"]) \
|
|
66 |
.Build()
|
|
67 |
op = opcodes.OpBackupQuery()
|
|
68 |
ret = self.ExecOpCode(op)
|
|
69 |
self.assertEqual({
|
|
70 |
self.master.name: ["mock_export1"],
|
|
71 |
node.name: ["mock_export2"]
|
|
72 |
}, ret)
|
|
73 |
|
|
74 |
|
|
75 |
if __name__ == "__main__":
|
|
76 |
testutils.GanetiTestProgram()
|