--- smoser.py 2016-11-18 00:32:29.612881999 +0000
+++ new.py 2016-11-18 00:32:50.352943362 +0000
@@ -1,16 +1,21 @@
def can_dev_be_reformatted(devpath):
# determine if the ephemeral block device path devpath
# is newly formatted after a resize.
- if not os.path.isfile(devpath):
- return False, 'device %s is not a file' % devpath
+ if os.path.islink(devpath):
+ realpath = os.path.realpath(devpath)
+ LOG.debug('Resolving realpath of %s -> %s', devpath, realpath)
+ devpath = realpath
+
+ if not os.path.exists(devpath):
+ return False, 'device %s does not exist' % devpath
# devpath of /dev/sd[a-z] or /dev/disk/cloud/azure_resource
# where partitions are "<devpath>1" or "<devpath>-part1" or "<devpath>p1"
partpath = None
for suff in ("-part", "p", ""):
cand = devpath + suff + "1"
- if os.path.isfile(cand):
- if os.path.isfile(devpath + suff + "2"):
+ if os.path.exists(cand):
+ if os.path.exists(devpath + suff + "2"):
msg = ('device %s had more than 1 partition: %s, %s' %
devpath, cand, devpath + suff + "2")
return False, msg
@@ -21,7 +26,8 @@
return False, 'device %s was not partitioned' % devpath
real_partpath = os.path.realpath(partpath)
- ntfs_devices = util.find_devs_with("TYPE=ntfs")
+ ntfs_devices = util.find_devs_with("TYPE=ntfs", no_cache=True)
+ LOG.debug('ntfs_devices found = %s', ntfs_devices)
if real_partpath not in ntfs_devices:
msg = ('partition 1 (%s -> %s) on device %s was not ntfs formatted' %
partpath, real_partpath, devpath)
@@ -31,24 +37,25 @@
ignored = {'dataloss_warning_readme.txt'}
return len([f for f in os.listdir(mp) if f.lower() not in ignored])
- bmsg = ('partition 1 (%s -> %s) on device %s was ntfs formatted' %
- partpath, real_partpath, devpath)
+ bmsg = ('partition 1 (%s -> %s) on device %s was ntfs formatted' % (
+ partpath, real_partpath, devpath))
try:
- file_count = util.mount_cb(devpath, count_files)
+ file_count = util.mount_cb(real_partpath, count_files)
except util.MountFailedError as e:
- return False, bmsg + ' but mount failed: %s' % e
+ return False, bmsg + ' but mount of %s failed: %s' % (real_partpath, e)
if file_count != 0:
return False, bmsg + ' but had %d files on it.' % file_count
- return True, bmsg + ' and had important files.'
+ return True, bmsg + ' and had no important files. Safe for reformatting.'
def address_ephemeral_resize(devpath=RESOURCE_DISK_PATH, maxwait=120,
is_new_instance=False):
# wait for ephemeral disk to come up
naplen = .2
- missing = wait_for_files([devpath], maxwait=maxwait, naplen=naplen)
+ missing = wait_for_files([devpath], maxwait=maxwait, naplen=naplen,
+ log_pre="Azure ephemeral disk: ")
if missing:
LOG.warn("ephemeral device '%s' did not appear after %d seconds.",
@@ -66,7 +73,7 @@
if not result:
return
- for mod in ['disk_config', 'config_mounts']:
+ for mod in ['disk_setup', 'config_mounts']:
sempath = '/var/lib/cloud/instance/sem/config_' + mod
bmsg = 'Marker "%s" for module "%s"' % (sempath, mod)
if os.path.exists(sempath):