4 # Copyright (C) 2010 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 testing ganeti.backend"""
30 from ganeti import utils
31 from ganeti import backend
36 class TestX509Certificates(unittest.TestCase):
38 self.tmpdir = tempfile.mkdtemp()
41 shutil.rmtree(self.tmpdir)
44 (name, cert_pem) = backend.CreateX509Certificate(300, cryptodir=self.tmpdir)
46 self.assertEqual(utils.ReadFile(os.path.join(self.tmpdir, name,
47 backend._X509_CERT_FILE)),
49 self.assert_(0 < os.path.getsize(os.path.join(self.tmpdir, name,
50 backend._X509_KEY_FILE)))
52 (name2, cert_pem2) = \
53 backend.CreateX509Certificate(300, cryptodir=self.tmpdir)
55 backend.RemoveX509Certificate(name, cryptodir=self.tmpdir)
56 backend.RemoveX509Certificate(name2, cryptodir=self.tmpdir)
58 self.assertEqual(utils.ListVisibleFiles(self.tmpdir), [])
60 def testNonEmpty(self):
61 (name, _) = backend.CreateX509Certificate(300, cryptodir=self.tmpdir)
63 utils.WriteFile(utils.PathJoin(self.tmpdir, name, "hello-world"),
66 self.assertRaises(backend.RPCFail, backend.RemoveX509Certificate,
67 name, cryptodir=self.tmpdir)
69 self.assertEqual(utils.ListVisibleFiles(self.tmpdir), [name])
72 if __name__ == "__main__":
73 testutils.GanetiTestProgram()