Merge lp:~makyo/juju-quickstart/ssh-1-check-keys into lp:juju-quickstart

Proposed by Madison Scott-Clary
Status: Merged
Merged at revision: 29
Proposed branch: lp:~makyo/juju-quickstart/ssh-1-check-keys
Merge into: lp:juju-quickstart
Diff against target: 77 lines (+34/-0)
4 files modified
quickstart/app.py (+8/-0)
quickstart/manage.py (+2/-0)
quickstart/tests/test_app.py (+22/-0)
quickstart/tests/test_manage.py (+2/-0)
To merge this branch: bzr merge lp:~makyo/juju-quickstart/ssh-1-check-keys
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+197959@code.launchpad.net

Description of the change

SSH keys 1: abort if no keys

Juju needs ssh keys available to run. This ensures via ssh-add that there are keys available to the agent; if not, it exits with instructions on how to generate a key.

To test: make check

To QA:
1. mv ~/.ssh ~/.ssh.old
2. .venv/bin/python juju-quickstart # should produce error
3. mv ~/.ssh.old ~/.ssh
4. ssh-agent
5. ssh-add
6. .venv/bin/python juju-quickstart # should bootstrap

https://codereview.appspot.com/37930043/

To post a comment you must log in.
Revision history for this message
Madison Scott-Clary (makyo) wrote :
Download full text (4.2 KiB)

Reviewers: mp+197959_code.launchpad.net,

Message:
Please take a look.

Description:
SSH keys 1: abort if no keys

Juju needs ssh keys available to run. This ensures via ssh-add that
there are keys available to the agent; if not, it exits with
instructions on how to generate a key.

To test: make check

To QA:
1. mv ~/.ssh ~/.ssh.old
2. .venv/bin/python juju-quickstart # should produce error
3. mv ~/.ssh.old ~/.ssh
4. ssh-agent
5. ssh-add
6. .venv/bin/python juju-quickstart # should bootstrap

https://code.launchpad.net/~makyo/juju-quickstart/ssh-1-check-keys/+merge/197959

(do not edit description out of merge proposal)

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

Affected files (+36, -0 lines):
   A [revision details]
   M quickstart/app.py
   M quickstart/manage.py
   M quickstart/tests/test_app.py
   M quickstart/tests/test_manage.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: quickstart/app.py
=== modified file 'quickstart/app.py'
--- quickstart/app.py 2013-12-04 22:16:45 +0000
+++ quickstart/app.py 2013-12-05 19:54:20 +0000
@@ -79,6 +79,14 @@
              raise ProgramExit(error)

+def ensure_ssh_keys():
+ retcode = utils.call('/usr/bin/ssh-add', '-l')[0]
+ if retcode > 0:
+ raise ProgramExit('no ssh keys were found. Please run the
following: '
+ '`ssh-keygen -t rsa` and follow the
instructions '
+ 'before running quickstart again.')
+
+
  def ensure_environments():
      """Ensure that the environments file exists.

Index: quickstart/manage.py
=== modified file 'quickstart/manage.py'
--- quickstart/manage.py 2013-12-04 22:16:45 +0000
+++ quickstart/manage.py 2013-12-05 19:54:20 +0000
@@ -269,6 +269,8 @@
      print('juju quickstart v{}'.format(version))
      logging.debug('ensuring juju and lxc are installed')
      app.ensure_dependencies()
+ logging.debug('ensuring SSH keys are available')
+ app.ensure_ssh_keys()
      print('bootstrapping the {} environment (type: {})'.format(
          options.env_name, options.env_type))
      is_local = options.env_type == 'local'

Index: quickstart/tests/test_app.py
=== modified file 'quickstart/tests/test_app.py'
--- quickstart/tests/test_app.py 2013-12-04 22:16:45 +0000
+++ quickstart/tests/test_app.py 2013-12-05 19:54:20 +0000
@@ -174,6 +174,28 @@
              self.assertEqual(3, mock_call.call_count)

+class TestEnsureSSHKeys(
+ helpers.CallTestsMixin, ProgramExitTestsMixin, unittest.TestCase):
+
+ def test_success(self):
+ with self.patch_call(0) as mock_call:
+ app.ensure_ssh_keys()
+ mock_call.assert_has_calls([
+ mock.call('/usr/bin/ssh-add', '-l')
+ ])
+
+ def test_failure(self):
+ msg = 'no ssh keys were found. Please run the following: ' \
+ '`ssh-keygen -t rsa` and follow the instructions ' \
+ 'before ...

Read more...

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

Notes below

https://codereview.appspot.com/37930043/diff/1/quickstart/app.py
File quickstart/app.py (right):

https://codereview.appspot.com/37930043/diff/1/quickstart/app.py#newcode83
quickstart/app.py:83: retcode = utils.call('/usr/bin/ssh-add', '-l')[0]
retcode will be 130 if no agent was found, 127 if no keys were found, 0
(with output) if keys are available.

https://codereview.appspot.com/37930043/diff/1/quickstart/app.py#newcode85
quickstart/app.py:85: raise ProgramExit('no ssh keys were found. Please
run the following: '
Feel free to correct me on this message; just a best-guess.

https://codereview.appspot.com/37930043/

Revision history for this message
Gary Poster (gary) wrote :

LGTM and QA OK. Thank you!

https://codereview.appspot.com/37930043/diff/1/quickstart/app.py
File quickstart/app.py (right):

https://codereview.appspot.com/37930043/diff/1/quickstart/app.py#newcode83
quickstart/app.py:83: retcode = utils.call('/usr/bin/ssh-add', '-l')[0]
On 2013/12/05 20:38:19, matthew.scott wrote:
> retcode will be 130 if no agent was found, 127 if no keys were found,
0 (with
> output) if keys are available.

I suggest adding this note as a comment.

https://codereview.appspot.com/37930043/diff/1/quickstart/app.py#newcode85
quickstart/app.py:85: raise ProgramExit('no ssh keys were found. Please
run the following: '
On 2013/12/05 20:38:19, matthew.scott wrote:
> Feel free to correct me on this message; just a best-guess.

I suggest this one (with new lines as indicated).

No ssh keys were found.\n
Please run these commands and follow the instructions they produce
before running quickstart again:\n
\n
ssh-keygen -t rsa
ssh-agent
ssh-add

https://codereview.appspot.com/37930043/

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

*** Submitted:

SSH keys 1: abort if no keys

Juju needs ssh keys available to run. This ensures via ssh-add that
there are keys available to the agent; if not, it exits with
instructions on how to generate a key.

To test: make check

To QA:
1. mv ~/.ssh ~/.ssh.old
2. .venv/bin/python juju-quickstart # should produce error
3. mv ~/.ssh.old ~/.ssh
4. ssh-agent
5. ssh-add
6. .venv/bin/python juju-quickstart # should bootstrap

R=gary.poster
CC=
https://codereview.appspot.com/37930043

https://codereview.appspot.com/37930043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'quickstart/app.py'
2--- quickstart/app.py 2013-12-04 22:16:45 +0000
3+++ quickstart/app.py 2013-12-05 20:35:29 +0000
4@@ -79,6 +79,14 @@
5 raise ProgramExit(error)
6
7
8+def ensure_ssh_keys():
9+ retcode = utils.call('/usr/bin/ssh-add', '-l')[0]
10+ if retcode > 0:
11+ raise ProgramExit('no ssh keys were found. Please run the following: '
12+ '`ssh-keygen -t rsa` and follow the instructions '
13+ 'before running quickstart again.')
14+
15+
16 def ensure_environments():
17 """Ensure that the environments file exists.
18
19
20=== modified file 'quickstart/manage.py'
21--- quickstart/manage.py 2013-12-04 22:16:45 +0000
22+++ quickstart/manage.py 2013-12-05 20:35:29 +0000
23@@ -269,6 +269,8 @@
24 print('juju quickstart v{}'.format(version))
25 logging.debug('ensuring juju and lxc are installed')
26 app.ensure_dependencies()
27+ logging.debug('ensuring SSH keys are available')
28+ app.ensure_ssh_keys()
29 print('bootstrapping the {} environment (type: {})'.format(
30 options.env_name, options.env_type))
31 is_local = options.env_type == 'local'
32
33=== modified file 'quickstart/tests/test_app.py'
34--- quickstart/tests/test_app.py 2013-12-04 22:16:45 +0000
35+++ quickstart/tests/test_app.py 2013-12-05 20:35:29 +0000
36@@ -174,6 +174,28 @@
37 self.assertEqual(3, mock_call.call_count)
38
39
40+class TestEnsureSSHKeys(
41+ helpers.CallTestsMixin, ProgramExitTestsMixin, unittest.TestCase):
42+
43+ def test_success(self):
44+ with self.patch_call(0) as mock_call:
45+ app.ensure_ssh_keys()
46+ mock_call.assert_has_calls([
47+ mock.call('/usr/bin/ssh-add', '-l')
48+ ])
49+
50+ def test_failure(self):
51+ msg = 'no ssh keys were found. Please run the following: ' \
52+ '`ssh-keygen -t rsa` and follow the instructions ' \
53+ 'before running quickstart again.'
54+ with self.assert_program_exit(msg):
55+ with self.patch_call(130) as mock_call:
56+ app.ensure_ssh_keys()
57+ mock_call.assert_has_calls([
58+ mock.call('/usr/bin/ssh-add', '-l')
59+ ])
60+
61+
62 @helpers.mock_print
63 class TestEnsureEnvironments(
64 helpers.CallTestsMixin, ProgramExitTestsMixin, unittest.TestCase):
65
66=== modified file 'quickstart/tests/test_manage.py'
67--- quickstart/tests/test_manage.py 2013-12-04 22:16:45 +0000
68+++ quickstart/tests/test_manage.py 2013-12-05 20:35:29 +0000
69@@ -442,6 +442,8 @@
70 mock_app.bootstrap.return_value = (True, 'precise')
71 options = self.make_options()
72 manage.run(options)
73+ mock_app.ensure_dependencies.assert_called()
74+ mock_app.ensure_ssh_keys.assert_called()
75 mock_app.bootstrap.assert_called_once_with(
76 options.env_name, is_local=False, debug=options.debug)
77 mock_app.get_api_url.assert_called_once_with(options.env_name)

Subscribers

People subscribed via source and target branches