This adds a script for the QA of 'gnt-network'. So far it
covers adding/removing and connecting/disconnecting networks.

Signed-off-by: Helga Velroyen <hel...@google.com>
---
 qa/ganeti-qa.py   |   10 ++++++
 qa/qa-sample.json |   12 ++++++-
 qa/qa_network.py  |   89 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 110 insertions(+), 1 deletions(-)
 create mode 100644 qa/qa_network.py

diff --git a/qa/ganeti-qa.py b/qa/ganeti-qa.py
index 26c2407..987517e 100755
--- a/qa/ganeti-qa.py
+++ b/qa/ganeti-qa.py
@@ -37,6 +37,7 @@ import qa_env
 import qa_error
 import qa_group
 import qa_instance
+import qa_network
 import qa_node
 import qa_os
 import qa_job
@@ -324,6 +325,14 @@ def RunGroupListTests():
   RunTestIf("group-list", qa_group.TestGroupListFields)
 
 
+def RunNetworkTests():
+  """Run tests for network management.
+
+  """
+  RunTestIf("network", qa_network.TestNetworkAddRemove)
+  RunTestIf("network", qa_network.TestNetworkConnect)
+
+
 def RunGroupRwTests():
   """Run tests for adding/removing/renaming groups.
 
@@ -478,6 +487,7 @@ def RunQa():
   RunCommonNodeTests()
   RunGroupListTests()
   RunGroupRwTests()
+  RunNetworkTests()
 
   # The master shouldn't be readded or put offline; "delay" needs a non-master
   # node to test
diff --git a/qa/qa-sample.json b/qa/qa-sample.json
index 15be20e..c81e915 100644
--- a/qa/qa-sample.json
+++ b/qa/qa-sample.json
@@ -84,6 +84,14 @@
     ]
   },
 
+  "networks": {
+    "inexistent-networks": [
+      "network1",
+      "network2",
+      "network3",
+    ]
+  }
+
   "tests": {
     "# Whether tests are enabled or disabled by default": null,
     "default": true,
@@ -171,7 +179,9 @@
     "# Make sure not to include the disk(s) required for Dom0 to be up": null,
     "# in the volume group used for instances. Otherwise the whole": null,
     "# system may stop working until restarted.": null,
-    "instance-disk-failure": false
+    "instance-disk-failure": false,
+
+    "network": false
   },
 
   "options": {
diff --git a/qa/qa_network.py b/qa/qa_network.py
new file mode 100644
index 0000000..6eeb099
--- /dev/null
+++ b/qa/qa_network.py
@@ -0,0 +1,89 @@
+#
+#
+
+# 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.
+
+
+"""QA tests for networks.
+
+"""
+
+import qa_config
+import qa_utils
+
+from qa_utils import AssertCommand
+
+
+def GetNonexistentNetworks(count):
+  """Gets network names which shouldn't exist on the cluster.
+
+  @param count: Number of networks to get
+  @rtype: list
+
+  """
+  networks = qa_config.get("networks", {})
+
+  default = ["network1", "network2", "network3"]
+  assert count <= len(default)
+
+  candidates = networks.get("inexistent-networks", default)[:count]
+
+  if len(candidates) < count:
+    raise Exception("At least %s non-existent networks are needed" % count)
+
+  return candidates
+
+
+def TestNetworkAddRemove():
+  """gnt-network add/remove"""
+  (network1, network2) = GetNonexistentNetworks(2)
+
+  # Add some networks of different sizes
+  AssertCommand(["gnt-network", "add", "--network", "192.168.0.1/30", 
network1])
+  AssertCommand(["gnt-network", "add", "--network", "192.168.1.0/24", 
network2])
+  # Try to add a network with an existing name.
+  AssertCommand(["gnt-network", "add", "--network", "192.168.2.0/24", 
network2],
+                fail=True)
+
+  AssertCommand(["gnt-network", "remove", network1])
+  AssertCommand(["gnt-network", "remove", network2])
+
+
+def TestNetworkConnect():
+  """gnt-network connect/disconnect"""
+  (group1, ) = qa_utils.GetNonexistentGroups(1)
+  (network1, ) = GetNonexistentNetworks(1)
+
+  default_mode = "bridged"
+  default_link = "xen-br0"
+  nicparams = qa_config.get("default-nicparams")
+  if nicparams:
+    mode = nicparams.get("mode", default_mode)
+    link = nicparams.get("link", default_link)
+  else:
+    mode = default_mode
+    link = default_link
+
+  AssertCommand(["gnt-group", "add", group1])
+  AssertCommand(["gnt-network", "add", "--network", "192.168.0.1/24", 
network1])
+
+  AssertCommand(["gnt-network", "connect", network1, mode, link, group1])
+  AssertCommand(["gnt-network", "disconnect", network1, group1])
+
+  AssertCommand(["gnt-group", "remove", group1])
+  AssertCommand(["gnt-network", "remove", network1])
-- 
1.7.7.3

Reply via email to