Add unit test for LUInstanceQuery and -QueryData
authorThomas Thrainer <thomasth@google.com>
Tue, 27 Aug 2013 13:49:46 +0000 (15:49 +0200)
committerThomas Thrainer <thomasth@google.com>
Thu, 12 Sep 2013 12:56:56 +0000 (14:56 +0200)
This patch provides rudimentary unit test coverage for LUInstanceQuery
and LUInstanceQueryData.

Signed-off-by: Thomas Thrainer <thomasth@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>

Makefile.am
test/py/cmdlib/instance_query_unittest.py [new file with mode: 0644]

index e58aea2..2a184b0 100644 (file)
@@ -1322,6 +1322,7 @@ python_tests = \
        test/py/cmdlib/group_unittest.py \
        test/py/cmdlib/instance_unittest.py \
        test/py/cmdlib/instance_migration_unittest.py \
+       test/py/cmdlib/instance_query_unittest.py \
        test/py/cmdlib/instance_storage_unittest.py \
        test/py/cmdlib/test_unittest.py \
        test/py/cfgupgrade_unittest.py \
diff --git a/test/py/cmdlib/instance_query_unittest.py b/test/py/cmdlib/instance_query_unittest.py
new file mode 100644 (file)
index 0000000..68b651d
--- /dev/null
@@ -0,0 +1,68 @@
+#!/usr/bin/python
+#
+
+# Copyright (C) 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
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+
+"""Tests for LUInstanceFailover and LUInstanceMigrate
+
+"""
+
+from ganeti import opcodes
+from ganeti import query
+
+from testsupport import *
+
+import testutils
+
+
+class TestLUInstanceQuery(CmdlibTestCase):
+  def setUp(self):
+    super(TestLUInstanceQuery, self).setUp()
+
+    self.inst = self.cfg.AddNewInstance()
+    self.fields = query._BuildInstanceFields().keys()
+
+  def testInvalidInstance(self):
+    op = opcodes.OpInstanceQuery(names=["does_not_exist"],
+                                 output_fields=self.fields)
+    self.ExecOpCodeExpectOpPrereqError(
+      op, "Instance 'does_not_exist' not known")
+
+  def testQueryInstance(self):
+    op = opcodes.OpInstanceQuery(output_fields=self.fields)
+    self.ExecOpCode(op)
+
+
+class TestLUInstanceQueryData(CmdlibTestCase):
+  def setUp(self):
+    super(TestLUInstanceQueryData, self).setUp()
+
+    self.inst = self.cfg.AddNewInstance()
+
+  def testQueryInstanceData(self):
+    op = opcodes.OpInstanceQueryData()
+    self.ExecOpCode(op)
+
+  def testQueryStaticInstanceData(self):
+    op = opcodes.OpInstanceQueryData(static=True)
+    self.ExecOpCode(op)
+
+
+if __name__ == "__main__":
+  testutils.GanetiTestProgram()