root / test / ganeti.cmdlib_unittest.py @ 0559f745
History | View | Annotate | Download (1.7 kB)
1 | 6de7c41d | Iustin Pop | #!/usr/bin/python
|
---|---|---|---|
2 | 6de7c41d | Iustin Pop | #
|
3 | 6de7c41d | Iustin Pop | |
4 | 6de7c41d | Iustin Pop | # Copyright (C) 2008 Google Inc.
|
5 | 6de7c41d | Iustin Pop | #
|
6 | 6de7c41d | Iustin Pop | # This program is free software; you can redistribute it and/or modify
|
7 | 6de7c41d | Iustin Pop | # it under the terms of the GNU General Public License as published by
|
8 | 6de7c41d | Iustin Pop | # the Free Software Foundation; either version 2 of the License, or
|
9 | 6de7c41d | Iustin Pop | # (at your option) any later version.
|
10 | 6de7c41d | Iustin Pop | #
|
11 | 6de7c41d | Iustin Pop | # This program is distributed in the hope that it will be useful, but
|
12 | 6de7c41d | Iustin Pop | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 6de7c41d | Iustin Pop | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 6de7c41d | Iustin Pop | # General Public License for more details.
|
15 | 6de7c41d | Iustin Pop | #
|
16 | 6de7c41d | Iustin Pop | # You should have received a copy of the GNU General Public License
|
17 | 6de7c41d | Iustin Pop | # along with this program; if not, write to the Free Software
|
18 | 6de7c41d | Iustin Pop | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | 6de7c41d | Iustin Pop | # 0.0510-1301, USA.
|
20 | 6de7c41d | Iustin Pop | |
21 | 6de7c41d | Iustin Pop | |
22 | 6de7c41d | Iustin Pop | """Script for unittesting the cmdlib module"""
|
23 | 6de7c41d | Iustin Pop | |
24 | 6de7c41d | Iustin Pop | |
25 | 6de7c41d | Iustin Pop | import os |
26 | 6de7c41d | Iustin Pop | import unittest |
27 | 6de7c41d | Iustin Pop | import time |
28 | b98bf262 | Michael Hanselmann | import tempfile |
29 | b98bf262 | Michael Hanselmann | import shutil |
30 | 6de7c41d | Iustin Pop | |
31 | 6de7c41d | Iustin Pop | from ganeti import cmdlib |
32 | 6de7c41d | Iustin Pop | from ganeti import errors |
33 | 6de7c41d | Iustin Pop | |
34 | 25231ec5 | Michael Hanselmann | import testutils |
35 | 25231ec5 | Michael Hanselmann | |
36 | 6de7c41d | Iustin Pop | |
37 | b98bf262 | Michael Hanselmann | class TestCertVerification(testutils.GanetiTestCase): |
38 | b98bf262 | Michael Hanselmann | def setUp(self): |
39 | b98bf262 | Michael Hanselmann | testutils.GanetiTestCase.setUp(self)
|
40 | b98bf262 | Michael Hanselmann | |
41 | b98bf262 | Michael Hanselmann | self.tmpdir = tempfile.mkdtemp()
|
42 | b98bf262 | Michael Hanselmann | |
43 | b98bf262 | Michael Hanselmann | def tearDown(self): |
44 | b98bf262 | Michael Hanselmann | shutil.rmtree(self.tmpdir)
|
45 | b98bf262 | Michael Hanselmann | |
46 | b98bf262 | Michael Hanselmann | def testVerifyCertificate(self): |
47 | b98bf262 | Michael Hanselmann | cmdlib._VerifyCertificate(self._TestDataFilename("cert1.pem")) |
48 | b98bf262 | Michael Hanselmann | |
49 | b98bf262 | Michael Hanselmann | nonexist_filename = os.path.join(self.tmpdir, "does-not-exist") |
50 | b98bf262 | Michael Hanselmann | |
51 | b98bf262 | Michael Hanselmann | (errcode, msg) = cmdlib._VerifyCertificate(nonexist_filename) |
52 | b98bf262 | Michael Hanselmann | self.assertEqual(errcode, cmdlib.LUVerifyCluster.ETYPE_ERROR)
|
53 | b98bf262 | Michael Hanselmann | |
54 | b98bf262 | Michael Hanselmann | # Try to load non-certificate file
|
55 | 24d70417 | Michael Hanselmann | invalid_cert = self._TestDataFilename("bdev-net.txt") |
56 | b98bf262 | Michael Hanselmann | (errcode, msg) = cmdlib._VerifyCertificate(invalid_cert) |
57 | b98bf262 | Michael Hanselmann | self.assertEqual(errcode, cmdlib.LUVerifyCluster.ETYPE_ERROR)
|
58 | b98bf262 | Michael Hanselmann | |
59 | b98bf262 | Michael Hanselmann | |
60 | b98bf262 | Michael Hanselmann | if __name__ == "__main__": |
61 | 25231ec5 | Michael Hanselmann | testutils.GanetiTestProgram() |