Change all “Verify” methods in hypervisor abstractions to explicitely return None if no problem was detected. Remove punctuation from error messages. Update docstrings with “@return” and some small mistakes.
Signed-off-by: Michael Hanselmann <[email protected]> --- lib/hypervisor/hv_base.py | 2 ++ lib/hypervisor/hv_chroot.py | 8 ++++++-- lib/hypervisor/hv_fake.py | 8 ++++++-- lib/hypervisor/hv_kvm.py | 9 ++++++--- lib/hypervisor/hv_lxc.py | 10 +++++++--- lib/hypervisor/hv_xen.py | 4 ++++ 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/lib/hypervisor/hv_base.py b/lib/hypervisor/hv_base.py index 582c9b9..55e0bcb 100644 --- a/lib/hypervisor/hv_base.py +++ b/lib/hypervisor/hv_base.py @@ -266,6 +266,8 @@ class BaseHypervisor(object): def Verify(self): """Verify the hypervisor. + @return: Problem description if something is wrong, C{None} otherwise + """ raise NotImplementedError diff --git a/lib/hypervisor/hv_chroot.py b/lib/hypervisor/hv_chroot.py index 77c6d23..5d88447 100644 --- a/lib/hypervisor/hv_chroot.py +++ b/lib/hypervisor/hv_chroot.py @@ -281,9 +281,13 @@ class ChrootManager(hv_base.BaseHypervisor): For the chroot manager, it just checks the existence of the base dir. + @return: Problem description if something is wrong, C{None} otherwise + """ - if not os.path.exists(self._ROOT_DIR): - return "The required directory '%s' does not exist." % self._ROOT_DIR + if os.path.exists(self._ROOT_DIR): + return None + else: + return "The required directory '%s' does not exist" % self._ROOT_DIR @classmethod def PowercycleNode(cls): diff --git a/lib/hypervisor/hv_fake.py b/lib/hypervisor/hv_fake.py index 0f85e8c..c99e822 100644 --- a/lib/hypervisor/hv_fake.py +++ b/lib/hypervisor/hv_fake.py @@ -239,9 +239,13 @@ class FakeHypervisor(hv_base.BaseHypervisor): For the fake hypervisor, it just checks the existence of the base dir. + @return: Problem description if something is wrong, C{None} otherwise + """ - if not os.path.exists(self._ROOT_DIR): - return "The required directory '%s' does not exist." % self._ROOT_DIR + if os.path.exists(self._ROOT_DIR): + return None + else: + return "The required directory '%s' does not exist" % self._ROOT_DIR @classmethod def PowercycleNode(cls): diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py index bef3ab8..20fddca 100644 --- a/lib/hypervisor/hv_kvm.py +++ b/lib/hypervisor/hv_kvm.py @@ -2019,16 +2019,19 @@ class KVMHypervisor(hv_base.BaseHypervisor): def Verify(self): """Verify the hypervisor. - Check that the binary exists. + Check that the required binaries exist. + + @return: Problem description if something is wrong, C{None} otherwise """ # FIXME: this is the global kvm version, but the actual version can be # customized as an hv parameter. we should use the nodegroup's default kvm # path parameter here. if not os.path.exists(constants.KVM_PATH): - return "The kvm binary ('%s') does not exist." % constants.KVM_PATH + return "The KVM binary ('%s') does not exist" % constants.KVM_PATH if not os.path.exists(constants.SOCAT_PATH): - return "The socat binary ('%s') does not exist." % constants.SOCAT_PATH + return "The socat binary ('%s') does not exist" % constants.SOCAT_PATH + return None @classmethod def CheckParameterSyntax(cls, hvparams): diff --git a/lib/hypervisor/hv_lxc.py b/lib/hypervisor/hv_lxc.py index 294b789..2339034 100644 --- a/lib/hypervisor/hv_lxc.py +++ b/lib/hypervisor/hv_lxc.py @@ -401,11 +401,15 @@ class LXCHypervisor(hv_base.BaseHypervisor): def Verify(self): """Verify the hypervisor. - For the chroot manager, it just checks the existence of the base dir. + For the LXC manager, it just checks the existence of the base dir. + + @return: Problem description if something is wrong, C{None} otherwise """ - if not os.path.exists(self._ROOT_DIR): - return "The required directory '%s' does not exist." % self._ROOT_DIR + if os.path.exists(self._ROOT_DIR): + return None + else: + return "The required directory '%s' does not exist" % self._ROOT_DIR @classmethod def PowercycleNode(cls): diff --git a/lib/hypervisor/hv_xen.py b/lib/hypervisor/hv_xen.py index 84c87d2..623f1bd 100644 --- a/lib/hypervisor/hv_xen.py +++ b/lib/hypervisor/hv_xen.py @@ -435,11 +435,15 @@ class XenHypervisor(hv_base.BaseHypervisor): For Xen, this verifies that the xend process is running. + @return: Problem description if something is wrong, C{None} otherwise + """ result = utils.RunCmd([constants.XEN_CMD, "info"]) if result.failed: return "'xm info' failed: %s, %s" % (result.fail_reason, result.output) + return None + @staticmethod def _GetConfigFileDiskData(block_devices, blockdev_prefix): """Get disk directive for xen config file. -- 1.8.1
