root / test / py / cmdlib / backup_unittest.py @ 3388debb
History | View | Annotate | Download (3.2 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 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 |
class TestLUBackupPrepare(CmdlibTestCase): |
76 |
@patchUtils("instance_utils") |
77 |
def testPrepareLocalExport(self, utils): |
78 |
utils.ReadOneLineFile.return_value = "cluster_secret"
|
79 |
inst = self.cfg.AddNewInstance()
|
80 |
op = opcodes.OpBackupPrepare(instance_name=inst.name, |
81 |
mode=constants.EXPORT_MODE_LOCAL) |
82 |
self.ExecOpCode(op)
|
83 |
|
84 |
@patchUtils("instance_utils") |
85 |
def testPrepareRemoteExport(self, utils): |
86 |
utils.ReadOneLineFile.return_value = "cluster_secret"
|
87 |
inst = self.cfg.AddNewInstance()
|
88 |
self.rpc.call_x509_cert_create.return_value = \
|
89 |
self.RpcResultsBuilder() \
|
90 |
.CreateSuccessfulNodeResult(inst.primary_node, |
91 |
("key_name",
|
92 |
testutils.ReadTestData("cert1.pem")))
|
93 |
op = opcodes.OpBackupPrepare(instance_name=inst.name, |
94 |
mode=constants.EXPORT_MODE_REMOTE) |
95 |
self.ExecOpCode(op)
|
96 |
|
97 |
|
98 |
if __name__ == "__main__": |
99 |
testutils.GanetiTestProgram() |