Merge lp:~smoser/cloud-init/filesem-check-canon into lp:~cloud-init-dev/cloud-init/trunk

Proposed by Scott Moser
Status: Rejected
Rejected by: Scott Moser
Proposed branch: lp:~smoser/cloud-init/filesem-check-canon
Merge into: lp:~cloud-init-dev/cloud-init/trunk
Diff against target: 39 lines (+12/-4)
1 file modified
cloudinit/helpers.py (+12/-4)
To merge this branch: bzr merge lp:~smoser/cloud-init/filesem-check-canon
Reviewer Review Type Date Requested Status
cloud-init Commiters Pending
Review via email: mp+133294@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Joshua Harlow (harlowja) wrote :

+1 Seems good, maybe in a future version we can move the non-canon 'files' to there rightful 'canon' name if we encounter them, thus avoiding repeated checks in the future.

Revision history for this message
Joshua Harlow (harlowja) wrote :

After our discussion:

https://code.launchpad.net/~harlowja/cloud-init/migrator-module/+merge/133409

Maybe we want to go forward with that instead?

Revision history for this message
Scott Moser (smoser) wrote :

This was marked 'rejected' as we used the migrator module instead.

Unmerged revisions

701. By Scott Moser

check for canonicalized name in file semaphore checking

This works towards a fix for 1075980 by at least looking for filename
markers for a "name" with or without '-' replaced with '_'.

Ie, if 'name' is "foo-bar", this will check for both existance of
a file marker 'foo-bar' and 'foo_bar'.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cloudinit/helpers.py'
2--- cloudinit/helpers.py 2012-10-28 02:25:48 +0000
3+++ cloudinit/helpers.py 2012-11-07 16:56:21 +0000
4@@ -107,7 +107,7 @@
5 # This is a race condition since nothing atomic is happening
6 # here, but this should be ok due to the nature of when
7 # and where cloud-init runs... (file writing is not a lock...)
8- sem_file = self._get_path(name, freq)
9+ sem_file = self._get_path(_canon_sem_name(name), freq)
10 contents = "%s: %s\n" % (os.getpid(), time())
11 try:
12 util.write_file(sem_file, contents)
13@@ -119,11 +119,15 @@
14 def has_run(self, name, freq):
15 if not freq or freq == PER_ALWAYS:
16 return False
17- sem_file = self._get_path(name, freq)
18+
19+ # check for both the name, and canonicalized name
20+ cand_list = set([self._get_path(n, freq)
21+ for n in [name, _canon_sem_name(name)]])
22 # This isn't really a good atomic check
23 # but it suffices for where and when cloudinit runs
24- if os.path.exists(sem_file):
25- return True
26+ for cand in cand_list:
27+ if os.path.exists(cand):
28+ return True
29 return False
30
31 def _get_path(self, name, freq):
32@@ -426,3 +430,7 @@
33 if header:
34 contents = "\n".join([header, contents])
35 return contents
36+
37+
38+def _canon_sem_name(name):
39+ return(name.replace("-", "_"))