Merge lp:~hazmat/pyjuju/env-from-env into lp:pyjuju

Proposed by Kapil Thangavelu
Status: Merged
Approved by: Benjamin Saller
Approved revision: 457
Merged at revision: 476
Proposed branch: lp:~hazmat/pyjuju/env-from-env
Merge into: lp:pyjuju
Diff against target: 40 lines (+18/-1)
2 files modified
juju/control/tests/test_utils.py (+16/-0)
juju/control/utils.py (+2/-1)
To merge this branch: bzr merge lp:~hazmat/pyjuju/env-from-env
Reviewer Review Type Date Requested Status
Benjamin Saller (community) Approve
Jim Baker (community) Approve
Review via email: mp+93321@code.launchpad.net

Description of the change

Juju environment can be specified via environment variable.

The environment variable JUJU_ENV can now also be used to specify which
environment to use, this value takes precedence over the default in
environments.yaml, but is preceded by an explicit env on the cli args.

To post a comment you must log in.
Revision history for this message
Jim Baker (jimbaker) wrote :

+1, really a trivial. LGTM!

review: Approve
Revision history for this message
Benjamin Saller (bcsaller) wrote :

+1 lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'juju/control/tests/test_utils.py'
2--- juju/control/tests/test_utils.py 2011-12-02 04:35:10 +0000
3+++ juju/control/tests/test_utils.py 2012-02-15 23:35:21 +0000
4@@ -92,6 +92,22 @@
5
6 class GetEnvironmentTest(ControlToolTest):
7
8+ def test_get_environment_from_environment(self):
9+ self.change_environment(JUJU_ENV="secondenv")
10+ config = {
11+ "environments": {"firstenv": {"type": "dummy"},
12+ "secondenv": {"type": "dummy"}}}
13+ self.write_config(dump(config))
14+
15+ env_config = EnvironmentsConfig()
16+ env_config.load_or_write_sample()
17+ options = FakeOptions()
18+ options.environment = None
19+ options.environments = env_config
20+
21+ environment = get_environment(options)
22+ self.assertEqual(environment.name, "secondenv")
23+
24 def test_get_environment(self):
25 config = {
26 "environments": {"firstenv": {"type": "dummy"}}}
27
28=== modified file 'juju/control/utils.py'
29--- juju/control/utils.py 2011-12-02 00:22:55 +0000
30+++ juju/control/utils.py 2012-02-15 23:35:21 +0000
31@@ -10,7 +10,8 @@
32
33
34 def get_environment(options):
35- environment = options.environments.get(options.environment)
36+ env_name = options.environment or os.environ.get("JUJU_ENV")
37+ environment = options.environments.get(env_name)
38 if environment is None and options.environment:
39 raise EnvironmentsConfigError(
40 "Invalid environment %r" % options.environment)

Subscribers

People subscribed via source and target branches

to status/vote changes: