Merge pull request #1016 from JackDanger/elb-security-groups
Implementing ELB apply_security_groups_to_load_balancer
This commit is contained in:
commit
074ff68bf1
5 changed files with 99 additions and 17 deletions
|
|
@ -9,12 +9,6 @@ from boto.ec2.elb.attributes import (
|
|||
ConnectionDrainingAttribute,
|
||||
AccessLogAttribute,
|
||||
)
|
||||
from boto.ec2.elb.policies import (
|
||||
Policies,
|
||||
AppCookieStickinessPolicy,
|
||||
LBCookieStickinessPolicy,
|
||||
OtherPolicy,
|
||||
)
|
||||
from botocore.exceptions import ClientError
|
||||
from boto.exception import BotoServerError
|
||||
from nose.tools import assert_raises
|
||||
|
|
@ -24,17 +18,22 @@ from moto import mock_elb, mock_ec2, mock_elb_deprecated, mock_ec2_deprecated
|
|||
|
||||
|
||||
@mock_elb_deprecated
|
||||
@mock_ec2_deprecated
|
||||
def test_create_load_balancer():
|
||||
conn = boto.connect_elb()
|
||||
ec2 = boto.connect_ec2('the_key', 'the_secret')
|
||||
|
||||
security_group = ec2.create_security_group('sg-abc987', 'description')
|
||||
|
||||
zones = ['us-east-1a', 'us-east-1b']
|
||||
ports = [(80, 8080, 'http'), (443, 8443, 'tcp')]
|
||||
conn.create_load_balancer('my-lb', zones, ports, scheme='internal')
|
||||
conn.create_load_balancer('my-lb', zones, ports, scheme='internal', security_groups=[security_group.id])
|
||||
|
||||
balancers = conn.get_all_load_balancers()
|
||||
balancer = balancers[0]
|
||||
balancer.name.should.equal("my-lb")
|
||||
balancer.scheme.should.equal("internal")
|
||||
list(balancer.security_groups).should.equal([security_group.id])
|
||||
set(balancer.availability_zones).should.equal(
|
||||
set(['us-east-1a', 'us-east-1b']))
|
||||
listener1 = balancer.listeners[0]
|
||||
|
|
@ -143,6 +142,38 @@ def test_describe_paginated_balancers():
|
|||
assert 'NextToken' not in resp2.keys()
|
||||
|
||||
|
||||
@mock_elb
|
||||
@mock_ec2
|
||||
def test_apply_security_groups_to_load_balancer():
|
||||
client = boto3.client('elb', region_name='us-east-1')
|
||||
ec2 = boto3.resource('ec2', region_name='us-east-1')
|
||||
|
||||
vpc = ec2.create_vpc(CidrBlock='10.0.0.0/16')
|
||||
security_group = ec2.create_security_group(
|
||||
GroupName='sg01', Description='Test security group sg01', VpcId=vpc.id)
|
||||
|
||||
client.create_load_balancer(
|
||||
LoadBalancerName='my-lb',
|
||||
Listeners=[
|
||||
{'Protocol': 'tcp', 'LoadBalancerPort': 80, 'InstancePort': 8080}],
|
||||
AvailabilityZones=['us-east-1a', 'us-east-1b']
|
||||
)
|
||||
|
||||
response = client.apply_security_groups_to_load_balancer(
|
||||
LoadBalancerName='my-lb',
|
||||
SecurityGroups=[security_group.id])
|
||||
|
||||
assert response['SecurityGroups'] == [security_group.id]
|
||||
balancer = client.describe_load_balancers()['LoadBalancerDescriptions'][0]
|
||||
assert balancer['SecurityGroups'] == [security_group.id]
|
||||
|
||||
# Using a not-real security group raises an error
|
||||
with assert_raises(ClientError) as error:
|
||||
response = client.apply_security_groups_to_load_balancer(
|
||||
LoadBalancerName='my-lb',
|
||||
SecurityGroups=['not-really-a-security-group'])
|
||||
assert "One or more of the specified security groups do not exist." in str(error.exception)
|
||||
|
||||
|
||||
@mock_elb_deprecated
|
||||
def test_add_listener():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue