Merge lp:~fwereade/pyjuju/no-private-cloud-constraints into lp:~fwereade/pyjuju/constraints-compatibility

Proposed by William Reade
Status: Merged
Merged at revision: 523
Proposed branch: lp:~fwereade/pyjuju/no-private-cloud-constraints
Merge into: lp:~fwereade/pyjuju/constraints-compatibility
Diff against target: 176 lines (+64/-14)
7 files modified
juju/providers/ec2/__init__.py (+1/-2)
juju/providers/ec2/launch.py (+1/-1)
juju/providers/ec2/tests/common.py (+7/-6)
juju/providers/ec2/tests/test_launch.py (+29/-0)
juju/providers/ec2/tests/test_provider.py (+1/-3)
juju/providers/ec2/tests/test_utils.py (+22/-1)
juju/providers/ec2/utils.py (+3/-1)
To merge this branch: bzr merge lp:~fwereade/pyjuju/no-private-cloud-constraints
Reviewer Review Type Date Requested Status
William Reade Pending
Review via email: mp+101592@code.launchpad.net

Description of the change

Disable constraints on private clouds

Private clouds (defined as those with an ec2-uri config setting) now expose
no constraints at all; everything in the ec2 provider that uses constraints
now knows not to assume that any keys are present other than provider-type
and ubuntu-series.

https://codereview.appspot.com/6003046/

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

Reviewers: mp+101592_code.launchpad.net,

Message:
Please take a look.

Description:
Disable constraints on private clouds

Private clouds (defined as those with an ec2-uri config setting) now
expose
no constraints at all; everything in the ec2 provider that uses
constraints
now knows not to assume that any keys are present other than
provider-type
and ubuntu-series.

https://code.launchpad.net/~fwereade/juju/no-private-cloud-constraints/+merge/101592

(do not edit description out of merge proposal)

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

Affected files:
   A [revision details]
   M juju/providers/ec2/__init__.py
   M juju/providers/ec2/launch.py
   M juju/providers/ec2/tests/common.py
   M juju/providers/ec2/tests/test_launch.py
   M juju/providers/ec2/tests/test_provider.py
   M juju/providers/ec2/tests/test_utils.py
   M juju/providers/ec2/utils.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/providers/ec2/__init__.py
=== modified file 'juju/providers/ec2/__init__.py'
--- juju/providers/ec2/__init__.py 2012-04-11 00:09:41 +0000
+++ juju/providers/ec2/__init__.py 2012-04-11 15:47:12 +0000
@@ -74,8 +74,7 @@
      def get_constraint_set(self):
          """Return the set of constraints that are valid for this
provider."""
          cs = yield super(MachineProvider, self).get_constraint_set()
- if 1: # These keys still need to be valid (instance-type and
ec2-zone)
- #if self.using_amazon:
+ if self.using_amazon:
              # Expose EC2 instance types/zones on AWS itelf, not private
clouds.
              cs.register_generics(INSTANCE_TYPES.keys())
              cs.register("ec2-zone", converter=convert_zone)

Index: juju/providers/ec2/launch.py
=== modified file 'juju/providers/ec2/launch.py'
--- juju/providers/ec2/launch.py 2012-03-27 22:46:44 +0000
+++ juju/providers/ec2/launch.py 2012-04-11 15:47:12 +0000
@@ -34,7 +34,7 @@
              "$(curl http://169.254.169.254/1.0/meta-data/instance-id)")
          user_data = cloud_init.render()

- availability_zone = self._constraints["ec2-zone"]
+ availability_zone = self._constraints.get("ec2-zone")
          if availability_zone is not None:
              region = self._provider.config.get("region", DEFAULT_REGION)
              availability_zone = region + availability_zone

Index: juju/providers/ec2/tests/common.py
=== modified file 'juju/providers/ec2/tests/common.py'
--- juju/providers/ec2/tests/common.py 2012-04-11 00:09:41 +0000
+++ juju/providers/ec2/tests/common.py 2012-04-11 15:47:12 +0000
@@ -101,12 +101,13 @@
          get_public_key(MATCH(match_config))
          self.mocker.result("zebra")

- get_ami_args = get_ami_args or (
- "splendid", "amd64", "us-east-1", False, False)
- get_ami = self.mocker.replace(
- "juju.providers.ec2.utils.get_current_ami")
- get_ami(*get_ami_args)
- self.mocker.r...

Read more...

Revision history for this message
Kapil Thangavelu (hazmat) wrote :

unfortunate but nesc. lgtm.

https://codereview.appspot.com/6003046/

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

*** Submitted:

Disable constraints on private clouds

Private clouds (defined as those with an ec2-uri config setting) now
expose
no constraints at all; everything in the ec2 provider that uses
constraints
now knows not to assume that any keys are present other than
provider-type
and ubuntu-series.

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

https://codereview.appspot.com/6003046/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'juju/providers/ec2/__init__.py'
--- juju/providers/ec2/__init__.py 2012-04-11 00:09:41 +0000
+++ juju/providers/ec2/__init__.py 2012-04-11 15:55:30 +0000
@@ -74,8 +74,7 @@
74 def get_constraint_set(self):74 def get_constraint_set(self):
75 """Return the set of constraints that are valid for this provider."""75 """Return the set of constraints that are valid for this provider."""
76 cs = yield super(MachineProvider, self).get_constraint_set()76 cs = yield super(MachineProvider, self).get_constraint_set()
77 if 1: # These keys still need to be valid (instance-type and ec2-zone)77 if self.using_amazon:
78 #if self.using_amazon:
79 # Expose EC2 instance types/zones on AWS itelf, not private clouds.78 # Expose EC2 instance types/zones on AWS itelf, not private clouds.
80 cs.register_generics(INSTANCE_TYPES.keys())79 cs.register_generics(INSTANCE_TYPES.keys())
81 cs.register("ec2-zone", converter=convert_zone)80 cs.register("ec2-zone", converter=convert_zone)
8281
=== modified file 'juju/providers/ec2/launch.py'
--- juju/providers/ec2/launch.py 2012-03-27 22:46:44 +0000
+++ juju/providers/ec2/launch.py 2012-04-11 15:55:30 +0000
@@ -34,7 +34,7 @@
34 "$(curl http://169.254.169.254/1.0/meta-data/instance-id)")34 "$(curl http://169.254.169.254/1.0/meta-data/instance-id)")
35 user_data = cloud_init.render()35 user_data = cloud_init.render()
3636
37 availability_zone = self._constraints["ec2-zone"]37 availability_zone = self._constraints.get("ec2-zone")
38 if availability_zone is not None:38 if availability_zone is not None:
39 region = self._provider.config.get("region", DEFAULT_REGION)39 region = self._provider.config.get("region", DEFAULT_REGION)
40 availability_zone = region + availability_zone40 availability_zone = region + availability_zone
4141
=== modified file 'juju/providers/ec2/tests/common.py'
--- juju/providers/ec2/tests/common.py 2012-04-11 00:09:41 +0000
+++ juju/providers/ec2/tests/common.py 2012-04-11 15:55:30 +0000
@@ -101,12 +101,13 @@
101 get_public_key(MATCH(match_config))101 get_public_key(MATCH(match_config))
102 self.mocker.result("zebra")102 self.mocker.result("zebra")
103103
104 get_ami_args = get_ami_args or (104 if get_ami_args is not None:
105 "splendid", "amd64", "us-east-1", False, False)105 get_ami_args = get_ami_args or (
106 get_ami = self.mocker.replace(106 "splendid", "amd64", "us-east-1", False, False)
107 "juju.providers.ec2.utils.get_current_ami")107 get_ami = self.mocker.replace(
108 get_ami(*get_ami_args)108 "juju.providers.ec2.utils.get_current_ami")
109 self.mocker.result(succeed(ami_name))109 get_ami(*get_ami_args)
110 self.mocker.result(succeed(ami_name))
110111
111 def _mock_create_group(self):112 def _mock_create_group(self):
112 group_name = "juju-%s" % self.env_name113 group_name = "juju-%s" % self.env_name
113114
=== modified file 'juju/providers/ec2/tests/test_launch.py'
--- juju/providers/ec2/tests/test_launch.py 2012-04-11 00:18:49 +0000
+++ juju/providers/ec2/tests/test_launch.py 2012-04-11 15:55:30 +0000
@@ -88,6 +88,35 @@
88 d.addCallback(verify_result)88 d.addCallback(verify_result)
89 return d89 return d
9090
91 def test_provider_launch_private_cloud_constraints(self):
92 """
93 When running on a private cloud (ie when the provider registers no
94 constraints) we should only require default-image-id in config, and
95 fall back to an instance-type of m1.small if default-instance-type is
96 not present.
97 """
98 self.ec2.describe_security_groups()
99 self.mocker.result(succeed([]))
100 self._mock_create_group()
101 self._mock_create_machine_group("1")
102 self._mock_launch_utils(get_ami_args=None)
103 self._mock_get_zookeeper_hosts()
104 self._mock_launch(self.get_instance("i-foobar"), "ami-tango")
105 self.mocker.replay()
106
107 def verify_result(result):
108 (machine,) = result
109 self.assert_machine(machine, "i-foobar", "")
110 provider = self.get_provider()
111 provider.config["default-image-id"] = "ami-tango"
112 d = provider.start_machine({
113 "machine-id": "1",
114 "constraints": {
115 "provider-type": "ec2",
116 "ubuntu-series": "splendid"}})
117 d.addCallback(verify_result)
118 return d
119
91 @inlineCallbacks120 @inlineCallbacks
92 def test_provider_launch_requires_constraints(self):121 def test_provider_launch_requires_constraints(self):
93 self.mocker.replay()122 self.mocker.replay()
94123
=== modified file 'juju/providers/ec2/tests/test_provider.py'
--- juju/providers/ec2/tests/test_provider.py 2012-04-11 00:18:49 +0000
+++ juju/providers/ec2/tests/test_provider.py 2012-04-11 15:55:30 +0000
@@ -254,9 +254,7 @@
254 self.assertFalse(b.can_satisfy(a))254 self.assertFalse(b.can_satisfy(a))
255255
256 @inlineCallbacks256 @inlineCallbacks
257 def xtest_non_amazon_constraints(self):257 def test_non_amazon_constraints(self):
258 # Disabled because the ec2 provider requires these keys (instance-type
259 # and ec2-zone)
260 provider = MachineProvider("some-non-ec2-env", {258 provider = MachineProvider("some-non-ec2-env", {
261 "ec2-uri": "blah", "secret-key": "foobar", "access-key": "bar"})259 "ec2-uri": "blah", "secret-key": "foobar", "access-key": "bar"})
262 cs = yield provider.get_constraint_set()260 cs = yield provider.get_constraint_set()
263261
=== modified file 'juju/providers/ec2/tests/test_utils.py'
--- juju/providers/ec2/tests/test_utils.py 2012-04-11 08:19:44 +0000
+++ juju/providers/ec2/tests/test_utils.py 2012-04-11 15:55:30 +0000
@@ -4,7 +4,7 @@
4from twisted.internet.defer import fail, succeed, inlineCallbacks4from twisted.internet.defer import fail, succeed, inlineCallbacks
5from twisted.web.error import Error5from twisted.web.error import Error
66
7from juju.errors import ProviderError7from juju.errors import ProviderError, UnknownConstraintError
8from juju.lib.testing import TestCase8from juju.lib.testing import TestCase
9from juju.lib.mocker import MATCH9from juju.lib.mocker import MATCH
10from juju.providers import ec210from juju.providers import ec2
@@ -13,6 +13,7 @@
1313
14from .common import get_constraints14from .common import get_constraints
1515
16from juju.providers.ec2 import MachineProvider
16from juju.providers.ec2.utils import VerifyingContextFactory17from juju.providers.ec2.utils import VerifyingContextFactory
1718
1819
@@ -275,7 +276,27 @@
275276
276 @inlineCallbacks277 @inlineCallbacks
277 def test_config_override(self):278 def test_config_override(self):
279 """If config contains default-instance-type, that should always be used
280 regardless of constraints (it's only a valid key when in legacy
281 deployments, in which constraint entry is disabled, or on private
282 clouds (which themselves register no constraints))."""
278 constraints = yield get_constraints([])283 constraints = yield get_constraints([])
279 instance_type = get_instance_type(284 instance_type = get_instance_type(
280 {"default-instance-type": "whatever-they-typed"}, constraints)285 {"default-instance-type": "whatever-they-typed"}, constraints)
281 self.assertEquals(instance_type, "whatever-they-typed")286 self.assertEquals(instance_type, "whatever-they-typed")
287
288 @inlineCallbacks
289 def test_config_fallback(self):
290 """In a private cloud, a missing default-instance-id should fall back
291 to m1.small."""
292 provider = MachineProvider("", {
293 "access-key": "foo", "secret-key": "bar",
294 "ec2-uri": "http://example.com"})
295 cs = yield provider.get_constraint_set()
296
297 # Verify that this is indeed a ConstraintSet without instance-type
298 self.assertRaises(
299 UnknownConstraintError, cs.parse, ["instance-type=c1.medium"])
300 constraints = cs.parse([])
301 instance_type = get_instance_type({}, constraints)
302 self.assertEquals(instance_type, "m1.small")
282303
=== modified file 'juju/providers/ec2/utils.py'
--- juju/providers/ec2/utils.py 2012-04-11 08:36:43 +0000
+++ juju/providers/ec2/utils.py 2012-04-11 15:55:30 +0000
@@ -143,6 +143,8 @@
143 instance_type = config.get("default-instance-type")143 instance_type = config.get("default-instance-type")
144 if instance_type is not None:144 if instance_type is not None:
145 return instance_type145 return instance_type
146 if "instance-type" not in constraints:
147 return "m1.small"
146 instance_type = constraints["instance-type"]148 instance_type = constraints["instance-type"]
147 if instance_type is not None:149 if instance_type is not None:
148 return instance_type150 return instance_type
@@ -161,7 +163,7 @@
161 image_id = config.get("default-image-id")163 image_id = config.get("default-image-id")
162 if image_id is None:164 if image_id is None:
163 series = constraints["ubuntu-series"] or config["default-series"]165 series = constraints["ubuntu-series"] or config["default-series"]
164 arch = constraints["arch"] or "amd64"166 arch = constraints.get("arch") or "amd64"
165 region = config.get("region", DEFAULT_REGION)167 region = config.get("region", DEFAULT_REGION)
166 hvm = INSTANCE_TYPES[instance_type].hvm168 hvm = INSTANCE_TYPES[instance_type].hvm
167 ssl_verify = config.get("ssl-hostname-verification", False)169 ssl_verify = config.get("ssl-hostname-verification", False)

Subscribers

People subscribed via source and target branches

to all changes: