Cleanup querying missing ELB error.

This commit is contained in:
Steve Pulec 2015-12-13 22:41:17 -05:00
parent 2e69986e01
commit 5d421dc343
5 changed files with 30 additions and 7 deletions

View File

@ -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

View File

@ -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...

View File

@ -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'],

View File

@ -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',

View File

@ -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']