backend: Check for shared storage also
[ganeti-local] / test / ganeti.backend_unittest.py
index f1aae63..ff9a33c 100755 (executable)
@@ -28,7 +28,9 @@ import tempfile
 import unittest
 
 from ganeti import utils
+from ganeti import constants
 from ganeti import backend
+from ganeti import netutils
 
 import testutils
 
@@ -69,5 +71,28 @@ class TestX509Certificates(unittest.TestCase):
     self.assertEqual(utils.ListVisibleFiles(self.tmpdir), [name])
 
 
+class TestNodeVerify(testutils.GanetiTestCase):
+  def testMasterIPLocalhost(self):
+    # this a real functional test, but requires localhost to be reachable
+    local_data = (netutils.Hostname.GetSysName(),
+                  constants.IP4_ADDRESS_LOCALHOST)
+    result = backend.VerifyNode({constants.NV_MASTERIP: local_data}, None)
+    self.failUnless(constants.NV_MASTERIP in result,
+                    "Master IP data not returned")
+    self.failUnless(result[constants.NV_MASTERIP], "Cannot reach localhost")
+
+  def testMasterIPUnreachable(self):
+    # Network 192.0.2.0/24 is reserved for test/documentation as per
+    # RFC 5737
+    bad_data =  ("master.example.com", "192.0.2.1")
+    # we just test that whatever TcpPing returns, VerifyNode returns too
+    netutils.TcpPing = lambda a, b, source=None: False
+    result = backend.VerifyNode({constants.NV_MASTERIP: bad_data}, None)
+    self.failUnless(constants.NV_MASTERIP in result,
+                    "Master IP data not returned")
+    self.failIf(result[constants.NV_MASTERIP],
+                "Result from netutils.TcpPing corrupted")
+
+
 if __name__ == "__main__":
   testutils.GanetiTestProgram()