Modify gnt-node add to call external script
[ganeti-local] / qa / qa_cluster.py
index 7e74ff9..e854501 100644 (file)
@@ -1,7 +1,7 @@
 #
 #
 
-# Copyright (C) 2007 Google Inc.
+# Copyright (C) 2007, 2010 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
@@ -26,7 +26,6 @@
 import tempfile
 
 from ganeti import constants
-from ganeti import bootstrap
 from ganeti import utils
 
 import qa_config
@@ -81,6 +80,9 @@ def TestClusterInit(rapi_user, rapi_secret):
   # Initialize cluster
   cmd = ['gnt-cluster', 'init']
 
+  cmd.append("--primary-ip-version=%d" %
+             qa_config.get("primary_ip_version", 4))
+
   if master.get('secondary', None):
     cmd.append('--secondary-ip=%s' % master['secondary'])
 
@@ -137,6 +139,27 @@ def TestClusterVerify():
   AssertEqual(StartSSH(master['primary'],
                        utils.ShellQuoteArgs(cmd)).wait(), 0)
 
+def TestClusterReservedLvs():
+  """gnt-cluster reserved lvs"""
+  master = qa_config.GetMasterNode()
+  CVERIFY = ['gnt-cluster', 'verify']
+  for rcode, cmd in [
+    (0, CVERIFY),
+    (0, ['gnt-cluster', 'modify', '--reserved-lvs', '']),
+    (0, ['lvcreate', '-L1G', '-nqa-test', 'xenvg']),
+    (1, CVERIFY),
+    (0, ['gnt-cluster', 'modify', '--reserved-lvs', 'qa-test,other-test']),
+    (0, CVERIFY),
+    (0, ['gnt-cluster', 'modify', '--reserved-lvs', 'qa-.*']),
+    (0, CVERIFY),
+    (0, ['gnt-cluster', 'modify', '--reserved-lvs', '']),
+    (1, CVERIFY),
+    (0, ['lvremove', '-f', 'xenvg/qa-test']),
+    (0, CVERIFY),
+    ]:
+    AssertEqual(StartSSH(master['primary'],
+                         utils.ShellQuoteArgs(cmd)).wait(), rcode)
+
 
 def TestClusterInfo():
   """gnt-cluster info"""
@@ -171,10 +194,14 @@ def TestClusterRenewCrypto():
 
   # Conflicting options
   cmd = ["gnt-cluster", "renew-crypto", "--force",
-         "--new-cluster-certificate", "--new-confd-hmac-key",
-         "--new-rapi-certificate", "--rapi-certificate=/dev/null"]
-  AssertNotEqual(StartSSH(master["primary"],
-                          utils.ShellQuoteArgs(cmd)).wait(), 0)
+         "--new-cluster-certificate", "--new-confd-hmac-key"]
+  conflicting = [
+    ["--new-rapi-certificate", "--rapi-certificate=/dev/null"],
+    ["--new-cluster-domain-secret", "--cluster-domain-secret=/dev/null"],
+    ]
+  for i in conflicting:
+    AssertNotEqual(StartSSH(master["primary"],
+                            utils.ShellQuoteArgs(cmd + i)).wait(), 0)
 
   # Invalid RAPI certificate
   cmd = ["gnt-cluster", "renew-crypto", "--force",
@@ -191,7 +218,7 @@ def TestClusterRenewCrypto():
     # Ensure certificate doesn't cause "gnt-cluster verify" to complain
     validity = constants.SSL_CERT_EXPIRATION_WARN * 3
 
-    bootstrap.GenerateSelfSignedSslCert(fh.name, validity=validity)
+    utils.GenerateSelfSignedSslCert(fh.name, validity=validity)
 
     tmpcert = qa_utils.UploadFile(master["primary"], fh.name)
     try:
@@ -204,10 +231,27 @@ def TestClusterRenewCrypto():
       AssertEqual(StartSSH(master["primary"],
                            utils.ShellQuoteArgs(cmd)).wait(), 0)
 
+    # Custom cluster domain secret
+    cds_fh = tempfile.NamedTemporaryFile()
+    cds_fh.write(utils.GenerateSecret())
+    cds_fh.write("\n")
+    cds_fh.flush()
+
+    tmpcds = qa_utils.UploadFile(master["primary"], cds_fh.name)
+    try:
+      cmd = ["gnt-cluster", "renew-crypto", "--force",
+             "--cluster-domain-secret=%s" % tmpcds]
+      AssertEqual(StartSSH(master["primary"],
+                           utils.ShellQuoteArgs(cmd)).wait(), 0)
+    finally:
+      cmd = ["rm", "-f", tmpcds]
+      AssertEqual(StartSSH(master["primary"],
+                           utils.ShellQuoteArgs(cmd)).wait(), 0)
+
     # Normal case
     cmd = ["gnt-cluster", "renew-crypto", "--force",
            "--new-cluster-certificate", "--new-confd-hmac-key",
-           "--new-rapi-certificate"]
+           "--new-rapi-certificate", "--new-cluster-domain-secret"]
     AssertEqual(StartSSH(master["primary"],
                          utils.ShellQuoteArgs(cmd)).wait(), 0)
 
@@ -231,6 +275,8 @@ def TestClusterBurnin():
   parallel = options.get('burnin-in-parallel', False)
   check_inst = options.get('burnin-check-instances', False)
   do_rename = options.get('burnin-rename', '')
+  do_reboot = options.get('burnin-reboot', True)
+  reboot_types = options.get("reboot-types", constants.REBOOT_TYPES)
 
   # Get as many instances as we need
   instances = []
@@ -260,6 +306,10 @@ def TestClusterBurnin():
         cmd.append('--http-check')
       if do_rename:
         cmd.append('--rename=%s' % do_rename)
+      if not do_reboot:
+        cmd.append('--no-reboot')
+      else:
+        cmd.append('--reboot-types=%s' % ",".join(reboot_types))
       cmd += [inst['name'] for inst in instances]
       AssertEqual(StartSSH(master['primary'],
                            utils.ShellQuoteArgs(cmd)).wait(), 0)
@@ -273,16 +323,16 @@ def TestClusterBurnin():
 
 
 def TestClusterMasterFailover():
-  """gnt-cluster masterfailover"""
+  """gnt-cluster master-failover"""
   master = qa_config.GetMasterNode()
 
   failovermaster = qa_config.AcquireNode(exclude=master)
   try:
-    cmd = ['gnt-cluster', 'masterfailover']
+    cmd = ['gnt-cluster', 'master-failover']
     AssertEqual(StartSSH(failovermaster['primary'],
                          utils.ShellQuoteArgs(cmd)).wait(), 0)
 
-    cmd = ['gnt-cluster', 'masterfailover']
+    cmd = ['gnt-cluster', 'master-failover']
     AssertEqual(StartSSH(master['primary'],
                          utils.ShellQuoteArgs(cmd)).wait(), 0)
   finally: