Merge lp:~fwereade/pyjuju/block-legacy-constraints-usage into lp:~fwereade/pyjuju/shadow-trunk-1204

Proposed by William Reade
Status: Merged
Approved by: William Reade
Approved revision: 518
Merged at revision: 513
Proposed branch: lp:~fwereade/pyjuju/block-legacy-constraints-usage
Merge into: lp:~fwereade/pyjuju/shadow-trunk-1204
Prerequisite: lp:~fwereade/pyjuju/env-constraints
Diff against target: 125 lines (+54/-1)
5 files modified
juju/control/constraints_set.py (+4/-1)
juju/control/deploy.py (+1/-0)
juju/control/legacy.py (+15/-0)
juju/control/tests/test_constraints_set.py (+13/-0)
juju/control/tests/test_deploy.py (+21/-0)
To merge this branch: bzr merge lp:~fwereade/pyjuju/block-legacy-constraints-usage
Reviewer Review Type Date Requested Status
William Reade Pending
Review via email: mp+99856@code.launchpad.net

Description of the change

Block set-constraints, and deploy --constraints, in legacy deployments

https://codereview.appspot.com/5952045/

To post a comment you must log in.
Revision history for this message
William Reade (fwereade) wrote :
Download full text (6.1 KiB)

Reviewers: mp+99856_code.launchpad.net,

Message:
Please take a look.

Description:
Block set-constraints, and deploy --constraints, in legacy deployments

https://code.launchpad.net/~fwereade/juju/block-legacy-constraints-usage/+merge/99856

Requires:
https://code.launchpad.net/~fwereade/juju/env-constraints/+merge/99852

(do not edit description out of merge proposal)

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

Affected files:
   A [revision details]
   M juju/control/constraints_set.py
   M juju/control/deploy.py
   M juju/control/legacy.py
   M juju/control/tests/test_constraints_set.py
   M juju/control/tests/test_deploy.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: juju/control/constraints_set.py
=== modified file 'juju/control/constraints_set.py'
--- juju/control/constraints_set.py 2012-03-29 02:00:04 +0000
+++ juju/control/constraints_set.py 2012-03-29 03:20:51 +0000
@@ -2,6 +2,7 @@

  from twisted.internet.defer import inlineCallbacks

+from juju.control import legacy
  from juju.control.utils import get_environment
  from juju.state.environment import EnvironmentStateManager
  from juju.state.service import ServiceStateManager
@@ -35,11 +36,13 @@
      """
      environment = get_environment(options)
      return constraints_set(
- options.environments, environment, options.service,
options.constraints)
+ options.environments, environment, options.service,
+ options.constraints, options.log)

  @inlineCallbacks
-def constraints_set(env_config, environment, service_name,
constraint_strs):
+def constraints_set(env_config, environment, service_name, constraint_strs,
+ log):
      """
      Machine constraints allow you to pick the hardware to which your
services
      will be deployed. Examples:
@@ -86,6 +89,7 @@
      constraints = constraint_set.parse(constraint_strs)
      client = yield provider.connect()
      try:
+ yield legacy.check_constraints(client, constraint_strs)
          esm = EnvironmentStateManager(client)
          yield esm.set_config_state(env_config, environment.name)
          if service_name is None:

Index: juju/control/deploy.py
=== modified file 'juju/control/deploy.py'
--- juju/control/deploy.py 2012-03-29 01:37:57 +0000
+++ juju/control/deploy.py 2012-03-29 03:20:51 +0000
@@ -138,6 +138,7 @@
      client = yield provider.connect()

      try:
+ yield legacy.check_constraints(client, constraint_strs)
          yield legacy.check_environment(
              client, provider.get_legacy_config_keys())

Index: juju/control/legacy.py
=== modified file 'juju/control/legacy.py'
--- juju/control/legacy.py 2012-03-28 19:48:24 +0000
+++ juju/control/legacy.py 2012-03-29 03:20:51 +0000
@@ -1,8 +1,19 @@
+import logging
+import sys
+
  from twisted.internet.defer import inlineCallbacks

  from juju.errors import JujuError
  from juju.state.environment import Environm...

Read more...

Revision history for this message
William Reade (fwereade) wrote :
516. By William Reade

code tidying after post-sleep self-review

517. By William Reade

merge parent

Revision history for this message
Kapil Thangavelu (hazmat) wrote :
518. By William Reade

merge parent

Revision history for this message
William Reade (fwereade) wrote :

*** Submitted:

Block set-constraints, and deploy --constraints, in legacy deployments

R=hazmat
CC=
https://codereview.appspot.com/5952045

https://codereview.appspot.com/5952045/

519. By William Reade

merge parent

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'juju/control/constraints_set.py'
2--- juju/control/constraints_set.py 2012-03-30 08:41:34 +0000
3+++ juju/control/constraints_set.py 2012-03-30 08:41:34 +0000
4@@ -2,6 +2,7 @@
5
6 from twisted.internet.defer import inlineCallbacks
7
8+from juju.control import legacy
9 from juju.control.utils import get_environment
10 from juju.state.environment import EnvironmentStateManager
11 from juju.state.service import ServiceStateManager
12@@ -34,8 +35,9 @@
13 """Set machine constraints for the environment, or for a named service.
14 """
15 environment = get_environment(options)
16+ env_config = options.environments
17 return constraints_set(
18- options.environments, environment, options.service, options.constraints)
19+ env_config, environment, options.service, options.constraints)
20
21
22 @inlineCallbacks
23@@ -86,6 +88,7 @@
24 constraints = constraint_set.parse(constraint_strs)
25 client = yield provider.connect()
26 try:
27+ yield legacy.check_constraints(client, constraint_strs)
28 esm = EnvironmentStateManager(client)
29 yield esm.set_config_state(env_config, environment.name)
30 if service_name is None:
31
32=== modified file 'juju/control/deploy.py'
33--- juju/control/deploy.py 2012-03-30 08:41:34 +0000
34+++ juju/control/deploy.py 2012-03-30 08:41:34 +0000
35@@ -138,6 +138,7 @@
36 client = yield provider.connect()
37
38 try:
39+ yield legacy.check_constraints(client, constraint_strs)
40 yield legacy.check_environment(
41 client, provider.get_legacy_config_keys())
42
43
44=== modified file 'juju/control/legacy.py'
45--- juju/control/legacy.py 2012-03-28 19:48:24 +0000
46+++ juju/control/legacy.py 2012-03-30 08:41:34 +0000
47@@ -14,9 +14,11 @@
48 https://juju.ubuntu.com/DeprecatedEnvironmentSettings
49 """
50
51+
52 def error(keys):
53 raise JujuError(_ERROR % "\n ".join(sorted(keys)))
54
55+
56 @inlineCallbacks
57 def check_environment(client, keys):
58 if not keys:
59@@ -24,3 +26,16 @@
60 esm = EnvironmentStateManager(client)
61 if not (yield esm.get_in_legacy_environment()):
62 error(keys)
63+
64+
65+@inlineCallbacks
66+def check_constraints(client, constraint_strs):
67+ if not constraint_strs:
68+ return
69+ esm = EnvironmentStateManager(client)
70+ if (yield esm.get_in_legacy_environment()):
71+ raise JujuError(
72+ "Constraints are not valid in legacy deployments. To use machine "
73+ "constraints, please deploy your environment again from scratch. "
74+ "You can continue to use this environment as before, but any "
75+ "attempt to set constraints will fail.")
76
77=== modified file 'juju/control/tests/test_constraints_set.py'
78--- juju/control/tests/test_constraints_set.py 2012-03-30 08:41:34 +0000
79+++ juju/control/tests/test_constraints_set.py 2012-03-30 08:41:34 +0000
80@@ -62,3 +62,16 @@
81 "arch": "arm",
82 "cpu": None,
83 "mem": 512.0})
84+
85+ @inlineCallbacks
86+ def test_legacy_environment(self):
87+ yield self.client.delete("/constraints")
88+ finished = self.setup_cli_reactor()
89+ self.setup_exit(0)
90+ self.mocker.replay()
91+ main(["set-constraints", "arch=arm", "cpu=any"])
92+ yield finished
93+
94+ self.assertIn(
95+ "Constraints are not valid in legacy deployments.",
96+ self.stderr.getvalue())
97
98=== modified file 'juju/control/tests/test_deploy.py'
99--- juju/control/tests/test_deploy.py 2012-03-30 08:41:34 +0000
100+++ juju/control/tests/test_deploy.py 2012-03-30 08:41:34 +0000
101@@ -546,3 +546,24 @@
102 yield self.assertFailure(
103 service_manager.get_service_state("beekeeper"),
104 ServiceStateNotFound)
105+
106+ @inlineCallbacks
107+ def test_deploy_constraints_in_legacy_env(self):
108+ yield self.client.delete("/constraints")
109+
110+ finished = self.setup_cli_reactor()
111+ self.setup_exit(0)
112+ self.mocker.replay()
113+ stderr = self.capture_stream("stderr")
114+
115+ main(["deploy", "--repository", self.unbundled_repo_path,
116+ "local:sample", "beekeeper", "--constraints", "arch=i386"])
117+ yield finished
118+
119+ self.assertIn(
120+ "Constraints are not valid in legacy deployments.",
121+ stderr.getvalue())
122+ service_manager = ServiceStateManager(self.client)
123+ yield self.assertFailure(
124+ service_manager.get_service_state("beekeeper"),
125+ ServiceStateNotFound)

Subscribers

People subscribed via source and target branches

to all changes: