Disallow creation of ELBs with duplicate names.
This commit is contained in:
parent
076a6a7055
commit
e47fc4cafc
@ -35,3 +35,11 @@ class BadHealthCheckDefinition(ELBClientError):
|
||||
"ValidationError",
|
||||
"HealthCheck Target must begin with one of HTTP, TCP, HTTPS, SSL")
|
||||
|
||||
|
||||
class DuplicateLoadBalancerName(ELBClientError):
|
||||
def __init__(self, name):
|
||||
super(DuplicateLoadBalancerName, self).__init__(
|
||||
"DuplicateLoadBalancerName",
|
||||
"The specified load balancer name already exists for this account: {0}"
|
||||
.format(name))
|
||||
|
||||
|
@ -11,7 +11,12 @@ from boto.ec2.elb.attributes import (
|
||||
from boto.ec2.elb.policies import Policies
|
||||
from moto.core import BaseBackend
|
||||
from moto.ec2.models import ec2_backends
|
||||
from .exceptions import LoadBalancerNotFoundError, TooManyTagsError, BadHealthCheckDefinition
|
||||
from .exceptions import (
|
||||
LoadBalancerNotFoundError,
|
||||
TooManyTagsError,
|
||||
BadHealthCheckDefinition,
|
||||
DuplicateLoadBalancerName,
|
||||
)
|
||||
|
||||
|
||||
class FakeHealthCheck(object):
|
||||
@ -64,7 +69,7 @@ class FakeLoadBalancer(object):
|
||||
self.subnets = subnets or []
|
||||
self.vpc_id = vpc_id or 'vpc-56e10e3d'
|
||||
self.tags = {}
|
||||
self.dns_name = "tests.us-east-1.elb.amazonaws.com"
|
||||
self.dns_name = "%s.us-east-1.elb.amazonaws.com" % (name)
|
||||
|
||||
for port in ports:
|
||||
listener = FakeListener(
|
||||
@ -198,6 +203,8 @@ class ELBBackend(BaseBackend):
|
||||
if subnets:
|
||||
subnet = ec2_backend.get_subnet(subnets[0])
|
||||
vpc_id = subnet.vpc_id
|
||||
if name in self.load_balancers:
|
||||
raise DuplicateLoadBalancerName(name)
|
||||
new_load_balancer = FakeLoadBalancer(name=name, zones=zones, ports=ports, scheme=scheme, subnets=subnets, vpc_id=vpc_id)
|
||||
self.load_balancers[name] = new_load_balancer
|
||||
return new_load_balancer
|
||||
|
@ -438,7 +438,7 @@ DESCRIBE_LOAD_BALANCERS_TEMPLATE = """<DescribeLoadBalancersResponse xmlns="http
|
||||
<member>{{ zone }}</member>
|
||||
{% endfor %}
|
||||
</AvailabilityZones>
|
||||
<CanonicalHostedZoneName>tests.us-east-1.elb.amazonaws.com</CanonicalHostedZoneName>
|
||||
<CanonicalHostedZoneName>{{ load_balancer.dns_name }}</CanonicalHostedZoneName>
|
||||
<CanonicalHostedZoneNameID>Z3ZONEID</CanonicalHostedZoneNameID>
|
||||
<Scheme>{{ load_balancer.scheme }}</Scheme>
|
||||
<DNSName>{{ load_balancer.dns_name }}</DNSName>
|
||||
|
@ -763,3 +763,12 @@ def test_subnets():
|
||||
lb['Subnets'][0].should.equal(subnet.id)
|
||||
|
||||
lb.should.have.key('VPCId').which.should.equal(vpc.id)
|
||||
|
||||
|
||||
@mock_elb
|
||||
def test_create_load_balancer_duplicate():
|
||||
conn = boto.connect_elb()
|
||||
ports = [(80, 8080, 'http'), (443, 8443, 'tcp')]
|
||||
conn.create_load_balancer('my-lb', [], ports)
|
||||
conn.create_load_balancer.when.called_with('my-lb', [], ports).should.throw(BotoServerError)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user