Merge lp:~bac/juju-quickstart/local-error-osx into lp:juju-quickstart

Proposed by Brad Crittenden
Status: Merged
Merged at revision: 75
Proposed branch: lp:~bac/juju-quickstart/local-error-osx
Merge into: lp:juju-quickstart
Diff against target: 76 lines (+29/-3)
2 files modified
quickstart/manage.py (+7/-1)
quickstart/tests/test_manage.py (+22/-2)
To merge this branch: bzr merge lp:~bac/juju-quickstart/local-error-osx
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+222562@code.launchpad.net

Description of the change

Error if local env requested but not supported.

If '-e some-local-environment' is used on a host that does not support LXC,
then bootstrap will be called and an obscure 'apt-config' error is thrown.
So, let's not do that. Instead, detect the error early and return an argparse
error that makes sense.

https://codereview.appspot.com/104940045/

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :
Download full text (4.2 KiB)

Reviewers: mp+222562_code.launchpad.net,

Message:
Please take a look.

Description:
Error if local env requested but not supported.

If '-e some-local-environment' is used on a host that does not support
LXC,
then bootstrap will be called and an obscure 'apt-config' error is
thrown.
So, let's not do that. Instead, detect the error early and return an
argparse
error that makes sense.

https://code.launchpad.net/~bac/juju-quickstart/local-error-osx/+merge/222562

(do not edit description out of merge proposal)

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

Affected files (+31, -3 lines):
   A [revision details]
   M quickstart/manage.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/manage.py
=== modified file 'quickstart/manage.py'
--- quickstart/manage.py 2014-06-02 12:56:24 +0000
+++ quickstart/manage.py 2014-06-09 19:21:43 +0000
@@ -285,11 +285,17 @@
          # This is a non-interactive session and we need to validate the
          # selected environment before proceeding.
          env_data = _retrieve_env_data(parser, env_type_db, env_db,
env_name)
+ # Check for local support, if requested.
+ options.env_type = env_data['type']
+ no_local_support = not
platform_support.supports_local(options.platform)
+ if options.env_type == 'local' and no_local_support:
+ return parser.error(
+ 'This host platform does not support local environments.'
+ )
      # Update the options namespace with the new values.
      options.admin_secret = env_data.get('admin-secret')
      options.env_file = env_file
      options.env_name = env_data['name']
- options.env_type = env_data['type']
      options.default_series = env_data.get('default-series')
      options.interactive = interactive

Index: quickstart/tests/test_manage.py
=== modified file 'quickstart/tests/test_manage.py'
--- quickstart/tests/test_manage.py 2014-06-02 12:56:24 +0000
+++ quickstart/tests/test_manage.py 2014-06-09 19:21:43 +0000
@@ -462,12 +462,14 @@
      def setUp(self):
          self.parser = mock.Mock()

- def make_options(self, env_file, env_name=None, interactive=False):
+ def make_options(self, env_file, env_name=None, interactive=False,
+ platform=settings.LINUX_APT):
          """Return a mock options object which includes the passed
arguments."""
          return mock.Mock(
              env_file=env_file,
              env_name=env_name,
              interactive=interactive,
+ platform=platform,
          )

      def patch_interactive_mode(self, return_value):
@@ -516,7 +518,7 @@
          message = self.parser.error.call_args[0][0]
          self.assertIn('unable to find an environment name to use', message)

- def test_local_provider(self):
+ def test_local_provider_linux(self):
          # Local environments are correctly handled.
     ...

Read more...

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

*** Submitted:

Error if local env requested but not supported.

If '-e some-local-environment' is used on a host that does not support
LXC,
then bootstrap will be called and an obscure 'apt-config' error is
thrown.
So, let's not do that. Instead, detect the error early and return an
argparse
error that makes sense.

R=
CC=
https://codereview.appspot.com/104940045

https://codereview.appspot.com/104940045/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'quickstart/manage.py'
--- quickstart/manage.py 2014-06-02 12:56:24 +0000
+++ quickstart/manage.py 2014-06-09 21:03:17 +0000
@@ -285,11 +285,17 @@
285 # This is a non-interactive session and we need to validate the285 # This is a non-interactive session and we need to validate the
286 # selected environment before proceeding.286 # selected environment before proceeding.
287 env_data = _retrieve_env_data(parser, env_type_db, env_db, env_name)287 env_data = _retrieve_env_data(parser, env_type_db, env_db, env_name)
288 # Check for local support, if requested.
289 options.env_type = env_data['type']
290 no_local_support = not platform_support.supports_local(options.platform)
291 if options.env_type == 'local' and no_local_support:
292 return parser.error(
293 'This host platform does not support local environments.'
294 )
288 # Update the options namespace with the new values.295 # Update the options namespace with the new values.
289 options.admin_secret = env_data.get('admin-secret')296 options.admin_secret = env_data.get('admin-secret')
290 options.env_file = env_file297 options.env_file = env_file
291 options.env_name = env_data['name']298 options.env_name = env_data['name']
292 options.env_type = env_data['type']
293 options.default_series = env_data.get('default-series')299 options.default_series = env_data.get('default-series')
294 options.interactive = interactive300 options.interactive = interactive
295301
296302
=== modified file 'quickstart/tests/test_manage.py'
--- quickstart/tests/test_manage.py 2014-06-02 12:56:24 +0000
+++ quickstart/tests/test_manage.py 2014-06-09 21:03:17 +0000
@@ -462,12 +462,14 @@
462 def setUp(self):462 def setUp(self):
463 self.parser = mock.Mock()463 self.parser = mock.Mock()
464464
465 def make_options(self, env_file, env_name=None, interactive=False):465 def make_options(self, env_file, env_name=None, interactive=False,
466 platform=settings.LINUX_APT):
466 """Return a mock options object which includes the passed arguments."""467 """Return a mock options object which includes the passed arguments."""
467 return mock.Mock(468 return mock.Mock(
468 env_file=env_file,469 env_file=env_file,
469 env_name=env_name,470 env_name=env_name,
470 interactive=interactive,471 interactive=interactive,
472 platform=platform,
471 )473 )
472474
473 def patch_interactive_mode(self, return_value):475 def patch_interactive_mode(self, return_value):
@@ -516,7 +518,7 @@
516 message = self.parser.error.call_args[0][0]518 message = self.parser.error.call_args[0][0]
517 self.assertIn('unable to find an environment name to use', message)519 self.assertIn('unable to find an environment name to use', message)
518520
519 def test_local_provider(self):521 def test_local_provider_linux(self):
520 # Local environments are correctly handled.522 # Local environments are correctly handled.
521 contents = yaml.safe_dump({523 contents = yaml.safe_dump({
522 'environments': {524 'environments': {
@@ -534,6 +536,24 @@
534 self.assertIsNone(options.default_series)536 self.assertIsNone(options.default_series)
535 self.assertFalse(options.interactive)537 self.assertFalse(options.interactive)
536538
539 def test_local_provider_not_linux(self):
540 # Local environments are correctly handled.
541 contents = yaml.safe_dump({
542 'environments': {
543 'lxc': {'admin-secret': 'Secret!', 'type': 'local'},
544 },
545 })
546 env_file = self.make_env_file(contents)
547 options = self.make_options(
548 env_file, env_name='lxc', interactive=False,
549 platform=settings.OSX)
550 manage._setup_env(options, self.parser)
551 self.assertTrue(self.parser.error.called)
552 message = self.parser.error.call_args[0][0]
553 self.assertEqual(
554 'This host platform does not support local environments.',
555 message)
556
537 def test_interactive_mode(self):557 def test_interactive_mode(self):
538 # The interactive mode is started properly if the corresponding option558 # The interactive mode is started properly if the corresponding option
539 # flag is set.559 # flag is set.

Subscribers

People subscribed via source and target branches