Fixed some tests.
Some subnets were bogus so fixed that. Fixed issue where EC2-Classic was not respected. RDS Deepcopy was breaking on subnet generator
This commit is contained in:
parent
d935e0995f
commit
9ddf7fe436
@ -567,13 +567,17 @@ class Instance(TaggedEC2Resource, BotoInstance):
|
|||||||
def prep_nics(self, nic_spec, private_ip=None, associate_public_ip=None):
|
def prep_nics(self, nic_spec, private_ip=None, associate_public_ip=None):
|
||||||
self.nics = {}
|
self.nics = {}
|
||||||
|
|
||||||
subnet = self.ec2_backend.get_subnet(self.subnet_id)
|
if self.subnet_id:
|
||||||
if not private_ip:
|
subnet = self.ec2_backend.get_subnet(self.subnet_id)
|
||||||
private_ip = subnet.get_available_subnet_ip(instance=self)
|
if not private_ip:
|
||||||
else:
|
private_ip = subnet.get_available_subnet_ip(instance=self)
|
||||||
subnet.request_ip(private_ip, instance=self)
|
else:
|
||||||
|
subnet.request_ip(private_ip, instance=self)
|
||||||
|
|
||||||
self._private_ips.add(private_ip)
|
self._private_ips.add(private_ip)
|
||||||
|
elif private_ip is None:
|
||||||
|
# Preserve old behaviour if in EC2-Classic mode
|
||||||
|
private_ip = random_private_ip()
|
||||||
|
|
||||||
# Primary NIC defaults
|
# Primary NIC defaults
|
||||||
primary_nic = {'SubnetId': self.subnet_id,
|
primary_nic = {'SubnetId': self.subnet_id,
|
||||||
@ -2136,7 +2140,7 @@ class Subnet(TaggedEC2Resource):
|
|||||||
self.id = subnet_id
|
self.id = subnet_id
|
||||||
self.vpc_id = vpc_id
|
self.vpc_id = vpc_id
|
||||||
self.cidr_block = cidr_block
|
self.cidr_block = cidr_block
|
||||||
self.cidr = ipaddress.ip_network(self.cidr_block)
|
self.cidr = ipaddress.ip_network(six.text_type(self.cidr_block))
|
||||||
self._availability_zone = availability_zone
|
self._availability_zone = availability_zone
|
||||||
self.default_for_az = default_for_az
|
self.default_for_az = default_for_az
|
||||||
self.map_public_ip_on_launch = map_public_ip_on_launch
|
self.map_public_ip_on_launch = map_public_ip_on_launch
|
||||||
|
@ -704,7 +704,8 @@ class RDS2Backend(BaseBackend):
|
|||||||
if self.arn_regex.match(source_database_id):
|
if self.arn_regex.match(source_database_id):
|
||||||
db_kwargs['region'] = self.region
|
db_kwargs['region'] = self.region
|
||||||
|
|
||||||
replica = copy.deepcopy(primary)
|
# Shoudln't really copy here as the instance is duplicated. RDS replicas have different instances.
|
||||||
|
replica = copy.copy(primary)
|
||||||
replica.update(db_kwargs)
|
replica.update(db_kwargs)
|
||||||
replica.set_as_replica()
|
replica.set_as_replica()
|
||||||
self.databases[database_id] = replica
|
self.databases[database_id] = replica
|
||||||
|
@ -7,6 +7,7 @@ import base64
|
|||||||
import datetime
|
import datetime
|
||||||
import ipaddress
|
import ipaddress
|
||||||
|
|
||||||
|
import six
|
||||||
import boto
|
import boto
|
||||||
import boto3
|
import boto3
|
||||||
from boto.ec2.instance import Reservation, InstanceAttribute
|
from boto.ec2.instance import Reservation, InstanceAttribute
|
||||||
@ -414,6 +415,7 @@ def test_get_instances_filtering_by_image_id():
|
|||||||
'Values': [image_id]}])['Reservations']
|
'Values': [image_id]}])['Reservations']
|
||||||
reservations[0]['Instances'].should.have.length_of(1)
|
reservations[0]['Instances'].should.have.length_of(1)
|
||||||
|
|
||||||
|
|
||||||
@mock_ec2
|
@mock_ec2
|
||||||
def test_get_instances_filtering_by_private_dns():
|
def test_get_instances_filtering_by_private_dns():
|
||||||
image_id = 'ami-1234abcd'
|
image_id = 'ami-1234abcd'
|
||||||
@ -428,6 +430,7 @@ def test_get_instances_filtering_by_private_dns():
|
|||||||
])['Reservations']
|
])['Reservations']
|
||||||
reservations[0]['Instances'].should.have.length_of(1)
|
reservations[0]['Instances'].should.have.length_of(1)
|
||||||
|
|
||||||
|
|
||||||
@mock_ec2
|
@mock_ec2
|
||||||
def test_get_instances_filtering_by_ni_private_dns():
|
def test_get_instances_filtering_by_ni_private_dns():
|
||||||
image_id = 'ami-1234abcd'
|
image_id = 'ami-1234abcd'
|
||||||
@ -442,6 +445,7 @@ def test_get_instances_filtering_by_ni_private_dns():
|
|||||||
])['Reservations']
|
])['Reservations']
|
||||||
reservations[0]['Instances'].should.have.length_of(1)
|
reservations[0]['Instances'].should.have.length_of(1)
|
||||||
|
|
||||||
|
|
||||||
@mock_ec2
|
@mock_ec2
|
||||||
def test_get_instances_filtering_by_instance_group_name():
|
def test_get_instances_filtering_by_instance_group_name():
|
||||||
image_id = 'ami-1234abcd'
|
image_id = 'ami-1234abcd'
|
||||||
@ -459,6 +463,7 @@ def test_get_instances_filtering_by_instance_group_name():
|
|||||||
])['Reservations']
|
])['Reservations']
|
||||||
reservations[0]['Instances'].should.have.length_of(1)
|
reservations[0]['Instances'].should.have.length_of(1)
|
||||||
|
|
||||||
|
|
||||||
@mock_ec2
|
@mock_ec2
|
||||||
def test_get_instances_filtering_by_instance_group_id():
|
def test_get_instances_filtering_by_instance_group_id():
|
||||||
image_id = 'ami-1234abcd'
|
image_id = 'ami-1234abcd'
|
||||||
@ -477,6 +482,7 @@ def test_get_instances_filtering_by_instance_group_id():
|
|||||||
])['Reservations']
|
])['Reservations']
|
||||||
reservations[0]['Instances'].should.have.length_of(1)
|
reservations[0]['Instances'].should.have.length_of(1)
|
||||||
|
|
||||||
|
|
||||||
@mock_ec2_deprecated
|
@mock_ec2_deprecated
|
||||||
def test_get_instances_filtering_by_tag():
|
def test_get_instances_filtering_by_tag():
|
||||||
conn = boto.connect_ec2()
|
conn = boto.connect_ec2()
|
||||||
@ -832,7 +838,7 @@ def test_run_instance_with_placement():
|
|||||||
|
|
||||||
|
|
||||||
@mock_ec2
|
@mock_ec2
|
||||||
def test_run_instance_with_subnet():
|
def test_run_instance_with_subnet_boto3():
|
||||||
client = boto3.client('ec2', region_name='eu-central-1')
|
client = boto3.client('ec2', region_name='eu-central-1')
|
||||||
|
|
||||||
ip_networks = [
|
ip_networks = [
|
||||||
@ -865,7 +871,7 @@ def test_run_instance_with_subnet():
|
|||||||
instance = resp['Instances'][0]
|
instance = resp['Instances'][0]
|
||||||
instance['SubnetId'].should.equal(subnet_id)
|
instance['SubnetId'].should.equal(subnet_id)
|
||||||
|
|
||||||
priv_ipv4 = ipaddress.ip_address(instance['PrivateIpAddress'])
|
priv_ipv4 = ipaddress.ip_address(six.text_type(instance['PrivateIpAddress']))
|
||||||
subnet_cidr.should.contain(priv_ipv4)
|
subnet_cidr.should.contain(priv_ipv4)
|
||||||
|
|
||||||
|
|
||||||
@ -899,7 +905,7 @@ def test_run_instance_with_specified_private_ipv4():
|
|||||||
)
|
)
|
||||||
instance = resp['Instances'][0]
|
instance = resp['Instances'][0]
|
||||||
instance['SubnetId'].should.equal(subnet_id)
|
instance['SubnetId'].should.equal(subnet_id)
|
||||||
instance['PrivateIpAddress'].shoud.equal('192.168.42.5')
|
instance['PrivateIpAddress'].should.equal('192.168.42.5')
|
||||||
|
|
||||||
|
|
||||||
@mock_ec2
|
@mock_ec2
|
||||||
@ -949,7 +955,7 @@ def test_run_instance_with_nic_autocreated():
|
|||||||
'test security group #1', 'this is a test security group')
|
'test security group #1', 'this is a test security group')
|
||||||
security_group2 = conn.create_security_group(
|
security_group2 = conn.create_security_group(
|
||||||
'test security group #2', 'this is a test security group')
|
'test security group #2', 'this is a test security group')
|
||||||
private_ip = "54.0.0.1"
|
private_ip = "10.0.0.1"
|
||||||
|
|
||||||
reservation = conn.run_instances('ami-1234abcd', subnet_id=subnet.id,
|
reservation = conn.run_instances('ami-1234abcd', subnet_id=subnet.id,
|
||||||
security_groups=[security_group1.name],
|
security_groups=[security_group1.name],
|
||||||
|
@ -126,9 +126,9 @@ def test_route_tables_filters_associations():
|
|||||||
conn = boto.connect_vpc('the_key', 'the_secret')
|
conn = boto.connect_vpc('the_key', 'the_secret')
|
||||||
|
|
||||||
vpc = conn.create_vpc("10.0.0.0/16")
|
vpc = conn.create_vpc("10.0.0.0/16")
|
||||||
subnet1 = conn.create_subnet(vpc.id, "10.0.0.0/18")
|
subnet1 = conn.create_subnet(vpc.id, "10.0.0.0/24")
|
||||||
subnet2 = conn.create_subnet(vpc.id, "10.0.1.0/18")
|
subnet2 = conn.create_subnet(vpc.id, "10.0.1.0/24")
|
||||||
subnet3 = conn.create_subnet(vpc.id, "10.0.2.0/18")
|
subnet3 = conn.create_subnet(vpc.id, "10.0.2.0/24")
|
||||||
route_table1 = conn.create_route_table(vpc.id)
|
route_table1 = conn.create_route_table(vpc.id)
|
||||||
route_table2 = conn.create_route_table(vpc.id)
|
route_table2 = conn.create_route_table(vpc.id)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user