This patch adds node_unittest.py containing the framework for unit
testing LUNodeAdd.
At this point, only generic tests and tests for OpenvSwitch are
implemented.

Signed-off-by: Sebastian Gebhard <[email protected]>
---
 test/py/cmdlib/node_unittest.py | 102 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 102 insertions(+)
 create mode 100644 test/py/cmdlib/node_unittest.py

diff --git a/test/py/cmdlib/node_unittest.py b/test/py/cmdlib/node_unittest.py
new file mode 100644
index 0000000..0af499b
--- /dev/null
+++ b/test/py/cmdlib/node_unittest.py
@@ -0,0 +1,102 @@
+#!/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 LUNode*
+
+"""
+
+from collections import defaultdict
+
+from ganeti import constants
+from ganeti import objects
+from ganeti import opcodes
+
+from testsupport import *
+
+import testutils
+
+
+class TestLUNodeAdd(CmdlibTestCase):
+  def setUp(self):
+    super(TestLUNodeAdd, self).setUp()
+
+    # don't add to configuration now!
+    self.node = objects.Node(name="node1")
+    self.op = opcodes.OpNodeAdd(node_name=self.node.name,
+                                secondary_ip="127.0.1.1")
+
+    self.netutils_mod.TcpPing.return_value = True
+
+    self.mocked_dns_rpc = self.rpc_mod.DnsOnlyRunner.return_value
+
+    self.mocked_dns_rpc.call_version.return_value = \
+      self.RpcResultsBuilder(use_node_names=True) \
+        .AddSuccessfulNode(self.node, constants.CONFIG_VERSION) \
+        .Build()
+
+    node_verify_result = \
+      self.RpcResultsBuilder() \
+        .CreateSuccessfulNodeResult(self.node, {constants.NV_NODELIST: []})
+    # we can't know the node's UUID in advance, so use defaultdict here
+    self.rpc.call_node_verify.return_value = \
+      defaultdict(lambda: node_verify_result, {})
+
+  def testOvsParamsButNotEnabled(self):
+    ndparams = {
+      constants.ND_OVS: False,
+      constants.ND_OVS_NAME: "testswitch",
+    }
+    op = self.CopyOpCode(self.op,
+                         ndparams=ndparams)
+    self.ExecOpCodeExpectOpPrereqError(op, "OpenvSwitch is not enabled")
+
+  def testOvsNoLink(self):
+    ndparams = {
+      constants.ND_OVS: True,
+      constants.ND_OVS_NAME: "testswitch",
+      constants.ND_OVS_LINK: "",
+    }
+    op = self.CopyOpCode(self.op,
+                         ndparams=ndparams)
+
+    self.ExecOpCode(op)
+    self.assertLogContainsRegex(
+      "No physical interface for OpenvSwitch was given."
+      " OpenvSwitch will not have an outside connection."
+      " This might not be what you want")
+
+  def testWithOVS(self):
+    ndparams = {
+      constants.ND_OVS: True,
+      constants.ND_OVS_LINK: "eth2",
+    }
+    op = self.CopyOpCode(self.op,
+                         ndparams=ndparams)
+    print(str(self.cfg._config_data.nodes))
+    self.ExecOpCode(op)
+    print(str(self.cfg._config_data.nodes))
+
+  def testWithoutOVS(self):
+    op = self.CopyOpCode(self.op)
+    self.ExecOpCode(op)
+
+if __name__ == "__main__":
+  testutils.GanetiTestProgram()
-- 
1.8.1.2

Reply via email to