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
=== 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:04:02 +0000
@@ -111,19 +111,22 @@
111 env_name = os.getenv('JUJU_ENV', '').strip()111 env_name = os.getenv('JUJU_ENV', '').strip()
112 if env_name:112 if env_name:
113 return env_name113 return env_name
114 # XXX 2013-10-16 frankban bug=1193244:
115 # Support the new behavior of juju-switch, currently under development:
116 # the command will just output the environment name, or exit with an
117 # error if no default environment is configured.
118 # The "juju switch" command parses ~/.juju/current-environment file. If the114 # The "juju switch" command parses ~/.juju/current-environment file. If the
119 # environment name is not found there, then it tries to retrieve the name115 # environment name is not found there, then it tries to retrieve the name
120 # from the "default" section of the ~/.juju/environments.yaml file.116 # from the "default" section of the ~/.juju/environments.yaml file.
121 retcode, output, _ = utils.call('juju', 'switch')117 retcode, output, _ = utils.call('juju', 'switch')
118 # Before juju-core 1.17, the "juju switch" command returns a human readable
119 # output. Newer releases just output the environment name, or exit with an
120 # error if no default environment is configured.
122 if retcode:121 if retcode:
123 return None122 return None
123 # Use a regular expression to check if "juju switch" returned a human
124 # readable output.
124 match = _juju_switch_expression.match(output)125 match = _juju_switch_expression.match(output)
125 if match is not None:126 if match is not None:
126 return match.groups()[0]127 return match.groups()[0]
128 # At this point we can safely assume we are using the newer "juju switch".
129 return output.strip()
127130
128131
129def create_empty_env_db():132def create_empty_env_db():
130133
=== 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:04:02 +0000
@@ -58,9 +58,10 @@
58 env_name = envs.get_default_env_name()58 env_name = envs.get_default_env_name()
59 self.assertIsNone(env_name)59 self.assertIsNone(env_name)
6060
61 def test_juju_switch(self):61 def test_juju_switch_old_behavior(self):
62 # The environment name is successfully returned if previously set using62 # The environment name is successfully returned if retrievable using
63 # the "juju switch" command.63 # the "juju switch" command. This test exercises the old "juju switch"
64 # returning a human readable output.
64 output = 'Current environment: "hp"\n'65 output = 'Current environment: "hp"\n'
65 with self.patch_call(0, output=output) as mock_call:66 with self.patch_call(0, output=output) as mock_call:
66 with mock.patch('os.environ', {}):67 with mock.patch('os.environ', {}):
@@ -68,6 +69,18 @@
68 self.assertEqual('hp', env_name)69 self.assertEqual('hp', env_name)
69 mock_call.assert_called_once_with('juju', 'switch')70 mock_call.assert_called_once_with('juju', 'switch')
7071
72 def test_juju_switch_new_behavior(self):
73 # The environment name is successfully returned if retrievable using
74 # the "juju switch" command. This test exercises the new "juju switch"
75 # returning a machine readable output (just the name of the env).
76 # This new behavior has been introduced in juju-core 1.17.
77 output = 'ec2\n'
78 with self.patch_call(0, output=output) as mock_call:
79 with mock.patch('os.environ', {}):
80 env_name = envs.get_default_env_name()
81 self.assertEqual('ec2', env_name)
82 mock_call.assert_called_once_with('juju', 'switch')
83
71 def test_juju_switch_failure(self):84 def test_juju_switch_failure(self):
72 # The environment name is not found if "juju switch" returns an error.85 # The environment name is not found if "juju switch" returns an error.
73 with self.patch_call(1) as mock_call:86 with self.patch_call(1) as mock_call:
@@ -76,14 +89,6 @@
76 self.assertIsNone(env_name)89 self.assertIsNone(env_name)
77 mock_call.assert_called_once_with('juju', 'switch')90 mock_call.assert_called_once_with('juju', 'switch')
7891
79 def test_juju_switch_nonsense(self):
80 # The environment name is not found if "juju switch" goes crazy.
81 with self.patch_call(0, output='Exterminate!') as mock_call:
82 with mock.patch('os.environ', {}):
83 env_name = envs.get_default_env_name()
84 self.assertIsNone(env_name)
85 mock_call.assert_called_once_with('juju', 'switch')
86
8792
88class TestCreateEmptyEnvDb(unittest.TestCase):93class TestCreateEmptyEnvDb(unittest.TestCase):
8994

Subscribers

People subscribed via source and target branches