Commit 53fde1ac authored by Iustin Pop's avatar Iustin Pop
Browse files

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: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent e4157912
#
#
# 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
#!/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()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment