Merge lp:~frankban/juju-quickstart/new-juju-switch into lp:juju-quickstart

Proposed by Francesco Banconi
Status: Merged
Merged at revision: 48
Proposed branch: lp:~frankban/juju-quickstart/new-juju-switch
Merge into: lp:juju-quickstart
Diff against target: 81 lines (+23/-15)
2 files modified
quickstart/models/envs.py (+7/-4)
quickstart/tests/models/test_envs.py (+16/-11)
To merge this branch: bzr merge lp:~frankban/juju-quickstart/new-juju-switch
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+202299@code.launchpad.net

Description of the change

Support the new juju switch behavior.

Quickstart is now able to retrieve the
default environment name in newer
versions of juju-core.

Tests: `make check`.
No QA required.

https://codereview.appspot.com/54560043/

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

Reviewers: mp+202299_code.launchpad.net,

Message:
Please take a look.

Description:
Support the new juju switch behavior.

Quickstart is now able to retrieve the
default environment name in newer
versions of juju-core.

Tests: `make check`.
No QA required.

https://code.launchpad.net/~frankban/juju-quickstart/new-juju-switch/+merge/202299

(do not edit description out of merge proposal)

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

Affected files (+25, -15 lines):
   A [revision details]
   M quickstart/models/envs.py
   M quickstart/tests/models/test_envs.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/models/envs.py
=== modified file 'quickstart/models/envs.py'
--- quickstart/models/envs.py 2014-01-16 12:41:47 +0000
+++ quickstart/models/envs.py 2014-01-20 12:02:10 +0000
@@ -111,19 +111,22 @@
      env_name = os.getenv('JUJU_ENV', '').strip()
      if env_name:
          return env_name
- # XXX 2013-10-16 frankban bug=1193244:
- # Support the new behavior of juju-switch, currently under
development:
- # the command will just output the environment name, or exit with
an
- # error if no default environment is configured.
      # The "juju switch" command parses ~/.juju/current-environment file.
If the
      # environment name is not found there, then it tries to retrieve the
name
      # from the "default" section of the ~/.juju/environments.yaml file.
      retcode, output, _ = utils.call('juju', 'switch')
+ # Before juju-core 1.17, the "juju switch" command returns a human
readable
+ # output. Newer releases just output the environment name, or exit
with an
+ # error if no default environment is configured.
      if retcode:
          return None
+ # Use a regular expression to check if "juju switch" returned a human
+ # readable output.
      match = _juju_switch_expression.match(output)
      if match is not None:
          return match.groups()[0]
+ # At this point we can safely assume we are using the newer "juju
switch".
+ return output.strip()

  def create_empty_env_db():

Index: quickstart/tests/models/test_envs.py
=== modified file 'quickstart/tests/models/test_envs.py'
--- quickstart/tests/models/test_envs.py 2014-01-16 12:41:47 +0000
+++ quickstart/tests/models/test_envs.py 2014-01-20 12:02:10 +0000
@@ -58,9 +58,10 @@
                  env_name = envs.get_default_env_name()
          self.assertIsNone(env_name)

- def test_juju_switch(self):
- # The environment name is successfully returned if previously set
using
- # the "juju switch" command.
+ def test_juju_switch_old_behavior(self):
+ # The environment name is successfully returned if retrievable
using
+ # the "juju switch" command. This test exercises the old "juju
switch"
+ # returning a human readable output.
          output = 'Current e...

Read more...

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

LGTM. thank you!

(not here today, but trying to help out :-)

https://codereview.appspot.com/54560043/

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

*** Submitted:

Support the new juju switch behavior.

Quickstart is now able to retrieve the
default environment name in newer
versions of juju-core.

Tests: `make check`.
No QA required.

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

https://codereview.appspot.com/54560043/

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

Thank you for reviewing this while on holiday Gary!

https://codereview.appspot.com/54560043/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'quickstart/models/envs.py'
2--- quickstart/models/envs.py 2014-01-16 12:41:47 +0000
3+++ quickstart/models/envs.py 2014-01-20 12:04:02 +0000
4@@ -111,19 +111,22 @@
5 env_name = os.getenv('JUJU_ENV', '').strip()
6 if env_name:
7 return env_name
8- # XXX 2013-10-16 frankban bug=1193244:
9- # Support the new behavior of juju-switch, currently under development:
10- # the command will just output the environment name, or exit with an
11- # error if no default environment is configured.
12 # The "juju switch" command parses ~/.juju/current-environment file. If the
13 # environment name is not found there, then it tries to retrieve the name
14 # from the "default" section of the ~/.juju/environments.yaml file.
15 retcode, output, _ = utils.call('juju', 'switch')
16+ # Before juju-core 1.17, the "juju switch" command returns a human readable
17+ # output. Newer releases just output the environment name, or exit with an
18+ # error if no default environment is configured.
19 if retcode:
20 return None
21+ # Use a regular expression to check if "juju switch" returned a human
22+ # readable output.
23 match = _juju_switch_expression.match(output)
24 if match is not None:
25 return match.groups()[0]
26+ # At this point we can safely assume we are using the newer "juju switch".
27+ return output.strip()
28
29
30 def create_empty_env_db():
31
32=== modified file 'quickstart/tests/models/test_envs.py'
33--- quickstart/tests/models/test_envs.py 2014-01-16 12:41:47 +0000
34+++ quickstart/tests/models/test_envs.py 2014-01-20 12:04:02 +0000
35@@ -58,9 +58,10 @@
36 env_name = envs.get_default_env_name()
37 self.assertIsNone(env_name)
38
39- def test_juju_switch(self):
40- # The environment name is successfully returned if previously set using
41- # the "juju switch" command.
42+ def test_juju_switch_old_behavior(self):
43+ # The environment name is successfully returned if retrievable using
44+ # the "juju switch" command. This test exercises the old "juju switch"
45+ # returning a human readable output.
46 output = 'Current environment: "hp"\n'
47 with self.patch_call(0, output=output) as mock_call:
48 with mock.patch('os.environ', {}):
49@@ -68,6 +69,18 @@
50 self.assertEqual('hp', env_name)
51 mock_call.assert_called_once_with('juju', 'switch')
52
53+ def test_juju_switch_new_behavior(self):
54+ # The environment name is successfully returned if retrievable using
55+ # the "juju switch" command. This test exercises the new "juju switch"
56+ # returning a machine readable output (just the name of the env).
57+ # This new behavior has been introduced in juju-core 1.17.
58+ output = 'ec2\n'
59+ with self.patch_call(0, output=output) as mock_call:
60+ with mock.patch('os.environ', {}):
61+ env_name = envs.get_default_env_name()
62+ self.assertEqual('ec2', env_name)
63+ mock_call.assert_called_once_with('juju', 'switch')
64+
65 def test_juju_switch_failure(self):
66 # The environment name is not found if "juju switch" returns an error.
67 with self.patch_call(1) as mock_call:
68@@ -76,14 +89,6 @@
69 self.assertIsNone(env_name)
70 mock_call.assert_called_once_with('juju', 'switch')
71
72- def test_juju_switch_nonsense(self):
73- # The environment name is not found if "juju switch" goes crazy.
74- with self.patch_call(0, output='Exterminate!') as mock_call:
75- with mock.patch('os.environ', {}):
76- env_name = envs.get_default_env_name()
77- self.assertIsNone(env_name)
78- mock_call.assert_called_once_with('juju', 'switch')
79-
80
81 class TestCreateEmptyEnvDb(unittest.TestCase):
82

Subscribers

People subscribed via source and target branches