root / test / py / ganeti.bootstrap_unittest.py @ 5030cff3
History | View | Annotate | Download (2.2 kB)
1 |
#!/usr/bin/python
|
---|---|
2 |
#
|
3 |
|
4 |
# Copyright (C) 2013 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 |
# 02110-1301, USA.
|
20 |
|
21 |
|
22 |
"""Script for testing ganeti.bootstrap"""
|
23 |
|
24 |
import shutil |
25 |
import tempfile |
26 |
import unittest |
27 |
|
28 |
from ganeti import bootstrap |
29 |
from ganeti import constants |
30 |
from ganeti import errors |
31 |
|
32 |
import testutils |
33 |
|
34 |
|
35 |
class TestPrepareFileStorage(unittest.TestCase): |
36 |
def setUp(self): |
37 |
self.tmpdir = tempfile.mkdtemp()
|
38 |
|
39 |
def tearDown(self): |
40 |
shutil.rmtree(self.tmpdir)
|
41 |
|
42 |
def testFileStorageEnabled(self): |
43 |
enabled_disk_templates = [constants.DT_FILE] |
44 |
file_storage_dir = bootstrap._PrepareFileStorage( |
45 |
enabled_disk_templates, self.tmpdir)
|
46 |
self.assertEqual(self.tmpdir, file_storage_dir) |
47 |
|
48 |
def testFileStorageDisabled(self): |
49 |
# anything != DT_FILE would do here
|
50 |
enabled_disk_templates = [constants.DT_PLAIN] |
51 |
file_storage_dir = bootstrap._PrepareFileStorage( |
52 |
enabled_disk_templates, self.tmpdir)
|
53 |
self.assertEqual('', file_storage_dir) |
54 |
|
55 |
|
56 |
class TestInitCheckEnabledDiskTemplates(unittest.TestCase): |
57 |
def testValidTemplates(self): |
58 |
enabled_disk_templates = list(constants.DISK_TEMPLATES)
|
59 |
bootstrap._InitCheckEnabledDiskTemplates(enabled_disk_templates) |
60 |
|
61 |
def testInvalidTemplates(self): |
62 |
enabled_disk_templates = ["pinkbunny"]
|
63 |
self.assertRaises(errors.OpPrereqError,
|
64 |
bootstrap._InitCheckEnabledDiskTemplates, enabled_disk_templates) |
65 |
|
66 |
def testEmptyTemplates(self): |
67 |
enabled_disk_templates = [] |
68 |
self.assertRaises(errors.OpPrereqError,
|
69 |
bootstrap._InitCheckEnabledDiskTemplates, enabled_disk_templates) |
70 |
|
71 |
|
72 |
if __name__ == "__main__": |
73 |
testutils.GanetiTestProgram() |