summaryrefslogtreecommitdiff
path: root/tests/unit/ec2/test_networkinterface.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/ec2/test_networkinterface.py')
-rw-r--r--tests/unit/ec2/test_networkinterface.py148
1 files changed, 103 insertions, 45 deletions
diff --git a/tests/unit/ec2/test_networkinterface.py b/tests/unit/ec2/test_networkinterface.py
index 4674823d..81fa4aef 100644
--- a/tests/unit/ec2/test_networkinterface.py
+++ b/tests/unit/ec2/test_networkinterface.py
@@ -23,7 +23,7 @@
from tests.unit import unittest
-
+from boto.exception import BotoClientError
from boto.ec2.networkinterface import NetworkInterfaceCollection
from boto.ec2.networkinterface import NetworkInterfaceSpecification
from boto.ec2.networkinterface import PrivateIPAddress
@@ -42,7 +42,8 @@ class TestNetworkInterfaceCollection(unittest.TestCase):
description='description1',
private_ip_address='10.0.0.54', delete_on_termination=False,
private_ip_addresses=[self.private_ip_address1,
- self.private_ip_address2])
+ self.private_ip_address2]
+ )
self.private_ip_address3 = PrivateIPAddress(
private_ip_address='10.0.1.10', primary=False)
@@ -54,8 +55,18 @@ class TestNetworkInterfaceCollection(unittest.TestCase):
groups=['group_id1', 'group_id2'],
private_ip_address='10.0.1.54', delete_on_termination=False,
private_ip_addresses=[self.private_ip_address3,
+ self.private_ip_address4]
+ )
+
+ self.network_interfaces_spec3 = NetworkInterfaceSpecification(
+ device_index=0, subnet_id='subnet_id2',
+ description='description2',
+ groups=['group_id1', 'group_id2'],
+ private_ip_address='10.0.1.54', delete_on_termination=False,
+ private_ip_addresses=[self.private_ip_address3,
self.private_ip_address4],
- associate_public_ip_address=True)
+ associate_public_ip_address=True
+ )
def test_param_serialization(self):
collection = NetworkInterfaceCollection(self.network_interfaces_spec1,
@@ -63,30 +74,29 @@ class TestNetworkInterfaceCollection(unittest.TestCase):
params = {}
collection.build_list_params(params)
self.assertDictEqual(params, {
- 'NetworkInterface.1.DeviceIndex': '1',
- 'NetworkInterface.1.DeleteOnTermination': 'false',
- 'NetworkInterface.1.Description': 'description1',
- 'NetworkInterface.1.PrivateIpAddress': '10.0.0.54',
- 'NetworkInterface.1.SubnetId': 'subnet_id',
- 'NetworkInterface.1.PrivateIpAddresses.1.Primary': 'false',
- 'NetworkInterface.1.PrivateIpAddresses.1.PrivateIpAddress':
+ 'NetworkInterface.0.DeviceIndex': '1',
+ 'NetworkInterface.0.DeleteOnTermination': 'false',
+ 'NetworkInterface.0.Description': 'description1',
+ 'NetworkInterface.0.PrivateIpAddress': '10.0.0.54',
+ 'NetworkInterface.0.SubnetId': 'subnet_id',
+ 'NetworkInterface.0.PrivateIpAddresses.0.Primary': 'false',
+ 'NetworkInterface.0.PrivateIpAddresses.0.PrivateIpAddress':
'10.0.0.10',
- 'NetworkInterface.1.PrivateIpAddresses.2.Primary': 'false',
- 'NetworkInterface.1.PrivateIpAddresses.2.PrivateIpAddress':
+ 'NetworkInterface.0.PrivateIpAddresses.1.Primary': 'false',
+ 'NetworkInterface.0.PrivateIpAddresses.1.PrivateIpAddress':
'10.0.0.11',
- 'NetworkInterface.2.DeviceIndex': '2',
- 'NetworkInterface.2.Description': 'description2',
- 'NetworkInterface.2.DeleteOnTermination': 'false',
- 'NetworkInterface.2.PrivateIpAddress': '10.0.1.54',
- 'NetworkInterface.2.SubnetId': 'subnet_id2',
- 'NetworkInterface.2.AssociatePublicIpAddress': 'true',
- 'NetworkInterface.2.SecurityGroupId.1': 'group_id1',
- 'NetworkInterface.2.SecurityGroupId.2': 'group_id2',
- 'NetworkInterface.2.PrivateIpAddresses.1.Primary': 'false',
- 'NetworkInterface.2.PrivateIpAddresses.1.PrivateIpAddress':
+ 'NetworkInterface.1.DeviceIndex': '2',
+ 'NetworkInterface.1.Description': 'description2',
+ 'NetworkInterface.1.DeleteOnTermination': 'false',
+ 'NetworkInterface.1.PrivateIpAddress': '10.0.1.54',
+ 'NetworkInterface.1.SubnetId': 'subnet_id2',
+ 'NetworkInterface.1.SecurityGroupId.0': 'group_id1',
+ 'NetworkInterface.1.SecurityGroupId.1': 'group_id2',
+ 'NetworkInterface.1.PrivateIpAddresses.0.Primary': 'false',
+ 'NetworkInterface.1.PrivateIpAddresses.0.PrivateIpAddress':
'10.0.1.10',
- 'NetworkInterface.2.PrivateIpAddresses.2.Primary': 'false',
- 'NetworkInterface.2.PrivateIpAddresses.2.PrivateIpAddress':
+ 'NetworkInterface.1.PrivateIpAddresses.1.Primary': 'false',
+ 'NetworkInterface.1.PrivateIpAddresses.1.PrivateIpAddress':
'10.0.1.11',
})
@@ -99,44 +109,92 @@ class TestNetworkInterfaceCollection(unittest.TestCase):
# we're just checking a few keys to make sure we get the proper
# prefix.
self.assertDictEqual(params, {
- 'LaunchSpecification.NetworkInterface.1.DeviceIndex': '1',
- 'LaunchSpecification.NetworkInterface.1.DeleteOnTermination':
+ 'LaunchSpecification.NetworkInterface.0.DeviceIndex': '1',
+ 'LaunchSpecification.NetworkInterface.0.DeleteOnTermination':
'false',
- 'LaunchSpecification.NetworkInterface.1.Description':
+ 'LaunchSpecification.NetworkInterface.0.Description':
'description1',
- 'LaunchSpecification.NetworkInterface.1.PrivateIpAddress':
+ 'LaunchSpecification.NetworkInterface.0.PrivateIpAddress':
'10.0.0.54',
- 'LaunchSpecification.NetworkInterface.1.SubnetId': 'subnet_id',
- 'LaunchSpecification.NetworkInterface.1.PrivateIpAddresses.1.Primary':
+ 'LaunchSpecification.NetworkInterface.0.SubnetId': 'subnet_id',
+ 'LaunchSpecification.NetworkInterface.0.PrivateIpAddresses.0.Primary':
'false',
- 'LaunchSpecification.NetworkInterface.1.PrivateIpAddresses.1.PrivateIpAddress':
+ 'LaunchSpecification.NetworkInterface.0.PrivateIpAddresses.0.PrivateIpAddress':
'10.0.0.10',
- 'LaunchSpecification.NetworkInterface.1.PrivateIpAddresses.2.Primary': 'false',
- 'LaunchSpecification.NetworkInterface.1.PrivateIpAddresses.2.PrivateIpAddress':
+ 'LaunchSpecification.NetworkInterface.0.PrivateIpAddresses.1.Primary': 'false',
+ 'LaunchSpecification.NetworkInterface.0.PrivateIpAddresses.1.PrivateIpAddress':
'10.0.0.11',
- 'LaunchSpecification.NetworkInterface.2.DeviceIndex': '2',
- 'LaunchSpecification.NetworkInterface.2.Description':
+ 'LaunchSpecification.NetworkInterface.1.DeviceIndex': '2',
+ 'LaunchSpecification.NetworkInterface.1.Description':
'description2',
- 'LaunchSpecification.NetworkInterface.2.DeleteOnTermination':
+ 'LaunchSpecification.NetworkInterface.1.DeleteOnTermination':
'false',
- 'LaunchSpecification.NetworkInterface.2.PrivateIpAddress':
+ 'LaunchSpecification.NetworkInterface.1.PrivateIpAddress':
'10.0.1.54',
- 'LaunchSpecification.NetworkInterface.2.SubnetId': 'subnet_id2',
- 'LaunchSpecification.NetworkInterface.2.AssociatePublicIpAddress': 'true',
- 'LaunchSpecification.NetworkInterface.2.SecurityGroupId.1':
+ 'LaunchSpecification.NetworkInterface.1.SubnetId': 'subnet_id2',
+ 'LaunchSpecification.NetworkInterface.1.SecurityGroupId.0':
'group_id1',
- 'LaunchSpecification.NetworkInterface.2.SecurityGroupId.2':
+ 'LaunchSpecification.NetworkInterface.1.SecurityGroupId.1':
'group_id2',
- 'LaunchSpecification.NetworkInterface.2.PrivateIpAddresses.1.Primary':
+ 'LaunchSpecification.NetworkInterface.1.PrivateIpAddresses.0.Primary':
'false',
- 'LaunchSpecification.NetworkInterface.2.PrivateIpAddresses.1.PrivateIpAddress':
+ 'LaunchSpecification.NetworkInterface.1.PrivateIpAddresses.0.PrivateIpAddress':
'10.0.1.10',
- 'LaunchSpecification.NetworkInterface.2.PrivateIpAddresses.2.Primary':
+ 'LaunchSpecification.NetworkInterface.1.PrivateIpAddresses.1.Primary':
'false',
- 'LaunchSpecification.NetworkInterface.2.PrivateIpAddresses.2.PrivateIpAddress':
+ 'LaunchSpecification.NetworkInterface.1.PrivateIpAddresses.1.PrivateIpAddress':
'10.0.1.11',
})
+ def test_cant_use_public_ip(self):
+ collection = NetworkInterfaceCollection(self.network_interfaces_spec3,
+ self.network_interfaces_spec1)
+ params = {}
+
+ # First, verify we can't incorrectly create multiple interfaces with
+ # on having a public IP.
+ with self.assertRaises(BotoClientError):
+ collection.build_list_params(params, prefix='LaunchSpecification.')
+
+ # Next, ensure it can't be on device index 1.
+ self.network_interfaces_spec3.device_index = 1
+ collection = NetworkInterfaceCollection(self.network_interfaces_spec3)
+ params = {}
+
+ with self.assertRaises(BotoClientError):
+ collection.build_list_params(params, prefix='LaunchSpecification.')
+
+ def test_public_ip(self):
+ # With public IP.
+ collection = NetworkInterfaceCollection(self.network_interfaces_spec3)
+ params = {}
+ collection.build_list_params(params, prefix='LaunchSpecification.')
+
+ self.assertDictEqual(params, {
+ 'LaunchSpecification.NetworkInterface.0.AssociatePublicIpAddress':
+ 'true',
+ 'LaunchSpecification.NetworkInterface.0.DeviceIndex': '0',
+ 'LaunchSpecification.NetworkInterface.0.DeleteOnTermination':
+ 'false',
+ 'LaunchSpecification.NetworkInterface.0.Description':
+ 'description2',
+ 'LaunchSpecification.NetworkInterface.0.PrivateIpAddress':
+ '10.0.1.54',
+ 'LaunchSpecification.NetworkInterface.0.SubnetId': 'subnet_id2',
+ 'LaunchSpecification.NetworkInterface.0.PrivateIpAddresses.0.Primary':
+ 'false',
+ 'LaunchSpecification.NetworkInterface.0.PrivateIpAddresses.0.PrivateIpAddress':
+ '10.0.1.10',
+ 'LaunchSpecification.NetworkInterface.0.PrivateIpAddresses.1.Primary':
+ 'false',
+ 'LaunchSpecification.NetworkInterface.0.PrivateIpAddresses.1.PrivateIpAddress':
+ '10.0.1.11',
+ 'LaunchSpecification.NetworkInterface.0.SecurityGroupId.0':
+ 'group_id1',
+ 'LaunchSpecification.NetworkInterface.0.SecurityGroupId.1':
+ 'group_id2',
+ })
+
if __name__ == '__main__':
unittest.main()