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
1=== modified file 'juju/providers/ec2/__init__.py'
2--- juju/providers/ec2/__init__.py 2012-04-11 00:09:41 +0000
3+++ juju/providers/ec2/__init__.py 2012-04-11 15:55:30 +0000
4@@ -74,8 +74,7 @@
5 def get_constraint_set(self):
6 """Return the set of constraints that are valid for this provider."""
7 cs = yield super(MachineProvider, self).get_constraint_set()
8- if 1: # These keys still need to be valid (instance-type and ec2-zone)
9- #if self.using_amazon:
10+ if self.using_amazon:
11 # Expose EC2 instance types/zones on AWS itelf, not private clouds.
12 cs.register_generics(INSTANCE_TYPES.keys())
13 cs.register("ec2-zone", converter=convert_zone)
14
15=== modified file 'juju/providers/ec2/launch.py'
16--- juju/providers/ec2/launch.py 2012-03-27 22:46:44 +0000
17+++ juju/providers/ec2/launch.py 2012-04-11 15:55:30 +0000
18@@ -34,7 +34,7 @@
19 "$(curl http://169.254.169.254/1.0/meta-data/instance-id)")
20 user_data = cloud_init.render()
21
22- availability_zone = self._constraints["ec2-zone"]
23+ availability_zone = self._constraints.get("ec2-zone")
24 if availability_zone is not None:
25 region = self._provider.config.get("region", DEFAULT_REGION)
26 availability_zone = region + availability_zone
27
28=== modified file 'juju/providers/ec2/tests/common.py'
29--- juju/providers/ec2/tests/common.py 2012-04-11 00:09:41 +0000
30+++ juju/providers/ec2/tests/common.py 2012-04-11 15:55:30 +0000
31@@ -101,12 +101,13 @@
32 get_public_key(MATCH(match_config))
33 self.mocker.result("zebra")
34
35- get_ami_args = get_ami_args or (
36- "splendid", "amd64", "us-east-1", False, False)
37- get_ami = self.mocker.replace(
38- "juju.providers.ec2.utils.get_current_ami")
39- get_ami(*get_ami_args)
40- self.mocker.result(succeed(ami_name))
41+ if get_ami_args is not None:
42+ get_ami_args = get_ami_args or (
43+ "splendid", "amd64", "us-east-1", False, False)
44+ get_ami = self.mocker.replace(
45+ "juju.providers.ec2.utils.get_current_ami")
46+ get_ami(*get_ami_args)
47+ self.mocker.result(succeed(ami_name))
48
49 def _mock_create_group(self):
50 group_name = "juju-%s" % self.env_name
51
52=== modified file 'juju/providers/ec2/tests/test_launch.py'
53--- juju/providers/ec2/tests/test_launch.py 2012-04-11 00:18:49 +0000
54+++ juju/providers/ec2/tests/test_launch.py 2012-04-11 15:55:30 +0000
55@@ -88,6 +88,35 @@
56 d.addCallback(verify_result)
57 return d
58
59+ def test_provider_launch_private_cloud_constraints(self):
60+ """
61+ When running on a private cloud (ie when the provider registers no
62+ constraints) we should only require default-image-id in config, and
63+ fall back to an instance-type of m1.small if default-instance-type is
64+ not present.
65+ """
66+ self.ec2.describe_security_groups()
67+ self.mocker.result(succeed([]))
68+ self._mock_create_group()
69+ self._mock_create_machine_group("1")
70+ self._mock_launch_utils(get_ami_args=None)
71+ self._mock_get_zookeeper_hosts()
72+ self._mock_launch(self.get_instance("i-foobar"), "ami-tango")
73+ self.mocker.replay()
74+
75+ def verify_result(result):
76+ (machine,) = result
77+ self.assert_machine(machine, "i-foobar", "")
78+ provider = self.get_provider()
79+ provider.config["default-image-id"] = "ami-tango"
80+ d = provider.start_machine({
81+ "machine-id": "1",
82+ "constraints": {
83+ "provider-type": "ec2",
84+ "ubuntu-series": "splendid"}})
85+ d.addCallback(verify_result)
86+ return d
87+
88 @inlineCallbacks
89 def test_provider_launch_requires_constraints(self):
90 self.mocker.replay()
91
92=== modified file 'juju/providers/ec2/tests/test_provider.py'
93--- juju/providers/ec2/tests/test_provider.py 2012-04-11 00:18:49 +0000
94+++ juju/providers/ec2/tests/test_provider.py 2012-04-11 15:55:30 +0000
95@@ -254,9 +254,7 @@
96 self.assertFalse(b.can_satisfy(a))
97
98 @inlineCallbacks
99- def xtest_non_amazon_constraints(self):
100- # Disabled because the ec2 provider requires these keys (instance-type
101- # and ec2-zone)
102+ def test_non_amazon_constraints(self):
103 provider = MachineProvider("some-non-ec2-env", {
104 "ec2-uri": "blah", "secret-key": "foobar", "access-key": "bar"})
105 cs = yield provider.get_constraint_set()
106
107=== modified file 'juju/providers/ec2/tests/test_utils.py'
108--- juju/providers/ec2/tests/test_utils.py 2012-04-11 08:19:44 +0000
109+++ juju/providers/ec2/tests/test_utils.py 2012-04-11 15:55:30 +0000
110@@ -4,7 +4,7 @@
111 from twisted.internet.defer import fail, succeed, inlineCallbacks
112 from twisted.web.error import Error
113
114-from juju.errors import ProviderError
115+from juju.errors import ProviderError, UnknownConstraintError
116 from juju.lib.testing import TestCase
117 from juju.lib.mocker import MATCH
118 from juju.providers import ec2
119@@ -13,6 +13,7 @@
120
121 from .common import get_constraints
122
123+from juju.providers.ec2 import MachineProvider
124 from juju.providers.ec2.utils import VerifyingContextFactory
125
126
127@@ -275,7 +276,27 @@
128
129 @inlineCallbacks
130 def test_config_override(self):
131+ """If config contains default-instance-type, that should always be used
132+ regardless of constraints (it's only a valid key when in legacy
133+ deployments, in which constraint entry is disabled, or on private
134+ clouds (which themselves register no constraints))."""
135 constraints = yield get_constraints([])
136 instance_type = get_instance_type(
137 {"default-instance-type": "whatever-they-typed"}, constraints)
138 self.assertEquals(instance_type, "whatever-they-typed")
139+
140+ @inlineCallbacks
141+ def test_config_fallback(self):
142+ """In a private cloud, a missing default-instance-id should fall back
143+ to m1.small."""
144+ provider = MachineProvider("", {
145+ "access-key": "foo", "secret-key": "bar",
146+ "ec2-uri": "http://example.com"})
147+ cs = yield provider.get_constraint_set()
148+
149+ # Verify that this is indeed a ConstraintSet without instance-type
150+ self.assertRaises(
151+ UnknownConstraintError, cs.parse, ["instance-type=c1.medium"])
152+ constraints = cs.parse([])
153+ instance_type = get_instance_type({}, constraints)
154+ self.assertEquals(instance_type, "m1.small")
155
156=== modified file 'juju/providers/ec2/utils.py'
157--- juju/providers/ec2/utils.py 2012-04-11 08:36:43 +0000
158+++ juju/providers/ec2/utils.py 2012-04-11 15:55:30 +0000
159@@ -143,6 +143,8 @@
160 instance_type = config.get("default-instance-type")
161 if instance_type is not None:
162 return instance_type
163+ if "instance-type" not in constraints:
164+ return "m1.small"
165 instance_type = constraints["instance-type"]
166 if instance_type is not None:
167 return instance_type
168@@ -161,7 +163,7 @@
169 image_id = config.get("default-image-id")
170 if image_id is None:
171 series = constraints["ubuntu-series"] or config["default-series"]
172- arch = constraints["arch"] or "amd64"
173+ arch = constraints.get("arch") or "amd64"
174 region = config.get("region", DEFAULT_REGION)
175 hvm = INSTANCE_TYPES[instance_type].hvm
176 ssl_verify = config.get("ssl-hostname-verification", False)

Subscribers

People subscribed via source and target branches

to all changes: