root / test / ganeti.cmdlib_unittest.py @ 549071a0
History | View | Annotate | Download (3.3 kB)
1 |
#!/usr/bin/python
|
---|---|
2 |
#
|
3 |
|
4 |
# Copyright (C) 2008 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 |
# 0.0510-1301, USA.
|
20 |
|
21 |
|
22 |
"""Script for unittesting the cmdlib module"""
|
23 |
|
24 |
|
25 |
import os |
26 |
import unittest |
27 |
import time |
28 |
import tempfile |
29 |
import shutil |
30 |
|
31 |
from ganeti import mcpu |
32 |
from ganeti import cmdlib |
33 |
from ganeti import opcodes |
34 |
from ganeti import errors |
35 |
from ganeti import utils |
36 |
|
37 |
import testutils |
38 |
|
39 |
|
40 |
class TestCertVerification(testutils.GanetiTestCase): |
41 |
def setUp(self): |
42 |
testutils.GanetiTestCase.setUp(self)
|
43 |
|
44 |
self.tmpdir = tempfile.mkdtemp()
|
45 |
|
46 |
def tearDown(self): |
47 |
shutil.rmtree(self.tmpdir)
|
48 |
|
49 |
def testVerifyCertificate(self): |
50 |
cmdlib._VerifyCertificate(self._TestDataFilename("cert1.pem")) |
51 |
|
52 |
nonexist_filename = os.path.join(self.tmpdir, "does-not-exist") |
53 |
|
54 |
(errcode, msg) = cmdlib._VerifyCertificate(nonexist_filename) |
55 |
self.assertEqual(errcode, cmdlib.LUVerifyCluster.ETYPE_ERROR)
|
56 |
|
57 |
# Try to load non-certificate file
|
58 |
invalid_cert = self._TestDataFilename("bdev-net.txt") |
59 |
(errcode, msg) = cmdlib._VerifyCertificate(invalid_cert) |
60 |
self.assertEqual(errcode, cmdlib.LUVerifyCluster.ETYPE_ERROR)
|
61 |
|
62 |
|
63 |
class TestOpcodeParams(testutils.GanetiTestCase): |
64 |
def testParamsStructures(self): |
65 |
for op in sorted(mcpu.Processor.DISPATCH_TABLE): |
66 |
lu = mcpu.Processor.DISPATCH_TABLE[op] |
67 |
lu_name = lu.__name__ |
68 |
self.failIf(hasattr(lu, "_OP_REQP"), "LU '%s' has old-style _OP_REQP" % |
69 |
lu_name) |
70 |
self.failIf(hasattr(lu, "_OP_DEFS"), "LU '%s' has old-style _OP_DEFS" % |
71 |
lu_name) |
72 |
# this needs to remain a list!
|
73 |
defined_params = [v[0] for v in lu._OP_PARAMS] |
74 |
for row in lu._OP_PARAMS: |
75 |
# this relies on there being at least one element
|
76 |
param_name = row[0]
|
77 |
self.failIf(len(row) != 3, "LU '%s' parameter %s has invalid length" % |
78 |
(lu_name, param_name)) |
79 |
self.failIf(defined_params.count(param_name) > 1, "LU '%s' parameter" |
80 |
" '%s' is defined multiple times" % (lu_name, param_name))
|
81 |
|
82 |
def testParamsDefined(self): |
83 |
for op in sorted(mcpu.Processor.DISPATCH_TABLE): |
84 |
lu = mcpu.Processor.DISPATCH_TABLE[op] |
85 |
lu_name = lu.__name__ |
86 |
# TODO: this doesn't deal with recursive slots definitions
|
87 |
all_params = set(op.__slots__)
|
88 |
defined_params = set(v[0] for v in lu._OP_PARAMS) |
89 |
missing = all_params.difference(defined_params) |
90 |
self.failIf(missing, "Undeclared parameter types for LU '%s': %s" % |
91 |
(lu_name, utils.CommaJoin(missing))) |
92 |
extra = defined_params.difference(all_params) |
93 |
self.failIf(extra, "Extra parameter types for LU '%s': %s" % |
94 |
(lu_name, utils.CommaJoin(extra))) |
95 |
|
96 |
|
97 |
if __name__ == "__main__": |
98 |
testutils.GanetiTestProgram() |