From 53fde1ac4c85a65cc113124cf9567afbb95278ab Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Mon, 4 Feb 2013 11:10:14 +0100 Subject: [PATCH] Add a helper function for hypervisor verification This will allow easier multi-error results from hypervisors; right now, we only report the first error, which is not nice. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- lib/hypervisor/hv_base.py | 16 +++++++++++++++- test/py/ganeti.hypervisor_unittest.py | 12 +++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/hypervisor/hv_base.py b/lib/hypervisor/hv_base.py index 55e0bcb01..c723a4d30 100644 --- a/lib/hypervisor/hv_base.py +++ b/lib/hypervisor/hv_base.py @@ -1,7 +1,7 @@ # # -# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2012 Google Inc. +# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2012, 2013 Google Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -520,3 +520,17 @@ class BaseHypervisor(object): result = utils.RunCmd(["reboot", "-n", "-f"]) if not result: logging.error("Can't run shutdown: %s", result.output) + + @staticmethod + def _FormatVerifyResults(msgs): + """Formats the verification results, given a list of errors. + + @param msgs: list of errors, possibly empty + @return: overall problem description if something is wrong, + C{None} otherwise + + """ + if msgs: + return "; ".join(msgs) + else: + return None diff --git a/test/py/ganeti.hypervisor_unittest.py b/test/py/ganeti.hypervisor_unittest.py index c046f8e94..1d3e524e7 100755 --- a/test/py/ganeti.hypervisor_unittest.py +++ b/test/py/ganeti.hypervisor_unittest.py @@ -1,7 +1,7 @@ #!/usr/bin/python # -# Copyright (C) 2010 Google Inc. +# Copyright (C) 2010, 2013 Google Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -28,6 +28,7 @@ from ganeti import compat from ganeti import objects from ganeti import errors from ganeti import hypervisor +from ganeti.hypervisor import hv_base import testutils @@ -48,5 +49,14 @@ class TestParameters(unittest.TestCase): (hv, pname)) +class TestBase(unittest.TestCase): + def testVerifyResults(self): + fn = hv_base.BaseHypervisor._FormatVerifyResults + # FIXME: use assertIsNone when py 2.7 is minimum supported version + self.assertEqual(fn([]), None) + self.assertEqual(fn(["a"]), "a") + self.assertEqual(fn(["a", "b"]), "a; b") + + if __name__ == "__main__": testutils.GanetiTestProgram() -- GitLab