4 # Copyright (C) 2012 Google Inc.
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.
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.
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
22 """Script for testing ganeti.rapi.testutils"""
26 from ganeti import compat
27 from ganeti import constants
28 from ganeti import errors
29 from ganeti import opcodes
30 from ganeti import rapi
32 import ganeti.rapi.testutils
37 class TestHideInternalErrors(unittest.TestCase):
40 raise errors.GenericError("error")
42 fn = rapi.testutils._HideInternalErrors(inner)
44 self.assertRaises(rapi.testutils.VerificationError, fn)
47 class TestVerifyOpInput(unittest.TestCase):
48 def testUnknownOpId(self):
49 voi = rapi.testutils.VerifyOpInput
51 self.assertRaises(rapi.testutils.VerificationError, voi, "UNK_OP_ID", None)
53 def testUnknownParameter(self):
54 voi = rapi.testutils.VerifyOpInput
56 self.assertRaises(rapi.testutils.VerificationError, voi,
57 opcodes.OpClusterRename.OP_ID, {
61 def testWrongParameterValue(self):
62 voi = rapi.testutils.VerifyOpInput
63 self.assertRaises(rapi.testutils.VerificationError, voi,
64 opcodes.OpClusterRename.OP_ID, {
68 def testSuccess(self):
69 voi = rapi.testutils.VerifyOpInput
70 voi(opcodes.OpClusterRename.OP_ID, {
71 "name": "new-name.example.com",
75 class TestVerifyOpResult(unittest.TestCase):
76 def testSuccess(self):
77 vor = rapi.testutils.VerifyOpResult
79 vor(opcodes.OpClusterVerify.OP_ID, {
80 constants.JOB_IDS_KEY: [
81 (False, "error message"),
85 def testWrongResult(self):
86 vor = rapi.testutils.VerifyOpResult
88 self.assertRaises(rapi.testutils.VerificationError, vor,
89 opcodes.OpClusterVerify.OP_ID, [])
91 def testNoResultCheck(self):
92 vor = rapi.testutils.VerifyOpResult
94 assert opcodes.OpTestDummy.OP_RESULT is None
96 vor(opcodes.OpTestDummy.OP_ID, None)
99 if __name__ == "__main__":
100 testutils.GanetiTestProgram()