Test "GetNodeInfo" for Xen hypervisor
authorMichael Hanselmann <hansmi@google.com>
Wed, 6 Feb 2013 13:56:03 +0000 (14:56 +0100)
committerMichael Hanselmann <hansmi@google.com>
Wed, 20 Feb 2013 15:40:37 +0000 (16:40 +0100)
This patch adds unit tests for success and failure of the “GetNodeInfo”
method for the Xen hypervisor abstractions.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Helga Velroyen <helgav@google.com>

test/py/ganeti.hypervisor.hv_xen_unittest.py

index 057ac76..3679de4 100755 (executable)
@@ -716,6 +716,35 @@ class _TestXenHypervisor(object):
 
         self.assertEqual(ping_fn.Count(), expected_pings)
 
+  def _GetNodeInfoCmd(self, fail, cmd):
+    if cmd == [self.CMD, "info"]:
+      if fail:
+        return self._FailingCommand(cmd)
+      else:
+        output = testutils.ReadTestData("xen-xm-info-4.0.1.txt")
+    elif cmd == [self.CMD, "list"]:
+      if fail:
+        self.fail("'xm list' shouldn't be called when 'xm info' failed")
+      else:
+        output = testutils.ReadTestData("xen-xm-list-4.0.1-four-instances.txt")
+    else:
+      self.fail("Unhandled command: %s" % (cmd, ))
+
+    return self._SuccessCommand(output, cmd)
+
+  def testGetNodeInfo(self):
+    run_cmd = compat.partial(self._GetNodeInfoCmd, False)
+    hv = self._GetHv(run_cmd=run_cmd)
+    result = hv.GetNodeInfo()
+
+    self.assertEqual(result["hv_version"], (4, 0))
+    self.assertEqual(result["memory_free"], 8004)
+
+  def testGetNodeInfoFailing(self):
+    run_cmd = compat.partial(self._GetNodeInfoCmd, True)
+    hv = self._GetHv(run_cmd=run_cmd)
+    self.assertTrue(hv.GetNodeInfo() is None)
+
 
 def _MakeTestClass(cls, cmd):
   """Makes a class for testing.