diff options
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/config/cc_migrator.py | 64 | ||||
-rw-r--r-- | cloudinit/helpers.py | 15 |
2 files changed, 46 insertions, 33 deletions
diff --git a/cloudinit/config/cc_migrator.py b/cloudinit/config/cc_migrator.py index 58232fc9..facaa538 100644 --- a/cloudinit/config/cc_migrator.py +++ b/cloudinit/config/cc_migrator.py @@ -28,48 +28,50 @@ frequency = PER_ALWAYS def _migrate_canon_sems(cloud): - sem_path = cloud.paths.get_ipath('sem') - if not sem_path or not os.path.exists(sem_path): - return 0 + paths = (cloud.paths.get_ipath('sem'), cloud.paths.get_cpath('sem')) am_adjusted = 0 - for p in os.listdir(sem_path): - full_path = os.path.join(sem_path, p) - if os.path.isfile(full_path): - (name, ext) = os.path.splitext(p) - canon_name = helpers.canon_sem_name(name) - if canon_name != name: - new_path = os.path.join(sem_path, canon_name + ext) - shutil.move(full_path, new_path) - am_adjusted += 1 + for sem_path in paths: + if not sem_path or not os.path.exists(sem_path): + continue + for p in os.listdir(sem_path): + full_path = os.path.join(sem_path, p) + if os.path.isfile(full_path): + (name, ext) = os.path.splitext(p) + canon_name = helpers.canon_sem_name(name) + 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 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 = { 'apt-update-upgrade': [ 'apt-configure', 'package-update-upgrade-install', ], } - sem_helper = helpers.FileSemaphores(sem_path) - for (mod_name, migrate_to) in legacy_adjust.items(): - possibles = [mod_name, helpers.canon_sem_name(mod_name)] - old_exists = [] - for p in os.listdir(sem_path): - (name, _ext) = os.path.splitext(p) - if name in possibles and os.path.isfile(p): - old_exists.append(p) - for p in old_exists: - util.del_file(os.path.join(sem_path, p)) - (_name, freq) = os.path.splitext(p) - for m in migrate_to: - log.debug("Migrating %s => %s with the same frequency", - p, m) - with sem_helper.lock(m, freq): - pass + paths = (cloud.paths.get_ipath('sem'), cloud.paths.get_cpath('sem')) + for sem_path in paths: + if not sem_path or not os.path.exists(sem_path): + continue + sem_helper = helpers.FileSemaphores(sem_path) + for (mod_name, migrate_to) in legacy_adjust.items(): + possibles = [mod_name, helpers.canon_sem_name(mod_name)] + old_exists = [] + for p in os.listdir(sem_path): + (name, _ext) = os.path.splitext(p) + if name in possibles and os.path.isfile(p): + old_exists.append(p) + for p in old_exists: + util.del_file(os.path.join(sem_path, p)) + (_name, freq) = os.path.splitext(p) + 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): diff --git a/cloudinit/helpers.py b/cloudinit/helpers.py index 794f00ec..2077401c 100644 --- a/cloudinit/helpers.py +++ b/cloudinit/helpers.py @@ -125,12 +125,23 @@ class FileSemaphores(object): def has_run(self, name, freq): if not freq or freq == PER_ALWAYS: return False - name = canon_sem_name(name) - sem_file = self._get_path(name, freq) + + cname = canon_sem_name(name) + sem_file = self._get_path(cname, freq) # This isn't really a good atomic check # but it suffices for where and when cloudinit runs if os.path.exists(sem_file): return True + + # this case could happen if the migrator module hadn't run yet + # but the item had run before we did canon_sem_name. + if cname != name and os.path.exists(self._get_path(name, freq)): + LOG.warn("%s has run without canonicalized name [%s].\n" + "likely the migrator has not yet run. It will run next boot.\n" + "run manually with: cloud-init single --name=migrator" + % (name, cname)) + return True + return False def _get_path(self, name, freq): |