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
=== modified file 'quickstart/cli/views.py'
--- quickstart/cli/views.py 2014-04-23 15:53:32 +0000
+++ quickstart/cli/views.py 2014-06-16 12:33:53 +0000
@@ -102,7 +102,10 @@
102102
103import urwid103import urwid
104104
105from quickstart import settings105from quickstart import (
106 platform_support,
107 settings,
108)
106from quickstart.cli import (109from quickstart.cli import (
107 base,110 base,
108 forms,111 forms,
@@ -170,6 +173,9 @@
170 # Use the newly created environment.173 # Use the newly created environment.
171 raise ui.AppExit((env_db, env_data))174 raise ui.AppExit((env_db, env_data))
172175
176 platform = platform_support.get_platform()
177 supports_local = platform_support.supports_local(platform)
178
173 if environments:179 if environments:
174 title = 'Select an existing Juju environment or create a new one'180 title = 'Select an existing Juju environment or create a new one'
175 widgets = [181 widgets = [
@@ -188,16 +194,24 @@
188 'Quickstart in interactive mode again by passing the -i flag, '194 'Quickstart in interactive mode again by passing the -i flag, '
189 'e.g.:\n',195 'e.g.:\n',
190 ('highlight', '$ juju quickstart -i'),196 ('highlight', '$ juju quickstart -i'),
191 '\n\nAt the bottom of the page you can find links to manually '
192 'create new environments. If you instead prefer to quickly '
193 'start your Juju experience in a local environment (LXC), '
194 'just click the link below:'
195 ]),197 ]),
196 urwid.Divider(),
197 ui.MenuButton(
198 '\N{BULLET} automatically create and bootstrap a local '
199 'environment', ui.thunk(create_and_start_local_env)),
200 ]198 ]
199 # If the current platform supports local Juju environments, add an
200 # option to automatically create and bootstrap one.
201 if supports_local:
202 widgets.extend([
203 urwid.Text([
204 '\nAt the bottom of the page you can find links to '
205 'manually create new environments. If you instead prefer '
206 'to quickly start your Juju experience in a local '
207 'environment (LXC), just click the link below:'
208 ]),
209 urwid.Divider(),
210 ui.MenuButton(
211 '\N{BULLET} automatically create and bootstrap a local '
212 'environment', ui.thunk(create_and_start_local_env)),
213 ])
214
201 app.set_title(title)215 app.set_title(title)
202 # Start creating the page contents: a list of selectable environments.216 # Start creating the page contents: a list of selectable environments.
203 # Wouldn't it be nice if we were able to highlight in some way the217 # Wouldn't it be nice if we were able to highlight in some way the
@@ -225,7 +239,8 @@
225 env_short_description = envs.get_env_short_description(env_data)239 env_short_description = envs.get_env_short_description(env_data)
226 text = [bullet, ' {}'.format(env_short_description)]240 text = [bullet, ' {}'.format(env_short_description)]
227 widgets.append(ui.MenuButton(text, ui.thunk(detail_view, env_data)))241 widgets.append(ui.MenuButton(text, ui.thunk(detail_view, env_data)))
228 # Add the buttons used to create new environments.242
243 # Set up the "create a new environment" section.
229 widgets.extend([244 widgets.extend([
230 urwid.Divider(),245 urwid.Divider(),
231 urwid.Text((246 urwid.Text((
@@ -236,14 +251,23 @@
236 # series matches one of the series supported by the GUI.251 # series matches one of the series supported by the GUI.
237 # Suggest the most recent supported series by pre-filling the value.252 # Suggest the most recent supported series by pre-filling the value.
238 preferred_series = settings.JUJU_GUI_SUPPORTED_SERIES[-1]253 preferred_series = settings.JUJU_GUI_SUPPORTED_SERIES[-1]
254 # Retrieve the list of supported environment types: exclude the local
255 # environment if not supported by the current OS platform.
256 filter_function = None
257 if not supports_local:
258 filter_function = lambda env_type, _: env_type != 'local'
259 supported_env_types = envs.get_supported_env_types(
260 env_type_db, filter_function=filter_function)
261 # Add the buttons used to create new environments.
239 widgets.extend([262 widgets.extend([
240 ui.MenuButton(263 ui.MenuButton(
241 ['\N{BULLET} new ', ('highlight', label), ' environment'],264 ['\N{BULLET} new ', ('highlight', label), ' environment'],
242 ui.thunk(edit_view, {265 ui.thunk(edit_view, {
243 'type': env_type, 'default-series': preferred_series})266 'type': env_type, 'default-series': preferred_series})
244 )267 )
245 for env_type, label in envs.get_supported_env_types(env_type_db)268 for env_type, label in supported_env_types
246 ])269 ])
270
247 # Set up the application status messages.271 # Set up the application status messages.
248 status = [' \N{UPWARDS ARROW LEFTWARDS OF DOWNWARDS ARROW} navigate ']272 status = [' \N{UPWARDS ARROW LEFTWARDS OF DOWNWARDS ARROW} navigate ']
249 if default_found:273 if default_found:
250274
=== modified file 'quickstart/manage.py'
--- quickstart/manage.py 2014-06-13 14:36:30 +0000
+++ quickstart/manage.py 2014-06-16 12:33:53 +0000
@@ -290,7 +290,7 @@
290 no_local_support = not platform_support.supports_local(options.platform)290 no_local_support = not platform_support.supports_local(options.platform)
291 if options.env_type == 'local' and no_local_support:291 if options.env_type == 'local' and no_local_support:
292 return parser.error(292 return parser.error(
293 'This host platform does not support local environments.'293 'this host platform does not support local environments'
294 )294 )
295 # Update the options namespace with the new values.295 # Update the options namespace with the new values.
296 options.admin_secret = env_data.get('admin-secret')296 options.admin_secret = env_data.get('admin-secret')
297297
=== modified file 'quickstart/models/envs.py'
--- quickstart/models/envs.py 2014-04-23 11:22:44 +0000
+++ quickstart/models/envs.py 2014-06-16 12:33:53 +0000
@@ -685,15 +685,19 @@
685 return env_type_db685 return env_type_db
686686
687687
688def get_supported_env_types(env_type_db):688def get_supported_env_types(env_type_db, filter_function=None):
689 """Return a list of supported (provider type, label) tuples.689 """Return a list of supported (provider type, label) tuples.
690690
691 Each tuple represents an environment type supported by Quickstart.691 Each tuple represents an environment type supported by Quickstart.
692 It is possible to filter results by providing a filter_function callable
693 which receives the environment type and metadata.
692 """694 """
695 if filter_function is None:
696 filter_function = lambda env_type, metadata: True
693 return [697 return [
694 (env_type, metadata['label'])698 (env_type, metadata['label'])
695 for env_type, metadata in env_type_db.items()699 for env_type, metadata in env_type_db.items()
696 if env_type != '__fallback__'700 if (env_type != '__fallback__') and filter_function(env_type, metadata)
697 ]701 ]
698702
699703
700704
=== modified file 'quickstart/tests/cli/test_views.py'
--- quickstart/tests/cli/test_views.py 2014-04-23 12:20:35 +0000
+++ quickstart/tests/cli/test_views.py 2014-06-16 12:33:53 +0000
@@ -36,6 +36,18 @@
36from quickstart.tests.cli import helpers as cli_helpers36from quickstart.tests.cli import helpers as cli_helpers
3737
3838
39def local_envs_supported(value):
40 """Simulate local environments support in the current platform.
41
42 The value argument is a boolean representing whether or not local
43 environments are supported.
44 Return a context manager that can be used when calling views.
45 """
46 return mock.patch(
47 'quickstart.cli.views.platform_support.supports_local',
48 mock.Mock(return_value=value))
49
50
39class TestShow(unittest.TestCase):51class TestShow(unittest.TestCase):
4052
41 @contextmanager53 @contextmanager
@@ -125,6 +137,8 @@
125class TestEnvIndex(EnvViewTestsMixin, unittest.TestCase):137class TestEnvIndex(EnvViewTestsMixin, unittest.TestCase):
126138
127 base_status = ' \N{UPWARDS ARROW LEFTWARDS OF DOWNWARDS ARROW} navigate '139 base_status = ' \N{UPWARDS ARROW LEFTWARDS OF DOWNWARDS ARROW} navigate '
140 create_local_caption = (
141 '\N{BULLET} automatically create and bootstrap a local environment')
128142
129 def test_view_default_return_value_on_exit(self):143 def test_view_default_return_value_on_exit(self):
130 # The view configures the app so that the return value on user exit is144 # The view configures the app so that the return value on user exit is
@@ -157,7 +171,9 @@
157 # The view displays a list of the environments in env_db, and buttons171 # The view displays a list of the environments in env_db, and buttons
158 # to create new environments.172 # to create new environments.
159 env_db = helpers.make_env_db()173 env_db = helpers.make_env_db()
160 views.env_index(self.app, self.env_type_db, env_db, self.save_callable)174 with local_envs_supported(True):
175 views.env_index(
176 self.app, self.env_type_db, env_db, self.save_callable)
161 buttons = self.get_widgets_in_contents(177 buttons = self.get_widgets_in_contents(
162 filter_function=self.is_a(ui.MenuButton))178 filter_function=self.is_a(ui.MenuButton))
163 # A button is created for each existing environment (see details) and179 # A button is created for each existing environment (see details) and
@@ -166,6 +182,22 @@
166 expected_buttons_number = len(env_db['environments']) + len(env_types)182 expected_buttons_number = len(env_db['environments']) + len(env_types)
167 self.assertEqual(expected_buttons_number, len(buttons))183 self.assertEqual(expected_buttons_number, len(buttons))
168184
185 def test_new_local_environment_disabled(self):
186 # The option to create a new local environment is not present if they
187 # are not supported in the current platform.
188 env_db = helpers.make_env_db()
189 with local_envs_supported(False):
190 views.env_index(
191 self.app, self.env_type_db, env_db, self.save_callable)
192 buttons = self.get_widgets_in_contents(
193 filter_function=self.is_a(ui.MenuButton))
194 captions = map(cli_helpers.get_button_caption, buttons)
195 create_local_captions = [
196 caption for caption in captions
197 if caption.startswith('\N{BULLET} new local')
198 ]
199 self.assertEqual([], create_local_captions)
200
169 @mock.patch('quickstart.cli.views.env_detail')201 @mock.patch('quickstart.cli.views.env_detail')
170 def test_environment_clicked(self, mock_env_detail):202 def test_environment_clicked(self, mock_env_detail):
171 # The environment detail view is called when clicking an environment.203 # The environment detail view is called when clicking an environment.
@@ -196,7 +228,9 @@
196 # The environment edit view is called when clicking to create a new228 # The environment edit view is called when clicking to create a new
197 # environment.229 # environment.
198 env_db = helpers.make_env_db()230 env_db = helpers.make_env_db()
199 views.env_index(self.app, self.env_type_db, env_db, self.save_callable)231 with local_envs_supported(True):
232 views.env_index(
233 self.app, self.env_type_db, env_db, self.save_callable)
200 buttons = self.get_widgets_in_contents(234 buttons = self.get_widgets_in_contents(
201 filter_function=self.is_a(ui.MenuButton))235 filter_function=self.is_a(ui.MenuButton))
202 env_types = envs.get_supported_env_types(self.env_type_db)236 env_types = envs.get_supported_env_types(self.env_type_db)
@@ -223,14 +257,16 @@
223 # If that option is clicked, the view quits the application returning257 # If that option is clicked, the view quits the application returning
224 # the newly created env_data.258 # the newly created env_data.
225 env_db = envs.create_empty_env_db()259 env_db = envs.create_empty_env_db()
226 views.env_index(self.app, self.env_type_db, env_db, self.save_callable)260 with local_envs_supported(True):
261 views.env_index(
262 self.app, self.env_type_db, env_db, self.save_callable)
227 buttons = self.get_widgets_in_contents(263 buttons = self.get_widgets_in_contents(
228 filter_function=self.is_a(ui.MenuButton))264 filter_function=self.is_a(ui.MenuButton))
229 # The "create and bootstrap" button is the first one in the contents.265 # The "create and bootstrap" button is the first one in the contents.
230 create_button = buttons[0]266 create_button = buttons[0]
231 self.assertEqual(267 self.assertEqual(
232 '\N{BULLET} automatically create and bootstrap a local '268 self.create_local_caption,
233 'environment', cli_helpers.get_button_caption(create_button))269 cli_helpers.get_button_caption(create_button))
234 # An AppExit is raised clicking the button.270 # An AppExit is raised clicking the button.
235 with self.assertRaises(ui.AppExit) as context_manager:271 with self.assertRaises(ui.AppExit) as context_manager:
236 cli_helpers.emit(create_button)272 cli_helpers.emit(create_button)
@@ -239,6 +275,20 @@
239 self.assertIn('local', new_env_db['environments'])275 self.assertIn('local', new_env_db['environments'])
240 self.assertEqual(envs.get_env_data(new_env_db, 'local'), env_data)276 self.assertEqual(envs.get_env_data(new_env_db, 'local'), env_data)
241277
278 def test_create_and_bootstrap_local_environment_missing(self):
279 # The option to automatically create and bootstrap a new local
280 # environment is not displayed if the current platform does not support
281 # local environments.
282 env_db = envs.create_empty_env_db()
283 with local_envs_supported(False):
284 views.env_index(
285 self.app, self.env_type_db, env_db, self.save_callable)
286 buttons = self.get_widgets_in_contents(
287 filter_function=self.is_a(ui.MenuButton))
288 # No "create and bootstrap" buttons are present.
289 captions = map(cli_helpers.get_button_caption, buttons)
290 self.assertNotIn(self.create_local_caption, captions)
291
242 def test_selected_environment(self):292 def test_selected_environment(self):
243 # The default environment is already selected in the list.293 # The default environment is already selected in the list.
244 env_db = helpers.make_env_db(default='lxc')294 env_db = helpers.make_env_db(default='lxc')
245295
=== modified file 'quickstart/tests/models/test_envs.py'
--- quickstart/tests/models/test_envs.py 2014-04-23 12:20:35 +0000
+++ quickstart/tests/models/test_envs.py 2014-06-16 12:33:53 +0000
@@ -808,9 +808,12 @@
808808
809class TestGetSupportedEnvTypes(unittest.TestCase):809class TestGetSupportedEnvTypes(unittest.TestCase):
810810
811 def setUp(self):
812 # Store the environments database.
813 self.env_type_db = envs.get_env_type_db()
814
811 def test_env_types(self):815 def test_env_types(self):
812 # All the supported env_types but the fallback one are returned.816 # All the supported env_types but the fallback one are returned.
813 env_type_db = envs.get_env_type_db()
814 expected_env_types = [817 expected_env_types = [
815 ('ec2', 'Amazon EC2'),818 ('ec2', 'Amazon EC2'),
816 ('openstack', 'OpenStack (or HP Public Cloud)'),819 ('openstack', 'OpenStack (or HP Public Cloud)'),
@@ -818,7 +821,18 @@
818 ('joyent', 'Joyent'),821 ('joyent', 'Joyent'),
819 ('local', 'local (LXC)'),822 ('local', 'local (LXC)'),
820 ]823 ]
821 obtained_env_types = envs.get_supported_env_types(env_type_db)824 obtained_env_types = envs.get_supported_env_types(self.env_type_db)
825 self.assertEqual(expected_env_types, obtained_env_types)
826
827 def test_filter_function(self):
828 # Results can be filtered by providing a filter function.
829 expected_env_types = [
830 ('ec2', 'Amazon EC2'),
831 ('joyent', 'Joyent'),
832 ]
833 func = lambda env_type, metadata: env_type in ('ec2', 'joyent')
834 obtained_env_types = envs.get_supported_env_types(
835 self.env_type_db, filter_function=func)
822 self.assertEqual(expected_env_types, obtained_env_types)836 self.assertEqual(expected_env_types, obtained_env_types)
823837
824838
825839
=== modified file 'quickstart/tests/test_manage.py'
--- quickstart/tests/test_manage.py 2014-06-13 13:47:27 +0000
+++ quickstart/tests/test_manage.py 2014-06-16 12:33:53 +0000
@@ -572,7 +572,7 @@
572 self.assertTrue(self.parser.error.called)572 self.assertTrue(self.parser.error.called)
573 message = self.parser.error.call_args[0][0]573 message = self.parser.error.call_args[0][0]
574 self.assertEqual(574 self.assertEqual(
575 'This host platform does not support local environments.',575 'this host platform does not support local environments',
576 message)576 message)
577577
578 def test_interactive_mode(self):578 def test_interactive_mode(self):

Subscribers

People subscribed via source and target branches