Merge lp:~hazmat/pyjuju/var-run-mass-restart into lp:pyjuju

Proposed by Kapil Thangavelu
Status: Merged
Merged at revision: 621
Proposed branch: lp:~hazmat/pyjuju/var-run-mass-restart
Merge into: lp:pyjuju
Diff against target: 19 lines (+7/-1)
1 file modified
juju/agents/base.py (+7/-1)
To merge this branch: bzr merge lp:~hazmat/pyjuju/var-run-mass-restart
Reviewer Review Type Date Requested Status
Juju Engineering Pending
Review via email: mp+158980@code.launchpad.net

Description of the change

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://codereview.appspot.com/8583048/

To post a comment you must log in.
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)

Revision history for this message
Benjamin Saller (bcsaller) wrote :

LGTM w/trivial

https://codereview.appspot.com/8583048/diff/1/juju/agents/base.py
File juju/agents/base.py (right):

https://codereview.appspot.com/8583048/diff/1/juju/agents/base.py#newcode41
juju/agents/base.py:41: if e.errno != 17:
Could you use errno.EEXIST here rather than the magic number?

https://codereview.appspot.com/8583048/

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

done thanks.

On Mon, Apr 15, 2013 at 10:55 AM, Benjamin Saller <
<email address hidden>> wrote:

> LGTM w/trivial
>
>
> https://codereview.appspot.com/8583048/diff/1/juju/agents/base.py
> File juju/agents/base.py (right):
>
> https://codereview.appspot.com/8583048/diff/1/juju/agents/base.py#newcode41
> juju/agents/base.py:41: if e.errno != 17:
> Could you use errno.EEXIST here rather than the magic number?
>
> https://codereview.appspot.com/8583048/
>
> --
> https://code.launchpad.net/~hazmat/juju/var-run-mass-restart/+merge/158980
> You are the owner of lp:~hazmat/juju/var-run-mass-restart.
>

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

*** Submitted:

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.

R=bcsaller
CC=
https://codereview.appspot.com/8583048

https://codereview.appspot.com/8583048/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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:23:28 +0000
@@ -32,8 +32,14 @@
3232
33def save_client_id(path, client_id):33def save_client_id(path, client_id):
34 parent = os.path.dirname(path)34 parent = os.path.dirname(path)
35 if not os.path.exists(parent):35 # On reboot the run dir is wiped, with multiple agents
36 # we get a race trying to create the directory, hence try/except
37 # instead of checking to see if dir exists first.
38 try:
36 os.makedirs(parent)39 os.makedirs(parent)
40 except OSError, e:
41 if e.errno != 17:
42 raise
37 with open(path, "w") as f:43 with open(path, "w") as f:
38 f.write(yaml.dump(client_id))44 f.write(yaml.dump(client_id))
39 os.chmod(path, stat.S_IRUSR | stat.S_IWUSR)45 os.chmod(path, stat.S_IRUSR | stat.S_IWUSR)

Subscribers

People subscribed via source and target branches

to status/vote changes: