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.
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: 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)
- 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
+ def test_provider_launch_private_cloud_constraints(self):
+ """
+ When running on a private cloud (ie when the provider registers no
+ constraints) we should only require default-image-id in config, and
+ fall back to an instance-type of m1.small if default-instance-type
is
+ not present.
+ """
+ self.ec2.describe_security_groups()
+ self.mocker.result(succeed([]))
+ self._mock_create_group()
+ self._mock_create_machine_group("1")
+ self._mock_launch_utils(get_ami_args=None)
+ self._mock_get_zookeeper_hosts()
+ self._mock_launch(self.get_instance("i-foobar"), "ami-tango")
+ self.mocker.replay()
+
+ def verify_result(result):
+ (machine,) = result
+ self.assert_machine(machine, "i-foobar", "")
+ provider = self.get_provider()
+ provider.config["default-image-id"] = "ami-tango"
+ d = provider.start_machine({
+ "machine-id": "1",
+ "constraints": {
+ "provider-type": "ec2",
+ "ubuntu-series": "splendid"}})
+ d.addCallback(verify_result)
+ return d
+
@inlineCallbacks
def test_provider_launch_requires_constraints(self): self.mocker.replay()
-from juju.errors import ProviderError
+from juju.errors import ProviderError, UnknownConstraintError
from juju.lib.testing import TestCase
from juju.lib.mocker import MATCH
from juju.providers import ec2
@@ -13,6 +13,7 @@
from .common import get_constraints
+from juju.providers.ec2 import MachineProvider
from juju.providers.ec2.utils import VerifyingContextFactory
@@ -275,7 +276,27 @@
@inlineCallbacks
def test_config_override(self):
+ """If config contains default-instance-type, that should always be
used
+ regardless of constraints (it's only a valid key when in legacy
+ deployments, in which constraint entry is disabled, or on private
+ clouds (which themselves register no constraints)).""" constraints = yield get_constraints([]) instance_type = get_instance_type( {"default-instance-type": "whatever-they-typed"}, constraints) self.assertEquals(instance_type, "whatever-they-typed")
+
+ @inlineCallbacks
+ def test_config_fallback(self):
+ """In a private cloud, a missing default-instance-id should fall
back
+ to m1.small."""
+ provider = MachineProvider("", {
+ "access-key": "foo", "secret-key": "bar",
+ "ec2-uri": "http://example.com"})
+ cs = yield provider.get_constraint_set()
+
+ # Verify that this is indeed a ConstraintSet without instance-type
+ self.assertRaises(
+ UnknownConstraintError, cs.parse, ["instance-type=c1.medium"])
+ constraints = cs.parse([])
+ instance_type = get_instance_type({}, constraints)
+ self.assertEquals(instance_type, "m1.small")
Index: juju/providers/ec2/utils.py
=== 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:47:12 +0000
@@ -143,6 +143,8 @@
instance_type = config.get("default-instance-type")
if instance_type is not None:
return instance_type
+ if "instance-type" not in constraints:
+ return "m1.small"
instance_type = constraints["instance-type"]
if instance_type is not None:
return instance_type
@@ -161,7 +163,7 @@
image_id = config.get("default-image-id")
if image_id is None:
series = constraints["ubuntu-series"] or config["default-series"]
- arch = constraints["arch"] or "amd64"
+ arch = constraints.get("arch") or "amd64"
region = config.get("region", DEFAULT_REGION)
hvm = INSTANCE_TYPES[instance_type].hvm ssl_verify = config.get("ssl-hostname-verification", False)
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-constrain ts/+merge/ 101592
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/6003046/
Affected files: ec2/__init_ _.py ec2/launch. py ec2/tests/ common. py ec2/tests/ test_launch. py ec2/tests/ test_provider. py ec2/tests/ test_utils. py ec2/utils. py
A [revision details]
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
M juju/providers/
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 /ec2/__ init__. py' ec2/__init_ _.py 2012-04-11 00:09:41 +0000 ec2/__init_ _.py 2012-04-11 15:47:12 +0000 set(self) : ovider, self).get_ constraint_ set()
cs.register_ generics( INSTANCE_ TYPES.keys( ))
cs.register( "ec2-zone" , converter= convert_ zone)
=== modified file 'juju/providers
--- juju/providers/
+++ juju/providers/
@@ -74,8 +74,7 @@
def get_constraint_
"""Return the set of constraints that are valid for this
provider."""
cs = yield super(MachinePr
- 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.
Index: juju/providers/ ec2/launch. py /ec2/launch. py' ec2/launch. py 2012-03-27 22:46:44 +0000 ec2/launch. py 2012-04-11 15:47:12 +0000
"$(curl http:// 169.254. 169.254/ 1.0/meta- data/instance- id)")
=== modified file 'juju/providers
--- juju/providers/
+++ juju/providers/
@@ -34,7 +34,7 @@
user_data = cloud_init.render()
- availability_zone = self._constrain ts["ec2- zone"] ts.get( "ec2-zone" )
region = self._provider. config. get("region" , DEFAULT_REGION)
availability_ zone = region + availability_zone
+ availability_zone = self._constrain
if availability_zone is not None:
Index: juju/providers/ ec2/tests/ common. py /ec2/tests/ common. py' ec2/tests/ common. py 2012-04-11 00:09:41 +0000 ec2/tests/ common. py 2012-04-11 15:47:12 +0000
get_ public_ key(MATCH( match_config) )
self. mocker. result( "zebra" )
=== modified file 'juju/providers
--- juju/providers/
+++ juju/providers/
@@ -101,12 +101,13 @@
- get_ami_args = get_ami_args or ( replace( .ec2.utils. get_current_ ami") *get_ami_ args) result( succeed( ami_name) ) replace( .ec2.utils. get_current_ ami") *get_ami_ args) result( succeed( ami_name) )
- "splendid", "amd64", "us-east-1", False, False)
- get_ami = self.mocker.
- "juju.providers
- get_ami(
- self.mocker.
+ if get_ami_args is not None:
+ get_ami_args = get_ami_args or (
+ "splendid", "amd64", "us-east-1", False, False)
+ get_ami = self.mocker.
+ "juju.providers
+ get_ami(
+ self.mocker.
def _mock_create_ group(self) :
group_ name = "juju-%s" % self.env_name
Index: juju/providers/ ec2/tests/ test_launch. py /ec2/tests/ test_launch. py' ec2/tests/ test_launch. py 2012-04-11 00:18:49 +0000 ec2/tests/ test_launch. py 2012-04-11 15:47:12 +0000
d.addCallbac k(verify_ result)
=== modified file 'juju/providers
--- juju/providers/
+++ juju/providers/
@@ -88,6 +88,35 @@
return d
+ def test_provider_ launch_ private_ cloud_constrain ts(self) : instance- type describe_ security_ groups( ) result( succeed( [])) create_ group() create_ machine_ group(" 1") launch_ utils(get_ ami_args= None) get_zookeeper_ hosts() launch( self.get_ instance( "i-foobar" ), "ami-tango") replay( ) result( result) : machine( machine, "i-foobar", "") config[ "default- image-id" ] = "ami-tango" start_machine( { verify_ result) inlineCallbacks launch_ requires_ constraints( self):
self. mocker. replay( )
+ """
+ When running on a private cloud (ie when the provider registers no
+ constraints) we should only require default-image-id in config, and
+ fall back to an instance-type of m1.small if default-
is
+ not present.
+ """
+ self.ec2.
+ self.mocker.
+ self._mock_
+ self._mock_
+ self._mock_
+ self._mock_
+ self._mock_
+ self.mocker.
+
+ def verify_
+ (machine,) = result
+ self.assert_
+ provider = self.get_provider()
+ provider.
+ d = provider.
+ "machine-id": "1",
+ "constraints": {
+ "provider-type": "ec2",
+ "ubuntu-series": "splendid"}})
+ d.addCallback(
+ return d
+
@
def test_provider_
Index: juju/providers/ ec2/tests/ test_provider. py /ec2/tests/ test_provider. py' ec2/tests/ test_provider. py 2012-04-11 00:18:49 +0000 ec2/tests/ test_provider. py 2012-04-11 15:47:12 +0000
self. assertFalse( b.can_satisfy( a))
=== modified file 'juju/providers
--- juju/providers/
+++ juju/providers/
@@ -254,9 +254,7 @@
@ inlineCallbacks amazon_ constraints( self): amazon_ constraints( self): ("some- non-ec2- env", {
"ec2-uri" : "blah", "secret-key": "foobar", "access-key": "bar"}) get_constraint_ set()
- def xtest_non_
- # Disabled because the ec2 provider requires these keys
(instance-type
- # and ec2-zone)
+ def test_non_
provider = MachineProvider
cs = yield provider.
Index: juju/providers/ ec2/tests/ test_utils. py /ec2/tests/ test_utils. py' ec2/tests/ test_utils. py 2012-04-11 08:19:44 +0000 ec2/tests/ test_utils. py 2012-04-11 15:47:12 +0000 internet. defer import fail, succeed, inlineCallbacks
=== modified file 'juju/providers
--- juju/providers/
+++ juju/providers/
@@ -4,7 +4,7 @@
from twisted.
from twisted.web.error import Error
-from juju.errors import ProviderError ntError
+from juju.errors import ProviderError, UnknownConstrai
from juju.lib.testing import TestCase
from juju.lib.mocker import MATCH
from juju.providers import ec2
@@ -13,6 +13,7 @@
from .common import get_constraints
+from juju.providers.ec2 import MachineProvider ec2.utils import VerifyingContex tFactory
from juju.providers.
@@ -275,7 +276,27 @@
@ inlineCallbacks override( self): instance- type, that should always be
constraints = yield get_constraints([])
instance_ type = get_instance_type(
{"default- instance- type": "whatever- they-typed" }, constraints)
self. assertEquals( instance_ type, "whatever- they-typed" ) fallback( self): example. com"}) get_constraint_ set() ntError, cs.parse, ["instance- type=c1. medium" ]) type({} , constraints) ls(instance_ type, "m1.small")
def test_config_
+ """If config contains default-
used
+ regardless of constraints (it's only a valid key when in legacy
+ deployments, in which constraint entry is disabled, or on private
+ clouds (which themselves register no constraints))."""
+
+ @inlineCallbacks
+ def test_config_
+ """In a private cloud, a missing default-instance-id should fall
back
+ to m1.small."""
+ provider = MachineProvider("", {
+ "access-key": "foo", "secret-key": "bar",
+ "ec2-uri": "http://
+ cs = yield provider.
+
+ # Verify that this is indeed a ConstraintSet without instance-type
+ self.assertRaises(
+ UnknownConstrai
+ constraints = cs.parse([])
+ instance_type = get_instance_
+ self.assertEqua
Index: juju/providers/ ec2/utils. py /ec2/utils. py' ec2/utils. py 2012-04-11 08:36:43 +0000 ec2/utils. py 2012-04-11 15:47:12 +0000 get("default- instance- type") "instance- type"] get("default- image-id" ) "ubuntu- series" ] or config[ "default- series" ] get("arch" ) or "amd64" get("region" , DEFAULT_REGION) TYPES[instance_ type].hvm
ssl_ verify = config. get("ssl- hostname- verification" , False)
=== modified file 'juju/providers
--- juju/providers/
+++ juju/providers/
@@ -143,6 +143,8 @@
instance_type = config.
if instance_type is not None:
return instance_type
+ if "instance-type" not in constraints:
+ return "m1.small"
instance_type = constraints[
if instance_type is not None:
return instance_type
@@ -161,7 +163,7 @@
image_id = config.
if image_id is None:
series = constraints[
- arch = constraints["arch"] or "amd64"
+ arch = constraints.
region = config.
hvm = INSTANCE_