Commit 726d7d68 authored by Iustin Pop's avatar Iustin Pop
Browse files

Fix gnt-backup export

This patch fixes a bug in disk calculation for gnt-backup export, which
completely broke one-disk instance export.

The patch also corrects some error messages and style issues.

Reviewed-by: ultrotter
parent 268b8e42
......@@ -1606,24 +1606,21 @@ def FinalizeExport(instance, snap_disks):
# TODO: redundant: on load can read nics until it doesn't exist
config.set(constants.INISECT_INS, 'nic_count' , '%d' % nic_count)
disk_count = 0
disk_total = 0
for disk_count, disk in enumerate(snap_disks):
if disk:
disk_total += 1
config.set(constants.INISECT_INS, 'disk%d_ivname' % disk_count,
('%s' % disk.iv_name))
config.set(constants.INISECT_INS, 'disk%d_dump' % disk_count,
('%s' % disk.physical_id[1]))
config.set(constants.INISECT_INS, 'disk%d_size' % disk_count,
('%d' % disk.size))
config.set(constants.INISECT_INS, 'disk_count' , '%d' % disk_count)
cff = os.path.join(destdir, constants.EXPORT_CONF_FILE)
cfo = open(cff, 'w')
try:
config.write(cfo)
finally:
cfo.close()
config.set(constants.INISECT_INS, 'disk_count' , '%d' % disk_total)
utils.WriteFile(os.path.join(destdir, constants.EXPORT_CONF_FILE),
data=config.Dumps())
shutil.rmtree(finaldestdir, True)
shutil.move(destdir, finaldestdir)
......@@ -1691,8 +1688,9 @@ def ImportOSIntoInstance(instance, src_node, src_images, cluster_name):
import_env['IMPORT_INDEX'] = str(idx)
result = utils.RunCmd(command, env=import_env)
if result.failed:
logging.error("disk import command '%s' returned error: %s"
" output: %s", command, result.fail_reason, result.output)
logging.error("Disk import command '%s' returned error: %s"
" output: %s", command, result.fail_reason,
result.output)
final_result.append(False)
else:
final_result.append(True)
......
......@@ -3606,7 +3606,7 @@ class LUCreateInstance(LogicalUnit):
if instance_disks < export_disks:
raise errors.OpPrereqError("Not enough disks to import."
" (instance: %d, export: %d)" %
(2, export_disks))
(instance_disks, export_disks))
self.op.os_type = export_info.get(constants.INISECT_EXP, 'os')
disk_images = []
......@@ -3824,9 +3824,9 @@ class LUCreateInstance(LogicalUnit):
cluster_name)
for idx, result in enumerate(import_result):
if not result:
self.LogWarning("Could not image %s for on instance %s, disk %d,"
" on node %s" % (src_images[idx], instance, idx,
pnode_name))
self.LogWarning("Could not import the image %s for instance"
" %s, disk %d, on node %s" %
(src_images[idx], instance, idx, pnode_name))
else:
# also checked in the prereq part
raise errors.ProgrammerError("Unknown OS initialization mode '%s'"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment