Revert "jqueue: Resume jobs from “waitlock” status"
[ganeti-local] / lib / backend.py
index 15ac873..5b2bebd 100644 (file)
@@ -58,6 +58,7 @@ from ganeti import bdev
 from ganeti import objects
 from ganeti import ssconf
 from ganeti import serializer
+from ganeti import netutils
 
 
 _BOOT_ID_PATH = "/proc/sys/kernel/random/boot_id"
@@ -241,13 +242,14 @@ def GetMasterInfo():
 def StartMaster(start_daemons, no_voting):
   """Activate local node as master node.
 
-  The function will always try activate the IP address of the master
-  (unless someone else has it). It will also start the master daemons,
-  based on the start_daemons parameter.
+  The function will either try activate the IP address of the master
+  (unless someone else has it) or also start the master daemons, based
+  on the start_daemons parameter.
 
   @type start_daemons: boolean
-  @param start_daemons: whether to also start the master
-      daemons (ganeti-masterd and ganeti-rapi)
+  @param start_daemons: whether to start the master daemons
+      (ganeti-masterd and ganeti-rapi), or (if false) activate the
+      master ip
   @type no_voting: boolean
   @param no_voting: whether to start ganeti-masterd without a node vote
       (if start_daemons is True), but still non-interactively
@@ -258,28 +260,7 @@ def StartMaster(start_daemons, no_voting):
   master_netdev, master_ip, _ = GetMasterInfo()
 
   err_msgs = []
-  if utils.TcpPing(master_ip, constants.DEFAULT_NODED_PORT):
-    if utils.OwnIpAddress(master_ip):
-      # we already have the ip:
-      logging.debug("Master IP already configured, doing nothing")
-    else:
-      msg = "Someone else has the master ip, not activating"
-      logging.error(msg)
-      err_msgs.append(msg)
-  else:
-    result = utils.RunCmd(["ip", "address", "add", "%s/32" % master_ip,
-                           "dev", master_netdev, "label",
-                           "%s:0" % master_netdev])
-    if result.failed:
-      msg = "Can't activate master IP: %s" % result.output
-      logging.error(msg)
-      err_msgs.append(msg)
-
-    result = utils.RunCmd(["arping", "-q", "-U", "-c 3", "-I", master_netdev,
-                           "-s", master_ip, master_ip])
-    # we'll ignore the exit code of arping
-
-  # and now start the master and rapi daemons
+  # either start the master and rapi daemons
   if start_daemons:
     if no_voting:
       masterd_args = "--no-voting --yes-do-it"
@@ -295,6 +276,28 @@ def StartMaster(start_daemons, no_voting):
       msg = "Can't start Ganeti master: %s" % result.output
       logging.error(msg)
       err_msgs.append(msg)
+  # or activate the IP
+  else:
+    if netutils.TcpPing(master_ip, constants.DEFAULT_NODED_PORT):
+      if netutils.OwnIpAddress(master_ip):
+        # we already have the ip:
+        logging.debug("Master IP already configured, doing nothing")
+      else:
+        msg = "Someone else has the master ip, not activating"
+        logging.error(msg)
+        err_msgs.append(msg)
+    else:
+      result = utils.RunCmd(["ip", "address", "add", "%s/32" % master_ip,
+                             "dev", master_netdev, "label",
+                             "%s:0" % master_netdev])
+      if result.failed:
+        msg = "Can't activate master IP: %s" % result.output
+        logging.error(msg)
+        err_msgs.append(msg)
+
+      result = utils.RunCmd(["arping", "-q", "-U", "-c 3", "-I", master_netdev,
+                             "-s", master_ip, master_ip])
+      # we'll ignore the exit code of arping
 
   if err_msgs:
     _Fail("; ".join(err_msgs))
@@ -487,8 +490,8 @@ def VerifyNode(what, cluster_name):
 
   """
   result = {}
-  my_name = utils.HostInfo().name
-  port = utils.GetDaemonPort(constants.NODED)
+  my_name = netutils.HostInfo().name
+  port = netutils.GetDaemonPort(constants.NODED)
 
   if constants.NV_HYPERVISOR in what:
     result[constants.NV_HYPERVISOR] = tmp = {}
@@ -525,10 +528,10 @@ def VerifyNode(what, cluster_name):
     else:
       for name, pip, sip in what[constants.NV_NODENETTEST]:
         fail = []
-        if not utils.TcpPing(pip, port, source=my_pip):
+        if not netutils.TcpPing(pip, port, source=my_pip):
           fail.append("primary")
         if sip != pip:
-          if not utils.TcpPing(sip, port, source=my_sip):
+          if not netutils.TcpPing(sip, port, source=my_sip):
             fail.append("secondary")
         if fail:
           tmp[name] = ("failure using the %s interface(s)" %
@@ -539,10 +542,10 @@ def VerifyNode(what, cluster_name):
     # rest of the function)
     master_name, master_ip = what[constants.NV_MASTERIP]
     if master_name == my_name:
-      source = constants.LOCALHOST_IP_ADDRESS
+      source = constants.IP4_ADDRESS_LOCALHOST
     else:
       source = None
-    result[constants.NV_MASTERIP] = utils.TcpPing(master_ip, port,
+    result[constants.NV_MASTERIP] = netutils.TcpPing(master_ip, port,
                                                   source=source)
 
   if constants.NV_LVLIST in what:
@@ -584,6 +587,16 @@ def VerifyNode(what, cluster_name):
       used_minors = str(err)
     result[constants.NV_DRBDLIST] = used_minors
 
+  if constants.NV_DRBDHELPER in what:
+    status = True
+    try:
+      payload = bdev.BaseDRBD.GetUsermodeHelper()
+    except errors.BlockDeviceError, err:
+      logging.error("Can't get DRBD usermode helper: %s", str(err))
+      status = False
+      payload = str(err)
+    result[constants.NV_DRBDHELPER] = (status, payload)
+
   if constants.NV_NODESETUP in what:
     result[constants.NV_NODESETUP] = tmpr = []
     if not os.path.isdir("/sys/block") or not os.path.isdir("/sys/class/net"):
@@ -792,7 +805,8 @@ def GetInstanceMigratable(instance):
   for idx in range(len(instance.disks)):
     link_name = _GetBlockDevSymlinkPath(iname, idx)
     if not os.path.islink(link_name):
-      _Fail("Instance %s was not restarted since ganeti 1.2.5", iname)
+      logging.warning("Instance %s is missing symlink %s for disk %d",
+                      iname, link_name, idx)
 
 
 def GetAllInstancesInfo(hypervisor_list):
@@ -1903,7 +1917,8 @@ def _TryOSFromDisk(name, base_dir=None):
                       export_script=os_files[constants.OS_SCRIPT_EXPORT],
                       import_script=os_files[constants.OS_SCRIPT_IMPORT],
                       rename_script=os_files[constants.OS_SCRIPT_RENAME],
-                      verify_script=os_files[constants.OS_SCRIPT_VERIFY],
+                      verify_script=os_files.get(constants.OS_SCRIPT_VERIFY,
+                                                 None),
                       supported_variants=variants,
                       supported_parameters=parameters,
                       api_versions=api_versions)
@@ -2520,6 +2535,9 @@ def ValidateOS(required, osname, checks, osparams):
     else:
       return False
 
+  if max(tbv.api_versions) < constants.OS_API_V20:
+    return True
+
   if constants.OS_VALIDATE_PARAMETERS in checks:
     _CheckOSPList(tbv, osparams.keys())
 
@@ -2577,7 +2595,7 @@ def CreateX509Certificate(validity, cryptodir=constants.CRYPTO_KEYS_DIR):
 
   """
   (key_pem, cert_pem) = \
-    utils.GenerateSelfSignedX509Cert(utils.HostInfo.SysName(),
+    utils.GenerateSelfSignedX509Cert(netutils.HostInfo.SysName(),
                                      min(validity, _MAX_SSL_CERT_VALIDITY))
 
   cert_dir = tempfile.mkdtemp(dir=cryptodir,
@@ -2920,7 +2938,7 @@ def _FindDisks(nodes_ip, disks):
 
   """
   # set the correct physical ID
-  my_name = utils.HostInfo().name
+  my_name = netutils.HostInfo().name
   for cf in disks:
     cf.SetPhysicalID(my_name, nodes_ip)
 
@@ -3041,6 +3059,16 @@ def DrbdWaitSync(nodes_ip, disks):
   return (alldone, min_resync)
 
 
+def GetDrbdUsermodeHelper():
+  """Returns DRBD usermode helper currently configured.
+
+  """
+  try:
+    return bdev.BaseDRBD.GetUsermodeHelper()
+  except errors.BlockDeviceError, err:
+    _Fail(str(err))
+
+
 def PowercycleNode(hypervisor_type):
   """Hard-powercycle the node.