summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorRick Harris <rconradharris@gmail.com>2012-02-21 22:00:03 +0000
committerRick Harris <rconradharris@gmail.com>2012-02-21 22:00:03 +0000
commit043347267bdb2ea49d562d02c03fe8d242b641c9 (patch)
treeec67f87e029557e326e084816fdd62f71406e820 /plugins
parentadaf9049c8fb3652c0962909a3c835e1724d8a17 (diff)
downloadnova-043347267bdb2ea49d562d02c03fe8d242b641c9.tar.gz
nova-043347267bdb2ea49d562d02c03fe8d242b641c9.tar.xz
nova-043347267bdb2ea49d562d02c03fe8d242b641c9.zip
Avoid copying file if dst is a directory.
Fixes bug 938153 `shutil.move` in Python 2.4 will fallback to copying the file if dst is a directory. See http://bugs.python.org/issue1577. Change-Id: I2390337d82db5a72fef0e63877401134b1dcca55
Diffstat (limited to 'plugins')
-rwxr-xr-xplugins/xenserver/xenapi/etc/xapi.d/plugins/migration25
1 files changed, 14 insertions, 11 deletions
diff --git a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration
index adcfc2608..f86855260 100755
--- a/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration
+++ b/plugins/xenserver/xenapi/etc/xapi.d/plugins/migration
@@ -23,7 +23,6 @@ import os
import os.path
import pickle
import shlex
-import shutil
import subprocess
import XenAPIPlugin
@@ -32,6 +31,12 @@ from pluginlib_nova import *
configure_logging('migration')
+def move_file(item, src, dst):
+ """Move file with logging."""
+ logging.debug('Moving %(item)s: %(src)s -> %(dst)s' % locals())
+ os.rename(src, dst)
+
+
def move_vhds_into_sr(session, args):
"""Moves the VHDs from their copied location to the SR"""
params = pickle.loads(exists(args, 'params'))
@@ -54,9 +59,7 @@ def move_vhds_into_sr(session, args):
old_base_copy_uuid)
new_base_copy_path = "%s/%s.vhd" % (temp_vhd_path, new_base_copy_uuid)
- logging.debug('Moving base %s into %s' % (source_base_copy_path,
- temp_vhd_path))
- shutil.move(source_base_copy_path, new_base_copy_path)
+ move_file('base', source_base_copy_path, new_base_copy_path)
if 'old_cow_uuid' in params:
old_cow_uuid = params['old_cow_uuid']
@@ -65,9 +68,7 @@ def move_vhds_into_sr(session, args):
source_cow_path = "%s/%s.vhd" % (source_image_path, old_cow_uuid)
new_cow_path = "%s/%s.vhd" % (temp_vhd_path, new_cow_uuid)
- logging.debug('Moving COW %s into %s' % (source_cow_path,
- temp_vhd_path))
- shutil.move(source_cow_path, new_cow_path)
+ move_file('COW', source_cow_path, new_cow_path)
# Link the COW to the base copy
logging.debug('Attaching COW to the base %s -> %s' %
@@ -77,11 +78,13 @@ def move_vhds_into_sr(session, args):
# NOTE(sirp): COW should be copied before base_copy to avoid
# snapwatchd GC'ing an unreferenced base copy VDI
- logging.debug('Moving COW %s to %s' % (new_cow_path, sr_path))
- shutil.move(new_cow_path, sr_path)
+ new_cow_sr_path = os.path.join(
+ sr_path, os.path.basename(new_cow_path))
+ move_file('COW', new_cow_path, new_cow_sr_path)
- logging.debug('Moving base %s to %s' % (new_base_copy_path, sr_path))
- shutil.move(new_base_copy_path, sr_path)
+ new_base_copy_sr_path = os.path.join(
+ sr_path, os.path.basename(new_base_copy_path))
+ move_file('base', new_base_copy_path, new_base_copy_sr_path)
logging.debug('Cleaning up source path %s' % source_image_path)
os.rmdir(source_image_path)