Merge lp:~frankban/juju-quickstart/minor-fixes-0 into lp:juju-quickstart

Proposed by Francesco Banconi
Status: Merged
Merged at revision: 51
Proposed branch: lp:~frankban/juju-quickstart/minor-fixes-0
Merge into: lp:juju-quickstart
Diff against target: 170 lines (+56/-48)
5 files modified
HACKING.rst (+8/-0)
quickstart/app.py (+22/-22)
quickstart/manage.py (+5/-5)
quickstart/tests/test_app.py (+20/-20)
quickstart/tests/test_manage.py (+1/-1)
To merge this branch: bzr merge lp:~frankban/juju-quickstart/minor-fixes-0
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+203942@code.launchpad.net

Description of the change

Minor fixes to code comments and documentation

Also fixed a possible encoding problem in error handling.

The get_admin_secret function and its test case are just moved, no
need to re-review.

Tests: `make check`.
No QA.

https://codereview.appspot.com/58680043/

To post a comment you must log in.
Revision history for this message
Francesco Banconi (frankban) wrote :

Reviewers: mp+203942_code.launchpad.net,

Message:
Please take a look.

Description:
Minor fixes to code comments and documentation

Also fixed a possible encoding problem in error handling.

The get_admin_secret function and its test case are just moved, no
need to re-review.

Tests: `make check`.
No QA.

https://code.launchpad.net/~frankban/juju-quickstart/minor-fixes-0/+merge/203942

(do not edit description out of merge proposal)

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

Affected files (+58, -48 lines):
   M HACKING.rst
   A [revision details]
   M quickstart/app.py
   M quickstart/manage.py
   M quickstart/tests/test_app.py
   M quickstart/tests/test_manage.py

Revision history for this message
Brad Crittenden (bac) wrote :
Revision history for this message
Francesco Banconi (frankban) wrote :

*** Submitted:

Minor fixes to code comments and documentation

Also fixed a possible encoding problem in error handling.

The get_admin_secret function and its test case are just moved, no
need to re-review.

Tests: `make check`.
No QA.

R=bac
CC=
https://codereview.appspot.com/58680043

https://codereview.appspot.com/58680043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'HACKING.rst'
2--- HACKING.rst 2013-11-20 08:58:02 +0000
3+++ HACKING.rst 2014-01-30 12:27:24 +0000
4@@ -110,6 +110,14 @@
5 available. They are available in saucy, and they are also stored in our PPA in
6 order to support previous Ubuntu releases.
7
8+Creating PyPI releases
9+~~~~~~~~~~~~~~~~~~~~~~
10+
11+Juju Quickstart is present on PyPI: see
12+<https://pypi.python.org/pypi/juju-quickstart>.
13+It is possible to register and upload a new release on PyPI by just running
14+``make release`` and providing your PyPI credentials.
15+
16 Updating application and test dependencies
17 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18
19
20=== modified file 'quickstart/app.py'
21--- quickstart/app.py 2014-01-29 14:25:35 +0000
22+++ quickstart/app.py 2014-01-30 12:27:24 +0000
23@@ -288,6 +288,28 @@
24 raise ProgramExit('the state server is not ready:\n{}'.format(details))
25
26
27+def get_admin_secret(env_name, juju_home):
28+ """Read the admin-secret from the generated environment file.
29+
30+ At bootstrap, juju (v1.16 and later) writes the admin-secret to a
31+ generated file located in JUJU_HOME. Return the value.
32+ Raise a ValueError if:
33+ - the environment file is not found;
34+ - the environment file contents are not parsable by YAML;
35+ - the YAML contents are not properly structured;
36+ - the admin-secret is not found.
37+ """
38+ filename = '{}.jenv'.format(env_name)
39+ juju_env_file = os.path.expanduser(
40+ os.path.join(juju_home, 'environments', filename))
41+ jenv_db = envs.load_generated(juju_env_file)
42+ try:
43+ return jenv_db['admin-secret']
44+ except KeyError:
45+ msg = 'admin-secret not found in {}'.format(juju_env_file)
46+ raise ValueError(msg.encode('utf-8'))
47+
48+
49 def get_api_url(env_name):
50 """Return a Juju API URL for the given environment name.
51
52@@ -497,25 +519,3 @@
53 env.deploy_bundle(bundle_yaml, name=bundle_name, bundle_id=bundle_id)
54 except jujuclient.EnvError as err:
55 raise ProgramExit('bad API server response: {}'.format(err.message))
56-
57-
58-def get_admin_secret(env_name, juju_home):
59- """Read the admin-secret from the generated environment file.
60-
61- At bootstrap, juju (v1.16 and later) writes the admin-secret to a
62- generated file located in JUJU_HOME. Return the value.
63- Raise a ValueError if:
64- - the environment file is not found;
65- - the environment file contents are not parsable by YAML;
66- - the YAML contents are not properly structured;
67- - the admin-secret is not found.
68- """
69- filename = '{}.jenv'.format(env_name)
70- juju_env_file = os.path.expanduser(
71- os.path.join(juju_home, 'environments', filename))
72- jenv_db = envs.load_generated(juju_env_file)
73- try:
74- return jenv_db['admin-secret']
75- except KeyError:
76- msg = 'admin-secret not found in {}'.format(juju_env_file)
77- raise ValueError(msg.encode('utf-8'))
78
79=== modified file 'quickstart/manage.py'
80--- quickstart/manage.py 2014-01-29 14:25:35 +0000
81+++ quickstart/manage.py 2014-01-30 12:27:24 +0000
82@@ -392,17 +392,17 @@
83 already_bootstrapped, bsn_series = app.bootstrap(
84 options.env_name, is_local=is_local, debug=options.debug)
85
86- # The admin secret was not in the environments file. Retrieve it from
87- # the Juju-generated file.
88- # Find the Juju-generated environment file.
89+ # Retrieve the admin-secret for the current environment.
90 try:
91 admin_secret = app.get_admin_secret(
92 options.env_name, settings.JUJU_HOME)
93 except ValueError as err:
94 admin_secret = options.admin_secret
95 if admin_secret is None:
96- msg = err.message + ' or {}.'.format(options.env_file)
97- raise app.ProgramExit(msg.encode('utf-8'))
98+ # The admin-secret cannot be found in the jenv file and is not
99+ # explicitly specified in the environments.yaml file.
100+ msg = b'{} or {}'.format(err, options.env_file.encode('utf-8'))
101+ raise app.ProgramExit(msg)
102
103 print('retrieving the Juju API address')
104 api_url = app.get_api_url(options.env_name)
105
106=== modified file 'quickstart/tests/test_app.py'
107--- quickstart/tests/test_app.py 2014-01-29 14:25:35 +0000
108+++ quickstart/tests/test_app.py 2014-01-30 12:27:24 +0000
109@@ -569,6 +569,26 @@
110 ] + self.make_status_calls(2))
111
112
113+class TestGetAdminSecret(unittest.TestCase):
114+
115+ def test_no_admin_secret(self):
116+ with mock.patch('quickstart.manage.envs.load_generated',
117+ lambda x: {}):
118+ with self.assertRaises(ValueError) as exc:
119+ app.get_admin_secret('local', '/home/bac/.juju')
120+ expected = (
121+ u'admin-secret not found in '
122+ '/home/bac/.juju/environments/local.jenv')
123+ self.assertIn(expected, bytes(exc.exception))
124+
125+ def test_success(self):
126+ expected = 'superchunk'
127+ with mock.patch('quickstart.manage.envs.load_generated',
128+ lambda x: {'admin-secret': expected}):
129+ secret = app.get_admin_secret('local', '~bac/.juju')
130+ self.assertEqual(expected, secret)
131+
132+
133 class TestGetApiUrl(
134 helpers.CallTestsMixin, ProgramExitTestsMixin, unittest.TestCase):
135
136@@ -1311,23 +1331,3 @@
137 with self.assertRaises(ValueError) as context_manager:
138 app.deploy_bundle(env, self.yaml, self.name, None)
139 self.assertIs(error, context_manager.exception)
140-
141-
142-class TestGetAdminSecret(unittest.TestCase):
143-
144- def test_no_admin_secret(self):
145- with mock.patch('quickstart.manage.envs.load_generated',
146- lambda x: {}):
147- with self.assertRaises(ValueError) as exc:
148- app.get_admin_secret('local', '/home/bac/.juju')
149- expected = (
150- u'admin-secret not found in '
151- '/home/bac/.juju/environments/local.jenv')
152- self.assertIn(expected, bytes(exc.exception))
153-
154- def test_success(self):
155- expected = 'superchunk'
156- with mock.patch('quickstart.manage.envs.load_generated',
157- lambda x: {'admin-secret': expected}):
158- secret = app.get_admin_secret('local', '~bac/.juju')
159- self.assertEqual(expected, secret)
160
161=== modified file 'quickstart/tests/test_manage.py'
162--- quickstart/tests/test_manage.py 2014-01-29 14:26:43 +0000
163+++ quickstart/tests/test_manage.py 2014-01-30 12:27:24 +0000
164@@ -770,5 +770,5 @@
165 manage.run(options)
166 expected = (
167 u'admin-secret not found in ~/.juju/environments/local.jenv '
168- 'or environments.yaml.')
169+ 'or environments.yaml')
170 self.assertEqual(expected, context.exception.message)

Subscribers

People subscribed via source and target branches