Merge lp:~frankban/juju-quickstart/local-osx into lp:juju-quickstart

Proposed by Francesco Banconi
Status: Merged
Merged at revision: 82
Proposed branch: lp:~frankban/juju-quickstart/local-osx
Merge into: lp:juju-quickstart
Diff against target: 301 lines (+114/-22)
6 files modified
quickstart/cli/views.py (+35/-11)
quickstart/manage.py (+1/-1)
quickstart/models/envs.py (+6/-2)
quickstart/tests/cli/test_views.py (+55/-5)
quickstart/tests/models/test_envs.py (+16/-2)
quickstart/tests/test_manage.py (+1/-1)
To merge this branch: bzr merge lp:~frankban/juju-quickstart/local-osx
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+223220@code.launchpad.net

Description of the change

Avoid proposing LXC envs as an option on MacOS.

https://codereview.appspot.com/105250043/

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

Reviewers: mp+223220_code.launchpad.net,

Message:
Please take a look.

Description:
Avoid proposing LXC envs as an option on MacOS.

https://code.launchpad.net/~frankban/juju-quickstart/local-osx/+merge/223220

(do not edit description out of merge proposal)

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

Affected files (+116, -22 lines):
   A [revision details]
   M quickstart/cli/views.py
   M quickstart/manage.py
   M quickstart/models/envs.py
   M quickstart/tests/cli/test_views.py
   M quickstart/tests/models/test_envs.py
   M quickstart/tests/test_manage.py

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

LGTM with some typo fixes and QA-ok. Thanks Francesco.

https://codereview.appspot.com/105250043/diff/1/quickstart/tests/cli/test_views.py
File quickstart/tests/cli/test_views.py (right):

https://codereview.appspot.com/105250043/diff/1/quickstart/tests/cli/test_views.py#newcode42
quickstart/tests/cli/test_views.py:42: The value arguments is a boolean
representing whether or not local
typo: s/arguments/argument/

https://codereview.appspot.com/105250043/diff/1/quickstart/tests/cli/test_views.py#newcode186
quickstart/tests/cli/test_views.py:186: # The option to create a new
local environments is not present if they
typo: s/environments/environment/

https://codereview.appspot.com/105250043/

90. By Francesco Banconi

Fix typos.

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

*** Submitted:

Avoid proposing LXC envs as an option on MacOS.

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

https://codereview.appspot.com/105250043/diff/1/quickstart/tests/cli/test_views.py
File quickstart/tests/cli/test_views.py (right):

https://codereview.appspot.com/105250043/diff/1/quickstart/tests/cli/test_views.py#newcode42
quickstart/tests/cli/test_views.py:42: The value arguments is a boolean
representing whether or not local
On 2014/06/16 12:27:11, bac wrote:
> typo: s/arguments/argument/

Done.

https://codereview.appspot.com/105250043/diff/1/quickstart/tests/cli/test_views.py#newcode186
quickstart/tests/cli/test_views.py:186: # The option to create a new
local environments is not present if they
On 2014/06/16 12:27:11, bac wrote:
> typo: s/environments/environment/

Done.

https://codereview.appspot.com/105250043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'quickstart/cli/views.py'
2--- quickstart/cli/views.py 2014-04-23 15:53:32 +0000
3+++ quickstart/cli/views.py 2014-06-16 12:33:53 +0000
4@@ -102,7 +102,10 @@
5
6 import urwid
7
8-from quickstart import settings
9+from quickstart import (
10+ platform_support,
11+ settings,
12+)
13 from quickstart.cli import (
14 base,
15 forms,
16@@ -170,6 +173,9 @@
17 # Use the newly created environment.
18 raise ui.AppExit((env_db, env_data))
19
20+ platform = platform_support.get_platform()
21+ supports_local = platform_support.supports_local(platform)
22+
23 if environments:
24 title = 'Select an existing Juju environment or create a new one'
25 widgets = [
26@@ -188,16 +194,24 @@
27 'Quickstart in interactive mode again by passing the -i flag, '
28 'e.g.:\n',
29 ('highlight', '$ juju quickstart -i'),
30- '\n\nAt the bottom of the page you can find links to manually '
31- 'create new environments. If you instead prefer to quickly '
32- 'start your Juju experience in a local environment (LXC), '
33- 'just click the link below:'
34 ]),
35- urwid.Divider(),
36- ui.MenuButton(
37- '\N{BULLET} automatically create and bootstrap a local '
38- 'environment', ui.thunk(create_and_start_local_env)),
39 ]
40+ # If the current platform supports local Juju environments, add an
41+ # option to automatically create and bootstrap one.
42+ if supports_local:
43+ widgets.extend([
44+ urwid.Text([
45+ '\nAt the bottom of the page you can find links to '
46+ 'manually create new environments. If you instead prefer '
47+ 'to quickly start your Juju experience in a local '
48+ 'environment (LXC), just click the link below:'
49+ ]),
50+ urwid.Divider(),
51+ ui.MenuButton(
52+ '\N{BULLET} automatically create and bootstrap a local '
53+ 'environment', ui.thunk(create_and_start_local_env)),
54+ ])
55+
56 app.set_title(title)
57 # Start creating the page contents: a list of selectable environments.
58 # Wouldn't it be nice if we were able to highlight in some way the
59@@ -225,7 +239,8 @@
60 env_short_description = envs.get_env_short_description(env_data)
61 text = [bullet, ' {}'.format(env_short_description)]
62 widgets.append(ui.MenuButton(text, ui.thunk(detail_view, env_data)))
63- # Add the buttons used to create new environments.
64+
65+ # Set up the "create a new environment" section.
66 widgets.extend([
67 urwid.Divider(),
68 urwid.Text((
69@@ -236,14 +251,23 @@
70 # series matches one of the series supported by the GUI.
71 # Suggest the most recent supported series by pre-filling the value.
72 preferred_series = settings.JUJU_GUI_SUPPORTED_SERIES[-1]
73+ # Retrieve the list of supported environment types: exclude the local
74+ # environment if not supported by the current OS platform.
75+ filter_function = None
76+ if not supports_local:
77+ filter_function = lambda env_type, _: env_type != 'local'
78+ supported_env_types = envs.get_supported_env_types(
79+ env_type_db, filter_function=filter_function)
80+ # Add the buttons used to create new environments.
81 widgets.extend([
82 ui.MenuButton(
83 ['\N{BULLET} new ', ('highlight', label), ' environment'],
84 ui.thunk(edit_view, {
85 'type': env_type, 'default-series': preferred_series})
86 )
87- for env_type, label in envs.get_supported_env_types(env_type_db)
88+ for env_type, label in supported_env_types
89 ])
90+
91 # Set up the application status messages.
92 status = [' \N{UPWARDS ARROW LEFTWARDS OF DOWNWARDS ARROW} navigate ']
93 if default_found:
94
95=== modified file 'quickstart/manage.py'
96--- quickstart/manage.py 2014-06-13 14:36:30 +0000
97+++ quickstart/manage.py 2014-06-16 12:33:53 +0000
98@@ -290,7 +290,7 @@
99 no_local_support = not platform_support.supports_local(options.platform)
100 if options.env_type == 'local' and no_local_support:
101 return parser.error(
102- 'This host platform does not support local environments.'
103+ 'this host platform does not support local environments'
104 )
105 # Update the options namespace with the new values.
106 options.admin_secret = env_data.get('admin-secret')
107
108=== modified file 'quickstart/models/envs.py'
109--- quickstart/models/envs.py 2014-04-23 11:22:44 +0000
110+++ quickstart/models/envs.py 2014-06-16 12:33:53 +0000
111@@ -685,15 +685,19 @@
112 return env_type_db
113
114
115-def get_supported_env_types(env_type_db):
116+def get_supported_env_types(env_type_db, filter_function=None):
117 """Return a list of supported (provider type, label) tuples.
118
119 Each tuple represents an environment type supported by Quickstart.
120+ It is possible to filter results by providing a filter_function callable
121+ which receives the environment type and metadata.
122 """
123+ if filter_function is None:
124+ filter_function = lambda env_type, metadata: True
125 return [
126 (env_type, metadata['label'])
127 for env_type, metadata in env_type_db.items()
128- if env_type != '__fallback__'
129+ if (env_type != '__fallback__') and filter_function(env_type, metadata)
130 ]
131
132
133
134=== modified file 'quickstart/tests/cli/test_views.py'
135--- quickstart/tests/cli/test_views.py 2014-04-23 12:20:35 +0000
136+++ quickstart/tests/cli/test_views.py 2014-06-16 12:33:53 +0000
137@@ -36,6 +36,18 @@
138 from quickstart.tests.cli import helpers as cli_helpers
139
140
141+def local_envs_supported(value):
142+ """Simulate local environments support in the current platform.
143+
144+ The value argument is a boolean representing whether or not local
145+ environments are supported.
146+ Return a context manager that can be used when calling views.
147+ """
148+ return mock.patch(
149+ 'quickstart.cli.views.platform_support.supports_local',
150+ mock.Mock(return_value=value))
151+
152+
153 class TestShow(unittest.TestCase):
154
155 @contextmanager
156@@ -125,6 +137,8 @@
157 class TestEnvIndex(EnvViewTestsMixin, unittest.TestCase):
158
159 base_status = ' \N{UPWARDS ARROW LEFTWARDS OF DOWNWARDS ARROW} navigate '
160+ create_local_caption = (
161+ '\N{BULLET} automatically create and bootstrap a local environment')
162
163 def test_view_default_return_value_on_exit(self):
164 # The view configures the app so that the return value on user exit is
165@@ -157,7 +171,9 @@
166 # The view displays a list of the environments in env_db, and buttons
167 # to create new environments.
168 env_db = helpers.make_env_db()
169- views.env_index(self.app, self.env_type_db, env_db, self.save_callable)
170+ with local_envs_supported(True):
171+ views.env_index(
172+ self.app, self.env_type_db, env_db, self.save_callable)
173 buttons = self.get_widgets_in_contents(
174 filter_function=self.is_a(ui.MenuButton))
175 # A button is created for each existing environment (see details) and
176@@ -166,6 +182,22 @@
177 expected_buttons_number = len(env_db['environments']) + len(env_types)
178 self.assertEqual(expected_buttons_number, len(buttons))
179
180+ def test_new_local_environment_disabled(self):
181+ # The option to create a new local environment is not present if they
182+ # are not supported in the current platform.
183+ env_db = helpers.make_env_db()
184+ with local_envs_supported(False):
185+ views.env_index(
186+ self.app, self.env_type_db, env_db, self.save_callable)
187+ buttons = self.get_widgets_in_contents(
188+ filter_function=self.is_a(ui.MenuButton))
189+ captions = map(cli_helpers.get_button_caption, buttons)
190+ create_local_captions = [
191+ caption for caption in captions
192+ if caption.startswith('\N{BULLET} new local')
193+ ]
194+ self.assertEqual([], create_local_captions)
195+
196 @mock.patch('quickstart.cli.views.env_detail')
197 def test_environment_clicked(self, mock_env_detail):
198 # The environment detail view is called when clicking an environment.
199@@ -196,7 +228,9 @@
200 # The environment edit view is called when clicking to create a new
201 # environment.
202 env_db = helpers.make_env_db()
203- views.env_index(self.app, self.env_type_db, env_db, self.save_callable)
204+ with local_envs_supported(True):
205+ views.env_index(
206+ self.app, self.env_type_db, env_db, self.save_callable)
207 buttons = self.get_widgets_in_contents(
208 filter_function=self.is_a(ui.MenuButton))
209 env_types = envs.get_supported_env_types(self.env_type_db)
210@@ -223,14 +257,16 @@
211 # If that option is clicked, the view quits the application returning
212 # the newly created env_data.
213 env_db = envs.create_empty_env_db()
214- views.env_index(self.app, self.env_type_db, env_db, self.save_callable)
215+ with local_envs_supported(True):
216+ views.env_index(
217+ self.app, self.env_type_db, env_db, self.save_callable)
218 buttons = self.get_widgets_in_contents(
219 filter_function=self.is_a(ui.MenuButton))
220 # The "create and bootstrap" button is the first one in the contents.
221 create_button = buttons[0]
222 self.assertEqual(
223- '\N{BULLET} automatically create and bootstrap a local '
224- 'environment', cli_helpers.get_button_caption(create_button))
225+ self.create_local_caption,
226+ cli_helpers.get_button_caption(create_button))
227 # An AppExit is raised clicking the button.
228 with self.assertRaises(ui.AppExit) as context_manager:
229 cli_helpers.emit(create_button)
230@@ -239,6 +275,20 @@
231 self.assertIn('local', new_env_db['environments'])
232 self.assertEqual(envs.get_env_data(new_env_db, 'local'), env_data)
233
234+ def test_create_and_bootstrap_local_environment_missing(self):
235+ # The option to automatically create and bootstrap a new local
236+ # environment is not displayed if the current platform does not support
237+ # local environments.
238+ env_db = envs.create_empty_env_db()
239+ with local_envs_supported(False):
240+ views.env_index(
241+ self.app, self.env_type_db, env_db, self.save_callable)
242+ buttons = self.get_widgets_in_contents(
243+ filter_function=self.is_a(ui.MenuButton))
244+ # No "create and bootstrap" buttons are present.
245+ captions = map(cli_helpers.get_button_caption, buttons)
246+ self.assertNotIn(self.create_local_caption, captions)
247+
248 def test_selected_environment(self):
249 # The default environment is already selected in the list.
250 env_db = helpers.make_env_db(default='lxc')
251
252=== modified file 'quickstart/tests/models/test_envs.py'
253--- quickstart/tests/models/test_envs.py 2014-04-23 12:20:35 +0000
254+++ quickstart/tests/models/test_envs.py 2014-06-16 12:33:53 +0000
255@@ -808,9 +808,12 @@
256
257 class TestGetSupportedEnvTypes(unittest.TestCase):
258
259+ def setUp(self):
260+ # Store the environments database.
261+ self.env_type_db = envs.get_env_type_db()
262+
263 def test_env_types(self):
264 # All the supported env_types but the fallback one are returned.
265- env_type_db = envs.get_env_type_db()
266 expected_env_types = [
267 ('ec2', 'Amazon EC2'),
268 ('openstack', 'OpenStack (or HP Public Cloud)'),
269@@ -818,7 +821,18 @@
270 ('joyent', 'Joyent'),
271 ('local', 'local (LXC)'),
272 ]
273- obtained_env_types = envs.get_supported_env_types(env_type_db)
274+ obtained_env_types = envs.get_supported_env_types(self.env_type_db)
275+ self.assertEqual(expected_env_types, obtained_env_types)
276+
277+ def test_filter_function(self):
278+ # Results can be filtered by providing a filter function.
279+ expected_env_types = [
280+ ('ec2', 'Amazon EC2'),
281+ ('joyent', 'Joyent'),
282+ ]
283+ func = lambda env_type, metadata: env_type in ('ec2', 'joyent')
284+ obtained_env_types = envs.get_supported_env_types(
285+ self.env_type_db, filter_function=func)
286 self.assertEqual(expected_env_types, obtained_env_types)
287
288
289
290=== modified file 'quickstart/tests/test_manage.py'
291--- quickstart/tests/test_manage.py 2014-06-13 13:47:27 +0000
292+++ quickstart/tests/test_manage.py 2014-06-16 12:33:53 +0000
293@@ -572,7 +572,7 @@
294 self.assertTrue(self.parser.error.called)
295 message = self.parser.error.call_args[0][0]
296 self.assertEqual(
297- 'This host platform does not support local environments.',
298+ 'this host platform does not support local environments',
299 message)
300
301 def test_interactive_mode(self):

Subscribers

People subscribed via source and target branches