Merge branch 'stable-2.8' into stable-2.9
[ganeti-local] / qa / qa_node.py
index 6081a02..16fdb15 100644 (file)
@@ -1,7 +1,7 @@
 #
 #
 
-# Copyright (C) 2007, 2011, 2012 Google Inc.
+# Copyright (C) 2007, 2011, 2012, 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
@@ -114,9 +114,18 @@ def TestNodeStorage():
   """gnt-node storage"""
   master = qa_config.GetMasterNode()
 
-  for storage_type in constants.VALID_STORAGE_TYPES:
+  # FIXME: test all storage_types in constants.STORAGE_TYPES
+  # as soon as they are implemented.
+  enabled_storage_types = qa_config.GetEnabledStorageTypes()
+  testable_storage_types = list(set(enabled_storage_types).intersection(
+      set([constants.ST_FILE, constants.ST_LVM_VG, constants.ST_LVM_PV])))
+
+  for storage_type in testable_storage_types:
+
+    cmd = ["gnt-node", "list-storage", "--storage-type", storage_type]
+
     # Test simple list
-    AssertCommand(["gnt-node", "list-storage", "--storage-type", storage_type])
+    AssertCommand(cmd)
 
     # Test all storage fields
     cmd = ["gnt-node", "list-storage", "--storage-type", storage_type,
@@ -188,6 +197,20 @@ def TestNodeFailover(node, node2):
   AssertCommand(["gnt-node", "failover", "-f", node2.primary])
 
 
+def TestNodeMigrate(node, node2):
+  """gnt-node migrate"""
+  if qa_utils.GetNodeInstances(node2, secondaries=False):
+    raise qa_error.UnusableNodeError("Secondary node has at least one"
+                                     " primary instance. This test requires"
+                                     " it to have no primary instances.")
+
+  # Migrate to secondary node
+  AssertCommand(["gnt-node", "migrate", "-f", node.primary])
+
+  # ... and back again.
+  AssertCommand(["gnt-node", "migrate", "-f", node2.primary])
+
+
 def TestNodeEvacuate(node, node2):
   """gnt-node evacuate"""
   node3 = qa_config.AcquireNode(exclude=[node, node2])
@@ -210,13 +233,19 @@ def TestNodeEvacuate(node, node2):
 
 def TestNodeModify(node):
   """gnt-node modify"""
+
+  # make sure enough master candidates will be available by disabling the
+  # master candidate role first with --auto-promote
+  AssertCommand(["gnt-node", "modify", "--master-candidate=no",
+                "--auto-promote", node.primary])
+
+  # now it's save to force-remove the master candidate role
   for flag in ["master-candidate", "drained", "offline"]:
     for value in ["yes", "no"]:
       AssertCommand(["gnt-node", "modify", "--force",
                      "--%s=%s" % (flag, value), node.primary])
 
-  AssertCommand(["gnt-node", "modify", "--master-candidate=yes",
-                 "--auto-promote", node.primary])
+  AssertCommand(["gnt-node", "modify", "--master-candidate=yes", node.primary])
 
   # Test setting secondary IP address
   AssertCommand(["gnt-node", "modify", "--secondary-ip=%s" % node.secondary,
@@ -425,3 +454,22 @@ def TestNodeListFields():
 def TestNodeListDrbd(node):
   """gnt-node list-drbd"""
   AssertCommand(["gnt-node", "list-drbd", node.primary])
+
+
+def _BuildSetESCmd(action, value, node_name):
+  cmd = ["gnt-node"]
+  if action == "add":
+    cmd.extend(["add", "--readd"])
+  else:
+    cmd.append("modify")
+  cmd.extend(["--node-parameters", "exclusive_storage=%s" % value, node_name])
+  return cmd
+
+
+def TestExclStorSingleNode(node):
+  """gnt-node add/modify cannot change the exclusive_storage flag.
+
+  """
+  for action in ["add", "modify"]:
+    for value in (True, False, "default"):
+      AssertCommand(_BuildSetESCmd(action, value, node.primary), fail=True)