make migrator walk the "cloud" path also

the migrator was not renaming items in the "cloud" semaphore path.
Those were items that would run once only.

Now we just check both ipath('sem') and cpath('sem')
This commit is contained in:
Scott Moser 2012-11-13 15:25:57 -05:00
parent 10299836d1
commit 01be0255f3

View File

@ -28,48 +28,50 @@ frequency = PER_ALWAYS
def _migrate_canon_sems(cloud): def _migrate_canon_sems(cloud):
sem_path = cloud.paths.get_ipath('sem') paths = (cloud.paths.get_ipath('sem'), cloud.paths.get_cpath('sem'))
if not sem_path or not os.path.exists(sem_path):
return 0
am_adjusted = 0 am_adjusted = 0
for p in os.listdir(sem_path): for sem_path in paths:
full_path = os.path.join(sem_path, p) if not sem_path or not os.path.exists(sem_path):
if os.path.isfile(full_path): continue
(name, ext) = os.path.splitext(p) for p in os.listdir(sem_path):
canon_name = helpers.canon_sem_name(name) full_path = os.path.join(sem_path, p)
if canon_name != name: if os.path.isfile(full_path):
new_path = os.path.join(sem_path, canon_name + ext) (name, ext) = os.path.splitext(p)
shutil.move(full_path, new_path) canon_name = helpers.canon_sem_name(name)
am_adjusted += 1 if canon_name != name:
new_path = os.path.join(sem_path, canon_name + ext)
shutil.move(full_path, new_path)
am_adjusted += 1
return am_adjusted return am_adjusted
def _migrate_legacy_sems(cloud, log): def _migrate_legacy_sems(cloud, log):
sem_path = cloud.paths.get_ipath('sem')
if not sem_path or not os.path.exists(sem_path):
return
legacy_adjust = { legacy_adjust = {
'apt-update-upgrade': [ 'apt-update-upgrade': [
'apt-configure', 'apt-configure',
'package-update-upgrade-install', 'package-update-upgrade-install',
], ],
} }
sem_helper = helpers.FileSemaphores(sem_path) paths = (cloud.paths.get_ipath('sem'), cloud.paths.get_cpath('sem'))
for (mod_name, migrate_to) in legacy_adjust.items(): for sem_path in paths:
possibles = [mod_name, helpers.canon_sem_name(mod_name)] if not sem_path or not os.path.exists(sem_path):
old_exists = [] continue
for p in os.listdir(sem_path): sem_helper = helpers.FileSemaphores(sem_path)
(name, _ext) = os.path.splitext(p) for (mod_name, migrate_to) in legacy_adjust.items():
if name in possibles and os.path.isfile(p): possibles = [mod_name, helpers.canon_sem_name(mod_name)]
old_exists.append(p) old_exists = []
for p in old_exists: for p in os.listdir(sem_path):
util.del_file(os.path.join(sem_path, p)) (name, _ext) = os.path.splitext(p)
(_name, freq) = os.path.splitext(p) if name in possibles and os.path.isfile(p):
for m in migrate_to: old_exists.append(p)
log.debug("Migrating %s => %s with the same frequency", for p in old_exists:
p, m) util.del_file(os.path.join(sem_path, p))
with sem_helper.lock(m, freq): (_name, freq) = os.path.splitext(p)
pass for m in migrate_to:
log.debug("Migrating %s => %s with the same frequency",
p, m)
with sem_helper.lock(m, freq):
pass
def handle(name, cfg, cloud, log, _args): def handle(name, cfg, cloud, log, _args):