Revision af95196c
b/lib/bootstrap.py | ||
---|---|---|
472 | 472 |
ipolicy[constants.IPOLICY_DTS] = restricted_disk_templates |
473 | 473 |
|
474 | 474 |
|
475 |
def _InitCheckDrbdHelper(drbd_helper): |
|
476 |
"""Checks the DRBD usermode helper. |
|
477 |
|
|
478 |
@type drbd_helper: string |
|
479 |
@param drbd_helper: name of the DRBD usermode helper that the system should |
|
480 |
use |
|
481 |
|
|
482 |
""" |
|
483 |
if drbd_helper is not None: |
|
484 |
try: |
|
485 |
curr_helper = drbd.DRBD8.GetUsermodeHelper() |
|
486 |
except errors.BlockDeviceError, err: |
|
487 |
raise errors.OpPrereqError("Error while checking drbd helper" |
|
488 |
" (specify --no-drbd-storage if you are not" |
|
489 |
" using drbd): %s" % str(err), |
|
490 |
errors.ECODE_ENVIRON) |
|
491 |
if drbd_helper != curr_helper: |
|
492 |
raise errors.OpPrereqError("Error: requiring %s as drbd helper but %s" |
|
493 |
" is the current helper" % (drbd_helper, |
|
494 |
curr_helper), |
|
495 |
errors.ECODE_INVAL) |
|
496 |
|
|
497 |
|
|
475 | 498 |
def InitCluster(cluster_name, mac_prefix, # pylint: disable=R0913, R0914 |
476 | 499 |
master_netmask, master_netdev, file_storage_dir, |
477 | 500 |
shared_file_storage_dir, candidate_pool_size, secondary_ip=None, |
... | ... | |
569 | 592 |
if vgstatus: |
570 | 593 |
raise errors.OpPrereqError("Error: %s" % vgstatus, errors.ECODE_INVAL) |
571 | 594 |
|
572 |
if drbd_helper is not None: |
|
573 |
try: |
|
574 |
curr_helper = drbd.DRBD8.GetUsermodeHelper() |
|
575 |
except errors.BlockDeviceError, err: |
|
576 |
raise errors.OpPrereqError("Error while checking drbd helper" |
|
577 |
" (specify --no-drbd-storage if you are not" |
|
578 |
" using drbd): %s" % str(err), |
|
579 |
errors.ECODE_ENVIRON) |
|
580 |
if drbd_helper != curr_helper: |
|
581 |
raise errors.OpPrereqError("Error: requiring %s as drbd helper but %s" |
|
582 |
" is the current helper" % (drbd_helper, |
|
583 |
curr_helper), |
|
584 |
errors.ECODE_INVAL) |
|
595 |
_InitCheckDrbdHelper(drbd_helper) |
|
585 | 596 |
|
586 | 597 |
logging.debug("Stopping daemons (if any are running)") |
587 | 598 |
result = utils.RunCmd([pathutils.DAEMON_UTIL, "stop-all"]) |
b/test/py/ganeti.bootstrap_unittest.py | ||
---|---|---|
27 | 27 |
|
28 | 28 |
from ganeti import bootstrap |
29 | 29 |
from ganeti import constants |
30 |
from ganeti.storage import drbd |
|
30 | 31 |
from ganeti import errors |
31 | 32 |
from ganeti import pathutils |
32 | 33 |
|
... | ... | |
130 | 131 |
self.assertEqual(ipolicy[constants.IPOLICY_DTS], [constants.DT_PLAIN]) |
131 | 132 |
|
132 | 133 |
|
134 |
class TestInitCheckDrbdHelper(unittest.TestCase): |
|
135 |
|
|
136 |
@testutils.patch_object(drbd.DRBD8, "GetUsermodeHelper") |
|
137 |
def testHelperNone(self, drbd_mock_get_usermode_helper): |
|
138 |
current_helper = "/bin/helper" |
|
139 |
drbd_helper = None |
|
140 |
drbd_mock_get_usermode_helper.return_value = current_helper |
|
141 |
bootstrap._InitCheckDrbdHelper(drbd_helper) |
|
142 |
|
|
143 |
@testutils.patch_object(drbd.DRBD8, "GetUsermodeHelper") |
|
144 |
def testHelperOk(self, drbd_mock_get_usermode_helper): |
|
145 |
current_helper = "/bin/helper" |
|
146 |
drbd_helper = "/bin/helper" |
|
147 |
drbd_mock_get_usermode_helper.return_value = current_helper |
|
148 |
bootstrap._InitCheckDrbdHelper(drbd_helper) |
|
149 |
|
|
150 |
@testutils.patch_object(drbd.DRBD8, "GetUsermodeHelper") |
|
151 |
def testWrongHelper(self, drbd_mock_get_usermode_helper): |
|
152 |
current_helper = "/bin/otherhelper" |
|
153 |
drbd_helper = "/bin/helper" |
|
154 |
drbd_mock_get_usermode_helper.return_value = current_helper |
|
155 |
self.assertRaises(errors.OpPrereqError, |
|
156 |
bootstrap._InitCheckDrbdHelper, drbd_helper) |
|
157 |
|
|
158 |
@testutils.patch_object(drbd.DRBD8, "GetUsermodeHelper") |
|
159 |
def testHelperCheckFails(self, drbd_mock_get_usermode_helper): |
|
160 |
drbd_helper = "/bin/helper" |
|
161 |
drbd_mock_get_usermode_helper.side_effect=errors.BlockDeviceError |
|
162 |
self.assertRaises(errors.OpPrereqError, |
|
163 |
bootstrap._InitCheckDrbdHelper, drbd_helper) |
|
164 |
|
|
165 |
|
|
133 | 166 |
if __name__ == "__main__": |
134 | 167 |
testutils.GanetiTestProgram() |
Also available in: Unified diff