Network Interfaces: Added attach/detach support.
This commit is contained in:
parent
aef0b909f6
commit
04a4ae88bf
5 changed files with 192 additions and 83 deletions
|
|
@ -360,6 +360,60 @@ def test_run_instance_with_nic_preexisting():
|
|||
instance_eni.private_ip_addresses[0].private_ip_address.should.equal(private_ip)
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_instance_with_nic_attach_detach():
|
||||
conn = boto.connect_vpc('the_key', 'the_secret')
|
||||
vpc = conn.create_vpc("10.0.0.0/16")
|
||||
subnet = conn.create_subnet(vpc.id, "10.0.0.0/18")
|
||||
|
||||
security_group1 = conn.create_security_group('test security group #1', 'this is a test security group')
|
||||
security_group2 = conn.create_security_group('test security group #2', 'this is a test security group')
|
||||
|
||||
reservation = conn.run_instances('ami-1234abcd', security_group_ids=[security_group1.id])
|
||||
instance = reservation.instances[0]
|
||||
|
||||
eni = conn.create_network_interface(subnet.id, groups=[security_group2.id])
|
||||
|
||||
# Check initial instance and ENI data
|
||||
instance.interfaces.should.have.length_of(0)
|
||||
|
||||
eni.groups.should.have.length_of(1)
|
||||
set([group.id for group in eni.groups]).should.equal(set([security_group2.id]))
|
||||
|
||||
# Attach
|
||||
conn.attach_network_interface(eni.id, instance.id, device_index=0)
|
||||
|
||||
# Check attached instance and ENI data
|
||||
instance.update()
|
||||
instance.interfaces.should.have.length_of(1)
|
||||
instance_eni = instance.interfaces[0]
|
||||
instance_eni.id.should.equal(eni.id)
|
||||
instance_eni.groups.should.have.length_of(2)
|
||||
set([group.id for group in instance_eni.groups]).should.equal(set([security_group1.id,security_group2.id]))
|
||||
|
||||
eni = conn.get_all_network_interfaces(eni.id)[0]
|
||||
eni.groups.should.have.length_of(2)
|
||||
set([group.id for group in eni.groups]).should.equal(set([security_group1.id,security_group2.id]))
|
||||
|
||||
# Detach
|
||||
conn.detach_network_interface(instance_eni.attachment.id)
|
||||
|
||||
# Check detached instance and ENI data
|
||||
instance.update()
|
||||
instance.interfaces.should.have.length_of(0)
|
||||
|
||||
eni = conn.get_all_network_interfaces(eni.id)[0]
|
||||
eni.groups.should.have.length_of(1)
|
||||
set([group.id for group in eni.groups]).should.equal(set([security_group2.id]))
|
||||
|
||||
# Detach with invalid attachment ID
|
||||
with assert_raises(EC2ResponseError) as cm:
|
||||
conn.detach_network_interface('eni-attach-1234abcd')
|
||||
cm.exception.code.should.equal('InvalidAttachmentID.NotFound')
|
||||
cm.exception.status.should.equal(400)
|
||||
cm.exception.request_id.should_not.be.none
|
||||
|
||||
|
||||
@mock_ec2
|
||||
def test_run_instance_with_keypair():
|
||||
conn = boto.connect_ec2('the_key', 'the_secret')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue