Mock InitDrbdHelper's output in unittests
authorHelga Velroyen <helgav@google.com>
Thu, 28 Jan 2016 17:56:45 +0000 (18:56 +0100)
committerHelga Velroyen <helgav@google.com>
Thu, 28 Jan 2016 18:13:27 +0000 (19:13 +0100)
The output of the InitDrbdHelper function was cluttering up
the unit tests. Let's mock that output in tests.

Signed-off-by: Helga Velroyen <helgav@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>

lib/client/gnt_cluster.py
test/py/ganeti.client.gnt_cluster_unittest.py

index 5c2c576..40792e2 100644 (file)
@@ -126,15 +126,15 @@ def _InitVgName(opts, enabled_disk_templates):
   return vg_name
 
 
-def _InitDrbdHelper(opts, enabled_disk_templates):
+def _InitDrbdHelper(opts, enabled_disk_templates, feedback_fn=ToStdout):
   """Initialize the DRBD usermode helper.
 
   """
   drbd_enabled = constants.DT_DRBD8 in enabled_disk_templates
 
   if not drbd_enabled and opts.drbd_helper is not None:
-    ToStdout("Note: You specified a DRBD usermode helper, while DRBD storage"
-             " is not enabled.")
+    feedback_fn("Note: You specified a DRBD usermode helper, while DRBD storage"
+                " is not enabled.")
 
   if drbd_enabled:
     if opts.drbd_helper is None:
index be28eb2..a087a54 100755 (executable)
@@ -293,21 +293,24 @@ class InitDrbdHelper(DrbdHelperTestCase):
     opts = mock.Mock()
     opts.drbd_helper = None
     self.disableDrbd()
-    helper = gnt_cluster._InitDrbdHelper(opts, self.enabled_disk_templates)
+    helper = gnt_cluster._InitDrbdHelper(opts, self.enabled_disk_templates,
+                                         feedback_fn=mock.Mock())
     self.assertEquals(None, helper)
 
   def testNoDrbdHelper(self):
     opts = mock.Mock()
     self.disableDrbd()
     opts.drbd_helper = "/bin/true"
-    helper = gnt_cluster._InitDrbdHelper(opts, self.enabled_disk_templates)
+    helper = gnt_cluster._InitDrbdHelper(opts, self.enabled_disk_templates,
+                                         feedback_fn=mock.Mock())
     self.assertEquals(opts.drbd_helper, helper)
 
   def testDrbdHelperNone(self):
     opts = mock.Mock()
     self.enableDrbd()
     opts.drbd_helper = None
-    helper = gnt_cluster._InitDrbdHelper(opts, self.enabled_disk_templates)
+    helper = gnt_cluster._InitDrbdHelper(opts, self.enabled_disk_templates,
+                                         feedback_fn=mock.Mock())
     self.assertEquals(constants.DEFAULT_DRBD_HELPER, helper)
 
   def testDrbdHelperEmpty(self):
@@ -315,13 +318,14 @@ class InitDrbdHelper(DrbdHelperTestCase):
     self.enableDrbd()
     opts.drbd_helper = ''
     self.assertRaises(errors.OpPrereqError, gnt_cluster._InitDrbdHelper, opts,
-        self.enabled_disk_templates)
+        self.enabled_disk_templates, feedback_fn=mock.Mock())
 
   def testDrbdHelper(self):
     opts = mock.Mock()
     self.enableDrbd()
     opts.drbd_helper = "/bin/true"
-    helper = gnt_cluster._InitDrbdHelper(opts, self.enabled_disk_templates)
+    helper = gnt_cluster._InitDrbdHelper(opts, self.enabled_disk_templates,
+                                         feedback_fn=mock.Mock())
     self.assertEquals(opts.drbd_helper, helper)