|
1 |
#!/usr/bin/python
|
|
2 |
#
|
|
3 |
|
|
4 |
# Copyright (C) 2010 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 |
"""Script for testing ganeti.backend"""
|
|
23 |
|
|
24 |
import os
|
|
25 |
import sys
|
|
26 |
import unittest
|
|
27 |
|
|
28 |
from ganeti import errors
|
|
29 |
|
|
30 |
import testutils
|
|
31 |
|
|
32 |
|
|
33 |
class TestErrors(testutils.GanetiTestCase):
|
|
34 |
def testGetErrorClass(self):
|
|
35 |
tdata = {
|
|
36 |
"": None,
|
|
37 |
".": None,
|
|
38 |
"-": None,
|
|
39 |
"ECODE_INVAL": None,
|
|
40 |
"NoErrorClassName": None,
|
|
41 |
"GenericError": errors.GenericError,
|
|
42 |
"ProgrammerError": errors.ProgrammerError,
|
|
43 |
}
|
|
44 |
|
|
45 |
for name, cls in tdata.items():
|
|
46 |
self.assert_(errors.GetErrorClass(name) is cls)
|
|
47 |
|
|
48 |
def testEncodeException(self):
|
|
49 |
self.assertEqualValues(errors.EncodeException(Exception("Foobar")),
|
|
50 |
("Exception", ("Foobar", )))
|
|
51 |
err = errors.GenericError(True, 100, "foo", ["x", "y"])
|
|
52 |
self.assertEqualValues(errors.EncodeException(err),
|
|
53 |
("GenericError", (True, 100, "foo", ["x", "y"])))
|
|
54 |
|
|
55 |
def testMaybeRaise(self):
|
|
56 |
# These shouldn't raise
|
|
57 |
for i in [None, 1, 2, 3, "Hello World", (1, ), (1, 2, 3),
|
|
58 |
("NoErrorClassName", []), ("NoErrorClassName", None),
|
|
59 |
("GenericError", [1, 2, 3], None), ("GenericError", 1)]:
|
|
60 |
errors.MaybeRaise(i)
|
|
61 |
|
|
62 |
self.assertRaises(errors.GenericError, errors.MaybeRaise,
|
|
63 |
("GenericError", ["Hello"]))
|
|
64 |
|
|
65 |
|
|
66 |
if __name__ == "__main__":
|
|
67 |
testutils.GanetiTestProgram()
|