baserlib: Accept empty body in FillOpcode
[ganeti-local] / lib / backend.py
index 30fe8ff..84a39d0 100644 (file)
@@ -296,7 +296,7 @@ def StartMaster(start_daemons, no_voting):
       if family == netutils.IP6Address.family:
         ipcls = netutils.IP6Address
 
-      result = utils.RunCmd(["ip", "address", "add",
+      result = utils.RunCmd([constants.IP_COMMAND_PATH, "address", "add",
                              "%s/%d" % (master_ip, ipcls.iplen),
                              "dev", master_netdev, "label",
                              "%s:0" % master_netdev])
@@ -343,7 +343,7 @@ def StopMaster(stop_daemons):
   if family == netutils.IP6Address.family:
     ipcls = netutils.IP6Address
 
-  result = utils.RunCmd(["ip", "address", "del",
+  result = utils.RunCmd([constants.IP_COMMAND_PATH, "address", "del",
                          "%s/%d" % (master_ip, ipcls.iplen),
                          "dev", master_netdev])
   if result.failed:
@@ -730,7 +730,7 @@ def GetVolumeList(vg_names):
       # we don't want to report such volumes as existing, since they
       # don't really hold data
       continue
-    lvs[vg_name+"/"+name] = (size, inactive, online)
+    lvs[vg_name + "/" + name] = (size, inactive, online)
 
   return lvs
 
@@ -925,7 +925,7 @@ def GetAllInstancesInfo(hypervisor_list):
   return output
 
 
-def _InstanceLogName(kind, os_name, instance):
+def _InstanceLogName(kind, os_name, instance, component):
   """Compute the OS log filename for a given instance and operation.
 
   The instance name and os name are passed in as strings since not all
@@ -937,11 +937,19 @@ def _InstanceLogName(kind, os_name, instance):
   @param os_name: the os name
   @type instance: string
   @param instance: the name of the instance being imported/added/etc.
+  @type component: string or None
+  @param component: the name of the component of the instance being
+      transferred
 
   """
   # TODO: Use tempfile.mkstemp to create unique filename
-  base = ("%s-%s-%s-%s.log" %
-          (kind, os_name, instance, utils.TimestampForFilename()))
+  if component:
+    assert "/" not in component
+    c_msg = "-%s" % component
+  else:
+    c_msg = ""
+  base = ("%s-%s-%s%s-%s.log" %
+          (kind, os_name, instance, c_msg, utils.TimestampForFilename()))
   return utils.PathJoin(constants.LOG_OS_DIR, base)
 
 
@@ -963,10 +971,10 @@ def InstanceOsAdd(instance, reinstall, debug):
   if reinstall:
     create_env["INSTANCE_REINSTALL"] = "1"
 
-  logfile = _InstanceLogName("add", instance.os, instance.name)
+  logfile = _InstanceLogName("add", instance.os, instance.name, None)
 
   result = utils.RunCmd([inst_os.create_script], env=create_env,
-                        cwd=inst_os.path, output=logfile,)
+                        cwd=inst_os.path, output=logfile, reset_env=True)
   if result.failed:
     logging.error("os create command '%s' returned error: %s, logfile: %s,"
                   " output: %s", result.cmd, result.fail_reason, logfile,
@@ -996,10 +1004,10 @@ def RunRenameInstance(instance, old_name, debug):
   rename_env["OLD_INSTANCE_NAME"] = old_name
 
   logfile = _InstanceLogName("rename", instance.os,
-                             "%s-%s" % (old_name, instance.name))
+                             "%s-%s" % (old_name, instance.name), None)
 
   result = utils.RunCmd([inst_os.rename_script], env=rename_env,
-                        cwd=inst_os.path, output=logfile)
+                        cwd=inst_os.path, output=logfile, reset_env=True)
 
   if result.failed:
     logging.error("os create command '%s' returned error: %s output: %s",
@@ -2351,7 +2359,7 @@ def FinalizeExport(instance, snap_disks):
       config.set(constants.INISECT_INS, "nic%d_%s" % (nic_count, param),
                  "%s" % nic.nicparams.get(param, None))
   # TODO: redundant: on load can read nics until it doesn't exist
-  config.set(constants.INISECT_INS, "nic_count" , "%d" % nic_total)
+  config.set(constants.INISECT_INS, "nic_count", "%d" % nic_total)
 
   disk_total = 0
   for disk_count, disk in enumerate(snap_disks):
@@ -2364,7 +2372,7 @@ def FinalizeExport(instance, snap_disks):
       config.set(constants.INISECT_INS, "disk%d_size" % disk_count,
                  ("%d" % disk.size))
 
-  config.set(constants.INISECT_INS, "disk_count" , "%d" % disk_total)
+  config.set(constants.INISECT_INS, "disk_count", "%d" % disk_total)
 
   # New-style hypervisor/backend parameters
 
@@ -2752,7 +2760,7 @@ def ValidateOS(required, osname, checks, osparams):
 
   validate_env = OSCoreEnv(osname, tbv, osparams)
   result = utils.RunCmd([tbv.verify_script] + checks, env=validate_env,
-                        cwd=tbv.path)
+                        cwd=tbv.path, reset_env=True)
   if result.failed:
     logging.error("os validate command '%s' returned error: %s output: %s",
                   result.cmd, result.fail_reason, result.output)
@@ -2964,7 +2972,8 @@ def _CreateImportExportStatusDir(prefix):
                                   (prefix, utils.TimestampForFilename())))
 
 
-def StartImportExportDaemon(mode, opts, host, port, instance, ieio, ieioargs):
+def StartImportExportDaemon(mode, opts, host, port, instance, component,
+                            ieio, ieioargs):
   """Starts an import or export daemon.
 
   @param mode: Import/output mode
@@ -2976,6 +2985,9 @@ def StartImportExportDaemon(mode, opts, host, port, instance, ieio, ieioargs):
   @param port: Remote port for export (None for import)
   @type instance: L{objects.Instance}
   @param instance: Instance object
+  @type component: string
+  @param component: which part of the instance is transferred now,
+      e.g. 'disk/0'
   @param ieio: Input/output type
   @param ieioargs: Input/output arguments
 
@@ -3015,7 +3027,7 @@ def StartImportExportDaemon(mode, opts, host, port, instance, ieio, ieioargs):
     if not os.path.exists(i):
       _Fail("File '%s' does not exist" % i)
 
-  status_dir = _CreateImportExportStatusDir(prefix)
+  status_dir = _CreateImportExportStatusDir("%s-%s" % (prefix, component))
   try:
     status_file = utils.PathJoin(status_dir, _IES_STATUS_FILE)
     pid_file = utils.PathJoin(status_dir, _IES_PID_FILE)
@@ -3073,7 +3085,7 @@ def StartImportExportDaemon(mode, opts, host, port, instance, ieio, ieioargs):
       # Overall timeout for establishing connection while listening
       cmd.append("--connect-timeout=%s" % opts.connect_timeout)
 
-    logfile = _InstanceLogName(prefix, instance.os, instance.name)
+    logfile = _InstanceLogName(prefix, instance.os, instance.name, component)
 
     # TODO: Once _InstanceLogName uses tempfile.mkstemp, StartDaemon has
     # support for receiving a file descriptor for output
@@ -3366,7 +3378,6 @@ class HooksRunner(object):
     else:
       _Fail("Unknown hooks phase '%s'", phase)
 
-
     subdir = "%s-%s.d" % (hpath, suffix)
     dir_name = utils.PathJoin(self._BASE_DIR, subdir)