~harlowja/cloud-init/migrator-module

« back to all changes in this revision

Viewing changes to cloudinit/config/cc_migrator.py

  • Committer: harlowja
  • Date: 2012-11-08 07:16:21 UTC
  • Revision ID: harlowja@virtualbox.rhel-20121108071621-pn9n5hkxmk1olze4
1. Check the name and not the full path
   when applying the canon routine.
2. Add in a function to migrate legacy
   semaphores to new semaphores.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
    for p in os.listdir(sem_path):
36
36
        full_path = os.path.join(sem_path, p)
37
37
        if os.path.isfile(full_path):
38
 
            canon_p = helpers.canon_sem_name(p)
39
 
            if canon_p != p:
40
 
                new_path = os.path.join(sem_path, p)
 
38
            (name, ext) = os.path.splitext(p)
 
39
            canon_name = helpers.canon_sem_name(name)
 
40
            if canon_name != name:
 
41
                new_path = os.path.join(sem_path, canon_name + ext)
41
42
                shutil.move(full_path, new_path)
42
43
                am_adjusted += 1
43
44
    return am_adjusted
44
45
 
45
46
 
 
47
def _migrate_legacy_sems(cloud, log):
 
48
    sem_path = cloud.paths.get_ipath('sem')
 
49
    touch_there = {
 
50
        'apt-update-upgrade': [
 
51
            'apt-configure',
 
52
            'package-update-upgrade-install',
 
53
        ],
 
54
    }
 
55
    sem_helper = helpers.FileSemaphores(sem_path)
 
56
    for (mod_name, migrate_to) in touch_there.items():
 
57
        possibles = [mod_name, helpers.canon_sem_name(mod_name)]
 
58
        old_exists = []
 
59
        for p in os.listdir(sem_path):
 
60
            (name, _ext) = os.path.splitext(p)
 
61
            if name in possibles and os.path.isfile(p):
 
62
                old_exists.append(p)
 
63
        for p in old_exists:
 
64
            util.del_file(os.path.join(sem_path, p))
 
65
            (_name, freq) = os.path.splitext(p)
 
66
            for m in migrate_to:
 
67
                log.debug("Migrating %s => %s with the same frequency",
 
68
                          p, m)
 
69
                with sem_helper.lock(m, freq):
 
70
                    pass
 
71
 
 
72
 
46
73
def handle(name, cfg, cloud, log, _args):
47
74
    do_migrate = util.get_cfg_option_str(cfg, "migrate", True)
48
75
    if not util.translate_bool(do_migrate):
51
78
    sems_moved = _migrate_canon_sems(cloud)
52
79
    log.debug("Migrated %s semaphore files to there canonicalized names",
53
80
              sems_moved)
 
81
    _migrate_legacy_sems(cloud, log)