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
1=== modified file 'quickstart/manage.py'
2--- quickstart/manage.py 2014-06-02 12:56:24 +0000
3+++ quickstart/manage.py 2014-06-09 21:03:17 +0000
4@@ -285,11 +285,17 @@
5 # This is a non-interactive session and we need to validate the
6 # selected environment before proceeding.
7 env_data = _retrieve_env_data(parser, env_type_db, env_db, env_name)
8+ # Check for local support, if requested.
9+ options.env_type = env_data['type']
10+ no_local_support = not platform_support.supports_local(options.platform)
11+ if options.env_type == 'local' and no_local_support:
12+ return parser.error(
13+ 'This host platform does not support local environments.'
14+ )
15 # Update the options namespace with the new values.
16 options.admin_secret = env_data.get('admin-secret')
17 options.env_file = env_file
18 options.env_name = env_data['name']
19- options.env_type = env_data['type']
20 options.default_series = env_data.get('default-series')
21 options.interactive = interactive
22
23
24=== modified file 'quickstart/tests/test_manage.py'
25--- quickstart/tests/test_manage.py 2014-06-02 12:56:24 +0000
26+++ quickstart/tests/test_manage.py 2014-06-09 21:03:17 +0000
27@@ -462,12 +462,14 @@
28 def setUp(self):
29 self.parser = mock.Mock()
30
31- def make_options(self, env_file, env_name=None, interactive=False):
32+ def make_options(self, env_file, env_name=None, interactive=False,
33+ platform=settings.LINUX_APT):
34 """Return a mock options object which includes the passed arguments."""
35 return mock.Mock(
36 env_file=env_file,
37 env_name=env_name,
38 interactive=interactive,
39+ platform=platform,
40 )
41
42 def patch_interactive_mode(self, return_value):
43@@ -516,7 +518,7 @@
44 message = self.parser.error.call_args[0][0]
45 self.assertIn('unable to find an environment name to use', message)
46
47- def test_local_provider(self):
48+ def test_local_provider_linux(self):
49 # Local environments are correctly handled.
50 contents = yaml.safe_dump({
51 'environments': {
52@@ -534,6 +536,24 @@
53 self.assertIsNone(options.default_series)
54 self.assertFalse(options.interactive)
55
56+ def test_local_provider_not_linux(self):
57+ # Local environments are correctly handled.
58+ contents = yaml.safe_dump({
59+ 'environments': {
60+ 'lxc': {'admin-secret': 'Secret!', 'type': 'local'},
61+ },
62+ })
63+ env_file = self.make_env_file(contents)
64+ options = self.make_options(
65+ env_file, env_name='lxc', interactive=False,
66+ platform=settings.OSX)
67+ manage._setup_env(options, self.parser)
68+ self.assertTrue(self.parser.error.called)
69+ message = self.parser.error.call_args[0][0]
70+ self.assertEqual(
71+ 'This host platform does not support local environments.',
72+ message)
73+
74 def test_interactive_mode(self):
75 # The interactive mode is started properly if the corresponding option
76 # flag is set.

Subscribers

People subscribed via source and target branches