Merge lp:~frankban/juju-quickstart/add-settings into lp:juju-quickstart

Proposed by Francesco Banconi
Status: Merged
Merged at revision: 13
Proposed branch: lp:~frankban/juju-quickstart/add-settings
Merge into: lp:juju-quickstart
Diff against target: 274 lines (+71/-29)
7 files modified
quickstart/app.py (+2/-6)
quickstart/manage.py (+6/-7)
quickstart/settings.py (+36/-0)
quickstart/tests/test_app.py (+6/-3)
quickstart/tests/test_manage.py (+10/-5)
quickstart/tests/test_utils.py (+7/-4)
quickstart/utils.py (+4/-4)
To merge this branch: bzr merge lp:~frankban/juju-quickstart/add-settings
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+195057@code.launchpad.net

Description of the change

Put constant parameters in a separate module.

Added a settings module where to store constants
reused in different parts of the application.

This is just a mechanical branch and it does
not include other changes.

https://codereview.appspot.com/26060043/

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

Reviewers: mp+195057_code.launchpad.net,

Message:
Please take a look.

Description:
Put constant parameters in a separate module.

Added a settings module where to store constants
reused in different parts of the application.

This is just a mechanical branch and it does
not include other changes.

https://code.launchpad.net/~frankban/juju-quickstart/add-settings/+merge/195057

(do not edit description out of merge proposal)

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

Affected files (+73, -29 lines):
   A [revision details]
   M quickstart/app.py
   M quickstart/manage.py
   A quickstart/settings.py
   M quickstart/tests/test_app.py
   M quickstart/tests/test_manage.py
   M quickstart/tests/test_utils.py
   M quickstart/utils.py

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

LGTM. Were you driven to do this now because of circular import fun?

https://codereview.appspot.com/26060043/

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

*** Submitted:

Put constant parameters in a separate module.

Added a settings module where to store constants
reused in different parts of the application.

This is just a mechanical branch and it does
not include other changes.

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

https://codereview.appspot.com/26060043/

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

On 2013/11/13 13:37:51, gary.poster wrote:
> LGTM. Were you driven to do this now because of circular import fun?

Well, I did this in prevision of that possibility, and also to have
a single place where looking for names which can be useful and used
in different parts of the code base.

Thank you!

https://codereview.appspot.com/26060043/

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-11-12 15:55:34 +0000
3+++ quickstart/app.py 2013-11-13 13:18:35 +0000
4@@ -25,15 +25,11 @@
5
6 from quickstart import (
7 juju,
8+ settings,
9 utils,
10 )
11
12
13-# The default Juju GUI charm URL to use when it is not possible to retrieve it
14-# from the charmworld API, e.g. due to temporary connection/charmworld errors.
15-DEFAULT_CHARM_URL = 'cs:precise/juju-gui-79'
16-
17-
18 class ProgramExit(Exception):
19 """An error occurred while setting up the Juju environment.
20
21@@ -133,7 +129,7 @@
22 except (IOError, ValueError) as err:
23 msg = 'unable to retrieve the Juju GUI charm URL from the API: {}'
24 logging.warn(msg.format(err))
25- charm_url = DEFAULT_CHARM_URL
26+ charm_url = settings.DEFAULT_CHARM_URL
27 print('charm URL: {}'.format(charm_url))
28 try:
29 env.deploy(service_name, charm_url, to=0)
30
31=== modified file 'quickstart/manage.py'
32--- quickstart/manage.py 2013-11-12 17:01:34 +0000
33+++ quickstart/manage.py 2013-11-13 13:18:35 +0000
34@@ -25,12 +25,11 @@
35 import quickstart
36 from quickstart import (
37 app,
38+ settings,
39 utils,
40 )
41
42
43-juju_home = os.getenv('JUJU_HOME', '~/.juju')
44-description = 'set up a Juju environment (including the GUI) in very few steps'
45 version = quickstart.get_version()
46
47
48@@ -38,7 +37,7 @@
49 """A customized argparse action that just shows a description."""
50
51 def __call__(self, parser, *args, **kwargs):
52- print(description)
53+ print(settings.DESCRIPTION)
54 parser.exit()
55
56
57@@ -180,8 +179,8 @@
58 'required if the bundle YAML/JSON only contains one bundle. This '
59 'option is ignored if the bundle file is not specified')
60 parser.add_argument(
61- '--environments-file',
62- default=os.path.join(juju_home, 'environments.yaml'), dest='env_file',
63+ '--environments-file', dest='env_file',
64+ default=os.path.join(settings.JUJU_HOME, 'environments.yaml'),
65 help='The path to the Juju environments YAML file (%(default)s)')
66 parser.add_argument(
67 '--gui-charm-url', dest='charm_url',
68@@ -225,9 +224,9 @@
69 print('connecting to {}'.format(api_url))
70 env = app.connect(api_url, options.admin_secret)
71 print('requesting Juju GUI deployment')
72- app.deploy_gui(env, 'juju-gui', charm_url=options.charm_url)
73+ app.deploy_gui(env, settings.JUJU_GUI_NAME, charm_url=options.charm_url)
74 print('Juju GUI deployment request accepted')
75- address = app.watch(env, 'juju-gui')
76+ address = app.watch(env, settings.JUJU_GUI_NAME)
77 url = 'https://{}'.format(address)
78 print('url: {}\npassword: {}'.format(url, options.admin_secret))
79
80
81=== added file 'quickstart/settings.py'
82--- quickstart/settings.py 1970-01-01 00:00:00 +0000
83+++ quickstart/settings.py 2013-11-13 13:18:35 +0000
84@@ -0,0 +1,36 @@
85+# This file is part of the Juju Quickstart Plugin, which lets users set up a
86+# Juju environment in very few steps (https://launchpad.net/juju-quickstart).
87+# Copyright (C) 2013 Canonical Ltd.
88+#
89+# This program is free software: you can redistribute it and/or modify it under
90+# the terms of the GNU Affero General Public License version 3, as published by
91+# the Free Software Foundation.
92+#
93+# This program is distributed in the hope that it will be useful, but WITHOUT
94+# ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
95+# SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
96+# Affero General Public License for more details.
97+#
98+# You should have received a copy of the GNU Affero General Public License
99+# along with this program. If not, see <http://www.gnu.org/licenses/>.
100+
101+"""Juju Quickstart settings."""
102+
103+import os
104+
105+
106+# The URL containing information about the last Juju GUI charm version.
107+CHARMWORLD_API = 'http://manage.jujucharms.com/api/3/charm/precise/juju-gui'
108+
109+# The default Juju GUI charm URL to use when it is not possible to retrieve it
110+# from the charmworld API, e.g. due to temporary connection/charmworld errors.
111+DEFAULT_CHARM_URL = 'cs:precise/juju-gui-79'
112+
113+# The quickstart app short description.
114+DESCRIPTION = 'set up a Juju environment (including the GUI) in very few steps'
115+
116+# Retrieve the current juju-core home.
117+JUJU_HOME = os.getenv('JUJU_HOME', '~/.juju')
118+
119+# The name of the Juju GUI service.
120+JUJU_GUI_NAME = 'juju-gui'
121
122=== modified file 'quickstart/tests/test_app.py'
123--- quickstart/tests/test_app.py 2013-11-06 15:12:43 +0000
124+++ quickstart/tests/test_app.py 2013-11-13 13:18:35 +0000
125@@ -24,7 +24,10 @@
126 import mock
127 import yaml
128
129-from quickstart import app
130+from quickstart import (
131+ app,
132+ settings,
133+)
134 from quickstart.tests import helpers
135
136
137@@ -282,11 +285,11 @@
138 with helpers.assert_logs([log], level='warn'):
139 app.deploy_gui(env, 'my-gui')
140 env.assert_has_calls([
141- mock.call.deploy('my-gui', app.DEFAULT_CHARM_URL, to=0),
142+ mock.call.deploy('my-gui', settings.DEFAULT_CHARM_URL, to=0),
143 mock.call.expose('my-gui')
144 ])
145 mock_print.assert_called_once_with(
146- 'charm URL: {}'.format(app.DEFAULT_CHARM_URL))
147+ 'charm URL: {}'.format(settings.DEFAULT_CHARM_URL))
148
149 def test_deployment_provided_charm_url(self, mock_print):
150 # The function correctly deploys and exposes the service using a user
151
152=== modified file 'quickstart/tests/test_manage.py'
153--- quickstart/tests/test_manage.py 2013-11-12 15:34:15 +0000
154+++ quickstart/tests/test_manage.py 2013-11-13 13:18:35 +0000
155@@ -27,7 +27,10 @@
156 import yaml
157
158 import quickstart
159-from quickstart import manage
160+from quickstart import (
161+ manage,
162+ settings,
163+)
164 from quickstart.tests import helpers
165
166
167@@ -44,7 +47,7 @@
168 # The action just prints the description and exits.
169 args = self.parser.parse_args(['--test'])
170 self.assertIsNone(args.test)
171- mock_print.assert_called_once_with(manage.description)
172+ mock_print.assert_called_once_with(settings.DESCRIPTION)
173 mock_exit.assert_called_once_with(0)
174
175
176@@ -293,7 +296,7 @@
177 # The program description is properly printed out as required by juju.
178 with mock.patch('__builtin__.print') as mock_print:
179 self.call_setup(['--description'])
180- mock_print.assert_called_once_with(manage.description)
181+ mock_print.assert_called_once_with(settings.DESCRIPTION)
182
183 def test_version(self):
184 # The program version is properly printed to stderr.
185@@ -353,8 +356,10 @@
186 mock_app.connect.assert_called_once_with(
187 mock_app.get_api_url(), options.admin_secret)
188 mock_app.deploy_gui.assert_called_once_with(
189- mock_app.connect(), 'juju-gui', charm_url=options.charm_url)
190- mock_app.watch.assert_called_once_with(mock_app.connect(), 'juju-gui')
191+ mock_app.connect(), settings.JUJU_GUI_NAME,
192+ charm_url=options.charm_url)
193+ mock_app.watch.assert_called_once_with(
194+ mock_app.connect(), settings.JUJU_GUI_NAME)
195 mock_open.assert_called_once_with(
196 'https://{}'.format(mock_app.watch()))
197 self.assertFalse(mock_app.deploy_bundle.called)
198
199=== modified file 'quickstart/tests/test_utils.py'
200--- quickstart/tests/test_utils.py 2013-11-12 19:45:11 +0000
201+++ quickstart/tests/test_utils.py 2013-11-13 13:18:35 +0000
202@@ -25,7 +25,10 @@
203 import mock
204 import yaml
205
206-from quickstart import utils
207+from quickstart import (
208+ settings,
209+ utils,
210+)
211 from quickstart.tests import helpers
212
213
214@@ -105,14 +108,14 @@
215 with self.patch_urlread(contents=contents) as mock_urlread:
216 charm_url = utils.get_charm_url()
217 self.assertEqual('cs:precise/juju-gui-42', charm_url)
218- mock_urlread.assert_called_once_with(utils.CHARMWORLD_API)
219+ mock_urlread.assert_called_once_with(settings.CHARMWORLD_API)
220
221 def test_io_error(self):
222 # IOErrors are properly propagated.
223 with self.patch_urlread(error=True) as mock_urlread:
224 with self.assertRaises(IOError) as context_manager:
225 utils.get_charm_url()
226- mock_urlread.assert_called_once_with(utils.CHARMWORLD_API)
227+ mock_urlread.assert_called_once_with(settings.CHARMWORLD_API)
228 self.assertEqual('bad wolf', str(context_manager.exception))
229
230 def test_value_error(self):
231@@ -121,7 +124,7 @@
232 with self.patch_urlread(contents=contents) as mock_urlread:
233 with self.assertRaises(ValueError) as context_manager:
234 utils.get_charm_url()
235- mock_urlread.assert_called_once_with(utils.CHARMWORLD_API)
236+ mock_urlread.assert_called_once_with(settings.CHARMWORLD_API)
237 self.assertEqual(
238 'unable to find the charm URL', str(context_manager.exception))
239
240
241=== modified file 'quickstart/utils.py'
242--- quickstart/utils.py 2013-11-12 19:45:11 +0000
243+++ quickstart/utils.py 2013-11-13 13:18:35 +0000
244@@ -29,10 +29,10 @@
245
246 import yaml
247
248+from quickstart import settings
249+
250 # Compile the regular expression used to parse the "juju switch" output.
251 _juju_switch_expression = re.compile(r'Current environment: "([\w-]+)"\n')
252-# Define the URL containing information about the last Juju GUI charm version.
253-CHARMWORLD_API = 'http://manage.jujucharms.com/api/3/charm/precise/juju-gui'
254
255
256 def call(*args):
257@@ -75,7 +75,7 @@
258 Raise an IOError if any problems occur connecting to the API endpoint.
259 Raise a ValueError if the API returns invalid data.
260 """
261- charm_info = json.loads(urlread(CHARMWORLD_API))
262+ charm_info = json.loads(urlread(settings.CHARMWORLD_API))
263 charm_url = charm_info.get('charm', {}).get('url')
264 if charm_url is None:
265 raise ValueError('unable to find the charm URL')
266@@ -162,7 +162,7 @@
267 if not bundle_services:
268 msg = 'bundle {} does not include any services'.format(bundle_name)
269 raise ValueError(msg)
270- if 'juju-gui' in bundle_services:
271+ if settings.JUJU_GUI_NAME in bundle_services:
272 raise ValueError('bundle {} contains an instance of juju-gui. '
273 'quickstart will install the latest version of the '
274 'Juju GUI automatically, please remove juju-gui from '

Subscribers

People subscribed via source and target branches