Code review comment for lp:~hazmat/pyjuju/var-run-mass-restart

Revision history for this message
Kapil Thangavelu (hazmat) wrote :

Reviewers: mp+158980_code.launchpad.net,

Message:
Please take a look.

Description:
Agents play nice on run dir race.

Previously a reboot of several agents could cause a race around
the creation of the /var/run/juju dir, even with an existence check,
instead just try/except and handle win or lose the race.

https://code.launchpad.net/~hazmat/juju/var-run-mass-restart/+merge/158980

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/8583048/

Affected files:
   A [revision details]
   M juju/agents/base.py

Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>

Index: juju/agents/base.py
=== modified file 'juju/agents/base.py'
--- juju/agents/base.py 2013-02-01 16:53:27 +0000
+++ juju/agents/base.py 2013-04-15 17:20:47 +0000
@@ -32,8 +32,14 @@

  def save_client_id(path, client_id):
      parent = os.path.dirname(path)
- if not os.path.exists(parent):
+ # On reboot the run dir is wiped, with multiple agents
+ # we get a race trying to create the directory, hence try/except
+ # instead of checking to see if dir exists first.
+ try:
          os.makedirs(parent)
+ except OSError, e:
+ if e.errno != 17:
+ raise
      with open(path, "w") as f:
          f.write(yaml.dump(client_id))
      os.chmod(path, stat.S_IRUSR | stat.S_IWUSR)

« Back to merge proposal