hv_xen: Test errors while writing config file
authorMichael Hanselmann <hansmi@google.com>
Thu, 24 Jan 2013 14:02:42 +0000 (15:02 +0100)
committerMichael Hanselmann <hansmi@google.com>
Fri, 25 Jan 2013 10:58:43 +0000 (11:58 +0100)
Test error handling while writing Xen configuration files.

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

test/py/ganeti.hypervisor.hv_xen_unittest.py

index 67dc785..fd05933 100755 (executable)
@@ -23,6 +23,8 @@
 
 import string # pylint: disable=W0402
 import unittest
+import tempfile
+import shutil
 
 from ganeti import constants
 from ganeti import objects
@@ -298,5 +300,29 @@ class TestXenHypervisorUnknownCommand(unittest.TestCase):
     self.assertRaises(errors.ProgrammerError, hv._RunXen, [])
 
 
+class TestXenHypervisorWriteConfigFile(unittest.TestCase):
+  def setUp(self):
+    self.tmpdir = tempfile.mkdtemp()
+
+  def tearDown(self):
+    shutil.rmtree(self.tmpdir)
+
+  def testWriteError(self):
+    cfgdir = utils.PathJoin(self.tmpdir, "foobar")
+
+    hv = hv_xen.XenHypervisor(_cfgdir=cfgdir,
+                              _run_cmd_fn=NotImplemented,
+                              _cmd=NotImplemented)
+
+    self.assertFalse(os.path.exists(cfgdir))
+
+    try:
+      hv._WriteConfigFile("name", "data")
+    except errors.HypervisorError, err:
+      self.assertTrue(str(err).startswith("Cannot write Xen instance"))
+    else:
+      self.fail("Exception was not raised")
+
+
 if __name__ == "__main__":
   testutils.GanetiTestProgram()