Revision 5030cff3
b/Makefile.am | ||
---|---|---|
1213 | 1213 |
test/py/ganeti.asyncnotifier_unittest.py \ |
1214 | 1214 |
test/py/ganeti.backend_unittest-runasroot.py \ |
1215 | 1215 |
test/py/ganeti.backend_unittest.py \ |
1216 |
test/py/ganeti.bootstrap_unittest.py \ |
|
1216 | 1217 |
test/py/ganeti.cli_unittest.py \ |
1217 | 1218 |
test/py/ganeti.client.gnt_cluster_unittest.py \ |
1218 | 1219 |
test/py/ganeti.client.gnt_instance_unittest.py \ |
b/lib/bootstrap.py | ||
---|---|---|
334 | 334 |
_WaitForSshDaemon(node, netutils.GetDaemonPort(constants.SSH), family) |
335 | 335 |
|
336 | 336 |
|
337 |
def _InitFileStorage(file_storage_dir): |
|
337 |
def _PrepareFileStorage(enabled_disk_templates, file_storage_dir): |
|
338 |
"""Checks if file storage is enabled and inits the dir. |
|
339 |
|
|
340 |
""" |
|
341 |
if utils.storage.IsFileStorageEnabled(enabled_disk_templates): |
|
342 |
file_storage_dir = _InitFileStorageDir(file_storage_dir) |
|
343 |
else: |
|
344 |
file_storage_dir = "" |
|
345 |
return file_storage_dir |
|
346 |
|
|
347 |
|
|
348 |
def _InitFileStorageDir(file_storage_dir): |
|
338 | 349 |
"""Initialize if needed the file storage. |
339 | 350 |
|
340 | 351 |
@param file_storage_dir: the user-supplied value |
... | ... | |
360 | 371 |
raise errors.OpPrereqError("The file storage directory '%s' is not" |
361 | 372 |
" a directory." % file_storage_dir, |
362 | 373 |
errors.ECODE_ENVIRON) |
374 |
|
|
375 |
# FIXME: check here if the file_storage_dir is in the set of allowed dirs |
|
363 | 376 |
return file_storage_dir |
364 | 377 |
|
365 | 378 |
|
379 |
def _InitCheckEnabledDiskTemplates(enabled_disk_templates): |
|
380 |
"""Checks the sanity of the enabled disk templates. |
|
381 |
|
|
382 |
""" |
|
383 |
if not enabled_disk_templates: |
|
384 |
raise errors.OpPrereqError("Enabled disk templates list must contain at" |
|
385 |
" least one member", errors.ECODE_INVAL) |
|
386 |
invalid_disk_templates = \ |
|
387 |
set(enabled_disk_templates) - constants.DISK_TEMPLATES |
|
388 |
if invalid_disk_templates: |
|
389 |
raise errors.OpPrereqError("Enabled disk templates list contains invalid" |
|
390 |
" entries: %s" % invalid_disk_templates, |
|
391 |
errors.ECODE_INVAL) |
|
392 |
|
|
393 |
|
|
366 | 394 |
def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913, R0914 |
367 | 395 |
master_netmask, master_netdev, file_storage_dir, |
368 | 396 |
shared_file_storage_dir, candidate_pool_size, secondary_ip=None, |
... | ... | |
396 | 424 |
" entries: %s" % invalid_hvs, |
397 | 425 |
errors.ECODE_INVAL) |
398 | 426 |
|
399 |
if not enabled_disk_templates: |
|
400 |
raise errors.OpPrereqError("Enabled disk templates list must contain at" |
|
401 |
" least one member", errors.ECODE_INVAL) |
|
402 |
invalid_disk_templates = \ |
|
403 |
set(enabled_disk_templates) - constants.DISK_TEMPLATES |
|
404 |
if invalid_disk_templates: |
|
405 |
raise errors.OpPrereqError("Enabled disk templates list contains invalid" |
|
406 |
" entries: %s" % invalid_disk_templates, |
|
407 |
errors.ECODE_INVAL) |
|
427 |
_InitCheckEnabledDiskTemplates(enabled_disk_templates) |
|
408 | 428 |
|
409 | 429 |
try: |
410 | 430 |
ipcls = netutils.IPAddress.GetClassFromIpVersion(primary_ip_version) |
... | ... | |
489 | 509 |
" had exitcode %s and error '%s'" % |
490 | 510 |
(result.cmd, result.exit_code, result.output)) |
491 | 511 |
|
492 |
if constants.ENABLE_FILE_STORAGE: |
|
493 |
file_storage_dir = _InitFileStorage(file_storage_dir) |
|
494 |
else: |
|
495 |
file_storage_dir = "" |
|
512 |
file_storage_dir = _PrepareFileStorage(enabled_disk_templates, |
|
513 |
file_storage_dir) |
|
496 | 514 |
|
497 | 515 |
if constants.ENABLE_SHARED_FILE_STORAGE: |
498 |
shared_file_storage_dir = _InitFileStorage(shared_file_storage_dir) |
|
516 |
shared_file_storage_dir = _InitFileStorageDir(shared_file_storage_dir)
|
|
499 | 517 |
else: |
500 | 518 |
shared_file_storage_dir = "" |
501 | 519 |
|
b/test/py/ganeti.bootstrap_unittest.py | ||
---|---|---|
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() |
Also available in: Unified diff