Statistics
| Branch: | Tag: | Revision:

root / test / ganeti.cmdlib_unittest.py @ 24d70417

History | View | Annotate | Download (1.7 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 cmdlib
32
from ganeti import errors
33

    
34
import testutils
35

    
36

    
37
class TestCertVerification(testutils.GanetiTestCase):
38
  def setUp(self):
39
    testutils.GanetiTestCase.setUp(self)
40

    
41
    self.tmpdir = tempfile.mkdtemp()
42

    
43
  def tearDown(self):
44
    shutil.rmtree(self.tmpdir)
45

    
46
  def testVerifyCertificate(self):
47
    cmdlib._VerifyCertificate(self._TestDataFilename("cert1.pem"))
48

    
49
    nonexist_filename = os.path.join(self.tmpdir, "does-not-exist")
50

    
51
    (errcode, msg) = cmdlib._VerifyCertificate(nonexist_filename)
52
    self.assertEqual(errcode, cmdlib.LUVerifyCluster.ETYPE_ERROR)
53

    
54
    # Try to load non-certificate file
55
    invalid_cert = self._TestDataFilename("bdev-net.txt")
56
    (errcode, msg) = cmdlib._VerifyCertificate(invalid_cert)
57
    self.assertEqual(errcode, cmdlib.LUVerifyCluster.ETYPE_ERROR)
58

    
59

    
60
if __name__ == "__main__":
61
  testutils.GanetiTestProgram()