4 # Copyright (C) 2008 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 unittesting the cmdlib module"""
31 from ganeti import cmdlib
32 from ganeti import errors
37 class TestCertVerification(testutils.GanetiTestCase):
39 testutils.GanetiTestCase.setUp(self)
41 self.tmpdir = tempfile.mkdtemp()
44 shutil.rmtree(self.tmpdir)
46 def testVerifyCertificate(self):
47 cmdlib._VerifyCertificate(self._TestDataFilename("cert1.pem"))
49 nonexist_filename = os.path.join(self.tmpdir, "does-not-exist")
51 (errcode, msg) = cmdlib._VerifyCertificate(nonexist_filename)
52 self.assertEqual(errcode, cmdlib.LUVerifyCluster.ETYPE_ERROR)
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)
60 if __name__ == "__main__":
61 testutils.GanetiTestProgram()