diff --git a/moto/elb/models.py b/moto/elb/models.py index 1f50c3aca..2303e907c 100644 --- a/moto/elb/models.py +++ b/moto/elb/models.py @@ -10,7 +10,7 @@ from boto.ec2.elb.attributes import ( ) from boto.ec2.elb.policies import Policies from moto.core import BaseBackend -from .exceptions import TooManyTagsError +from .exceptions import LoadBalancerNotFoundError, TooManyTagsError class FakeHealthCheck(object): @@ -139,7 +139,7 @@ class FakeLoadBalancer(object): def list_tags(self): return self.tags - + def remove_tag(self, key): if key in self.tags: del self.tags[key] @@ -174,7 +174,11 @@ class ELBBackend(BaseBackend): def describe_load_balancers(self, names): balancers = self.load_balancers.values() if names: - return [balancer for balancer in balancers if balancer.name in names] + matched_balancers = [balancer for balancer in balancers if balancer.name in names] + if len(names) != len(matched_balancers): + missing_elb = list(set(names) - set(matched_balancers))[0] + raise LoadBalancerNotFoundError(missing_elb) + return matched_balancers else: return balancers diff --git a/moto/elb/responses.py b/moto/elb/responses.py index 6e9690c9c..0ed230afd 100644 --- a/moto/elb/responses.py +++ b/moto/elb/responses.py @@ -245,7 +245,7 @@ class ELBResponse(BaseResponse): for i in tag_keys: counts[i] = tag_keys.count(i) - counts = sorted(counts.items(), key=lambda i:i[1], reverse=True) + counts = sorted(counts.items(), key=lambda i:i[1], reverse=True) if counts and counts[0][1] > 1: # We have dupes... diff --git a/tests/test_autoscaling/test_autoscaling.py b/tests/test_autoscaling/test_autoscaling.py index bc424bad9..81a331dfb 100644 --- a/tests/test_autoscaling/test_autoscaling.py +++ b/tests/test_autoscaling/test_autoscaling.py @@ -1,8 +1,10 @@ from __future__ import unicode_literals import boto +import boto.ec2.autoscale from boto.ec2.autoscale.launchconfig import LaunchConfiguration from boto.ec2.autoscale.group import AutoScalingGroup from boto.ec2.autoscale import Tag +import boto.ec2.elb import sure # noqa from moto import mock_autoscaling, mock_ec2, mock_elb @@ -10,8 +12,12 @@ from tests.helpers import requires_boto_gte @mock_autoscaling +@mock_elb def test_create_autoscaling_group(): - conn = boto.connect_autoscale() + elb_conn = boto.ec2.elb.connect_to_region('us-east-1') + elb_conn.create_load_balancer('test_lb', zones=[], listeners=[(80, 8080, 'http')]) + + conn = boto.ec2.autoscale.connect_to_region('us-east-1') config = LaunchConfiguration( name='tester', image_id='ami-abcd1234', @@ -19,7 +25,6 @@ def test_create_autoscaling_group(): ) conn.create_launch_configuration(config) - group = AutoScalingGroup( name='tester_group', availability_zones=['us-east-1c', 'us-east-1b'], diff --git a/tests/test_ec2/test_regions.py b/tests/test_ec2/test_regions.py index 153bb759a..9375314d4 100644 --- a/tests/test_ec2/test_regions.py +++ b/tests/test_ec2/test_regions.py @@ -1,8 +1,9 @@ from __future__ import unicode_literals import boto.ec2 import boto.ec2.autoscale +import boto.ec2.elb import sure -from moto import mock_ec2, mock_autoscaling +from moto import mock_ec2, mock_autoscaling, mock_elb def add_servers_to_region(ami_id, count, region): @@ -46,7 +47,13 @@ def test_add_servers_to_multiple_regions(): @mock_autoscaling +@mock_elb def test_create_autoscaling_group(): + elb_conn = boto.ec2.elb.connect_to_region('us-east-1') + elb_conn.create_load_balancer('us_test_lb', zones=[], listeners=[(80, 8080, 'http')]) + elb_conn = boto.ec2.elb.connect_to_region('ap-northeast-1') + elb_conn.create_load_balancer('ap_test_lb', zones=[], listeners=[(80, 8080, 'http')]) + us_conn = boto.ec2.autoscale.connect_to_region('us-east-1') config = boto.ec2.autoscale.LaunchConfiguration( name='us_tester', diff --git a/tests/test_elb/test_elb.py b/tests/test_elb/test_elb.py index 4bee51218..e16d490aa 100644 --- a/tests/test_elb/test_elb.py +++ b/tests/test_elb/test_elb.py @@ -15,6 +15,7 @@ from boto.ec2.elb.policies import ( LBCookieStickinessPolicy, OtherPolicy, ) +from boto.exception import BotoServerError import sure # noqa from moto import mock_elb, mock_ec2 @@ -42,6 +43,12 @@ def test_create_load_balancer(): listener2.protocol.should.equal("TCP") +@mock_elb +def test_getting_missing_elb(): + conn = boto.connect_elb() + conn.get_all_load_balancers.when.called_with(load_balancer_names='aaa').should.throw(BotoServerError) + + @mock_elb def test_create_elb_in_multiple_region(): zones = ['us-east-1a', 'us-east-1b']