Merge lp://qastaging/~bac/juju-quickstart/ssh-agent into lp://qastaging/juju-quickstart

Proposed by Brad Crittenden
Status: Merged
Approved by: Brad Crittenden
Approved revision: 54
Merged at revision: 53
Proposed branch: lp://qastaging/~bac/juju-quickstart/ssh-agent
Merge into: lp://qastaging/juju-quickstart
Diff against target: 220 lines (+64/-30)
3 files modified
Makefile (+4/-0)
quickstart/app.py (+7/-0)
quickstart/tests/test_app.py (+53/-30)
To merge this branch: bzr merge lp://qastaging/~bac/juju-quickstart/ssh-agent
Reviewer Review Type Date Requested Status
Madison Scott-Clary (community) Approve
Review via email: mp+204348@code.qastaging.launchpad.net

Description of the change

Don't start a new ssh-agent unless needed.

If quickstart creates its own ssh-agent it renders a previously running one
unusable. Keys that were already added must be added again. And, when the
quikstart process dies, the environment variables it had set up as required by
ssh-agent are not available to the parent shell, so that agent effectively
becomes a zombie.

Instead, check for the existence of a running agent before spinning up a new
one. If none exists, then launch a new one and then check again to ensure it
is running.

https://codereview.appspot.com/53740045/

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :
Download full text (8.1 KiB)

Reviewers: mp+204348_code.launchpad.net,

Message:
Please take a look.

Description:
Don't start a new ssh-agent unless needed.

If quickstart creates its own ssh-agent it renders a previously running
one
unusable. Keys that were already added must be added again. And, when
the
quikstart process dies, the environment variables it had set up as
required by
ssh-agent are not available to the parent shell, so that agent
effectively
becomes a zombie.

Instead, check for the existence of a running agent before spinning up a
new
one. If none exists, then launch a new one and then check again to
ensure it
is running.

https://code.launchpad.net/~bac/juju-quickstart/ssh-agent/+merge/204348

(do not edit description out of merge proposal)

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

Affected files (+46, -15 lines):
   M Makefile
   A [revision details]
   M quickstart/app.py
   M quickstart/tests/test_app.py

Index: Makefile
=== modified file 'Makefile'
--- Makefile 2014-01-31 18:09:48 +0000
+++ Makefile 2014-01-31 21:00:06 +0000
@@ -54,6 +54,7 @@
   @echo ' environment will be used. It is possible to override the default'
   @echo ' Juju environment by setting the JUJU_ENV environment variable,'
   @echo ' e.g.: "make run JUJU_ENV=ec2".'
+ @echo 'make debug - Same as the "run" target but with the --debug flag.\n'
   @echo 'make clean - Get rid of bytecode files, build and dist dirs, venv.'
   @echo 'make release - Register and upload a release on PyPI.'

@@ -68,6 +69,9 @@
   $(PYTHON) setup.py register sdist upload

  run: setup
+ $(VENV)/bin/python ./juju-quickstart
+
+debug: setup
   $(VENV)/bin/python ./juju-quickstart --debug

  source:

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: quickstart/app.py
=== modified file 'quickstart/app.py'
--- quickstart/app.py 2014-01-31 16:35:01 +0000
+++ quickstart/app.py 2014-01-31 21:00:06 +0000
@@ -96,11 +96,18 @@
      Allow the user to let quickstart create SSH keys, or quit by raising a
      ProgramExit if they would like to create the key themselves.
      """
+ # Test to see if we have ssh-keys loaded into the ssh-agent, or if we
can
+ # add them to the currently running ssh-agent.
+ if check_ssh_keys():
+ return
+
+ # No responsive agent was found. Start one up.
      try:
          utils.start_ssh_agent()
      except OSError as err:
          raise ProgramExit(bytes(err))

+ # And now check again.
      if not check_ssh_keys():
          print('Warning: No SSH keys were found in ~/.ssh\n\n'
                'To proceed and generate keys, quickstart can\n\n'

Index: quickstart/tests/test_app.py
=== modified file 'quickstart/tests/test_app.py'
--- quickstart/tests/test_app.py 2014-01-31 16:35:01 +0000
+++ quickstart/tests/test_app.py 2014-01-31 21:00:06 +0000
@@ -192,23 +192,41 @@
                 'quickstart:\n\n ssh-keygen -b 4096 -t rsa'

      def patch_check_ssh_keys(self,...

Read more...

54. By Brad Crittenden

Avoid calling system ssh-agent in tests

Revision history for this message
Brad Crittenden (bac) wrote :
Revision history for this message
Madison Scott-Clary (makyo) wrote :

This looks good, thanks for finding a better way around this!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches