Move the pseudo-secret generation to utils.py
[ganeti-local] / qa / qa_node.py
index 6b29d04..6caa48e 100644 (file)
@@ -1,3 +1,6 @@
+#
+#
+
 # Copyright (C) 2007 Google Inc.
 #
 # This program is free software; you can redistribute it and/or modify
@@ -25,15 +28,19 @@ import qa_utils
 from qa_utils import AssertEqual, StartSSH
 
 
-def _NodeAdd(node):
+def _NodeAdd(node, readd=False):
   master = qa_config.GetMasterNode()
 
-  if node.get('_added', False):
+  if not readd and node.get('_added', False):
     raise qa_error.Error("Node %s already in cluster" % node['primary'])
+  elif readd and not node.get('_added', False):
+    raise qa_error.Error("Node %s not yet in cluster" % node['primary'])
 
-  cmd = ['gnt-node', 'add']
+  cmd = ['gnt-node', 'add', "--no-ssh-key-check"]
   if node.get('secondary', None):
     cmd.append('--secondary-ip=%s' % node['secondary'])
+  if readd:
+    cmd.append('--readd')
   cmd.append(node['primary'])
   AssertEqual(StartSSH(master['primary'],
                        utils.ShellQuoteArgs(cmd)).wait(), 0)
@@ -55,7 +62,7 @@ def TestNodeAddAll():
   master = qa_config.GetMasterNode()
   for node in qa_config.get('nodes'):
     if node != master:
-      _NodeAdd(node)
+      _NodeAdd(node, readd=False)
 
 
 def TestNodeRemoveAll():
@@ -66,6 +73,11 @@ def TestNodeRemoveAll():
       _NodeRemove(node)
 
 
+def TestNodeReadd(node):
+  """gnt-node add --readd"""
+  _NodeAdd(node, readd=True)
+
+
 def TestNodeInfo():
   """gnt-node info"""
   master = qa_config.GetMasterNode()
@@ -88,10 +100,10 @@ def TestNodeFailover(node, node2):
   """gnt-node failover"""
   master = qa_config.GetMasterNode()
 
-  if qa_utils.GetNodeInstances(node2):
-    raise qa_errors.UnusableNodeError("Secondary node has at least one "
-                                      "primary instance. This test requires "
-                                      "it to have no primary instances.")
+  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.")
 
   # Fail over to secondary node
   cmd = ['gnt-node', 'failover', '-f', node['primary']]
@@ -110,10 +122,10 @@ def TestNodeEvacuate(node, node2):
 
   node3 = qa_config.AcquireNode(exclude=[node, node2])
   try:
-    if qa_utils.GetNodeInstances(node3):
-      raise qa_errors.UnusableNodeError("Evacuation node has at least one "
-                                        "secondary instance. This test requires "
-                                        "it to have no secondary instances.")
+    if qa_utils.GetNodeInstances(node3, secondaries=True):
+      raise qa_error.UnusableNodeError("Evacuation node has at least one"
+                                       " secondary instance. This test requires"
+                                       " it to have no secondary instances.")
 
     # Evacuate all secondary instances
     cmd = ['gnt-node', 'evacuate', '-f', node2['primary'], node3['primary']]