Revision b01b7a50
b/lib/backend.py | ||
---|---|---|
573 | 573 |
raise errors.QuitGanetiException(True, "Shutdown scheduled") |
574 | 574 |
|
575 | 575 |
|
576 |
def _CheckStorageParams(params, num_params): |
|
577 |
"""Performs sanity checks for storage parameters. |
|
578 |
|
|
579 |
@type params: list |
|
580 |
@param params: list of storage parameters |
|
581 |
@type num_params: int |
|
582 |
@param num_params: expected number of parameters |
|
583 |
|
|
584 |
""" |
|
585 |
if params is None: |
|
586 |
raise errors.ProgrammerError("No storage parameters for storage" |
|
587 |
" reporting is provided.") |
|
588 |
if not isinstance(params, list): |
|
589 |
raise errors.ProgrammerError("The storage parameters are not of type" |
|
590 |
" list: '%s'" % params) |
|
591 |
if not len(params) == num_params: |
|
592 |
raise errors.ProgrammerError("Did not receive the expected number of" |
|
593 |
"storage parameters: expected %s," |
|
594 |
" received '%s'" % (num_params, len(params))) |
|
595 |
|
|
596 |
|
|
576 | 597 |
def _GetLvmVgSpaceInfo(name, params): |
577 | 598 |
"""Wrapper around C{_GetVgInfo} which checks the storage parameters. |
578 | 599 |
|
... | ... | |
583 | 604 |
containing only one for exclusive storage |
584 | 605 |
|
585 | 606 |
""" |
586 |
if params is None: |
|
587 |
raise errors.ProgrammerError("No storage parameter for LVM vg storage" |
|
588 |
" reporting is provided.") |
|
589 |
if not isinstance(params, list): |
|
590 |
raise errors.ProgrammerError("The storage parameters are not of type" |
|
591 |
" list: '%s'" % params) |
|
592 |
if not len(params) == 1: |
|
593 |
raise errors.ProgrammerError("Received more than one storage parameter:" |
|
594 |
" '%s'" % params) |
|
607 |
_CheckStorageParams(params, 1) |
|
595 | 608 |
excl_stor = bool(params[0]) |
596 | 609 |
return _GetVgInfo(name, excl_stor) |
597 | 610 |
|
... | ... | |
715 | 728 |
return (bootid, storage_info, hv_info) |
716 | 729 |
|
717 | 730 |
|
718 |
# pylint: disable=W0613 |
|
719 |
def _GetFileStorageSpaceInfo(path, *args): |
|
731 |
def _GetFileStorageSpaceInfo(path, params): |
|
720 | 732 |
"""Wrapper around filestorage.GetSpaceInfo. |
721 | 733 |
|
722 | 734 |
The purpose of this wrapper is to call filestorage.GetFileStorageSpaceInfo |
... | ... | |
727 | 739 |
parameters. |
728 | 740 |
|
729 | 741 |
""" |
742 |
_CheckStorageParams(params, 0) |
|
730 | 743 |
return filestorage.GetFileStorageSpaceInfo(path) |
731 | 744 |
|
732 | 745 |
|
b/test/py/ganeti.backend_unittest.py | ||
---|---|---|
21 | 21 |
|
22 | 22 |
"""Script for testing ganeti.backend""" |
23 | 23 |
|
24 |
import mock |
|
24 | 25 |
import os |
25 | 26 |
import shutil |
26 | 27 |
import tempfile |
28 |
import testutils |
|
27 | 29 |
import unittest |
28 |
import mock |
|
29 | 30 |
|
30 |
from ganeti import utils |
|
31 |
from ganeti import constants |
|
32 | 31 |
from ganeti import backend |
33 |
from ganeti import netutils |
|
32 |
from ganeti import constants |
|
33 |
from ganeti import errors |
|
34 | 34 |
from ganeti import hypervisor |
35 |
|
|
36 |
import testutils
|
|
35 |
from ganeti import netutils |
|
36 |
from ganeti import utils
|
|
37 | 37 |
|
38 | 38 |
|
39 | 39 |
class TestX509Certificates(unittest.TestCase): |
... | ... | |
618 | 618 |
class TestApplyStorageInfoFunction(unittest.TestCase): |
619 | 619 |
|
620 | 620 |
_STORAGE_KEY = "some_key" |
621 |
_SOME_ARGS = "some_args"
|
|
621 |
_SOME_ARGS = ["some_args"]
|
|
622 | 622 |
|
623 | 623 |
def setUp(self): |
624 | 624 |
self.mock_storage_fn = mock.Mock() |
... | ... | |
650 | 650 |
storage_type, self._STORAGE_KEY, self._SOME_ARGS) |
651 | 651 |
|
652 | 652 |
|
653 |
class TestCheckStorageParams(unittest.TestCase): |
|
654 |
|
|
655 |
def testParamsNone(self): |
|
656 |
self.assertRaises(errors.ProgrammerError, backend._CheckStorageParams, |
|
657 |
None, NotImplemented) |
|
658 |
|
|
659 |
def testParamsWrongType(self): |
|
660 |
self.assertRaises(errors.ProgrammerError, backend._CheckStorageParams, |
|
661 |
"string", NotImplemented) |
|
662 |
|
|
663 |
def testParamsEmpty(self): |
|
664 |
backend._CheckStorageParams([], 0) |
|
665 |
|
|
666 |
def testParamsValidNumber(self): |
|
667 |
backend._CheckStorageParams(["a", True], 2) |
|
668 |
|
|
669 |
def testParamsInvalidNumber(self): |
|
670 |
self.assertRaises(errors.ProgrammerError, backend._CheckStorageParams, |
|
671 |
["b", False], 3) |
|
672 |
|
|
673 |
|
|
653 | 674 |
class TestGetNodeInfo(unittest.TestCase): |
654 | 675 |
|
655 | 676 |
_SOME_RESULT = None |
Also available in: Unified diff