diff options
author | Daniel G. Taylor <danielgtaylor@gmail.com> | 2013-10-09 14:19:40 -0700 |
---|---|---|
committer | Daniel G. Taylor <danielgtaylor@gmail.com> | 2013-10-09 14:19:40 -0700 |
commit | 5005178d88ef8e4bbe8c30949ffab46e46a716b0 (patch) | |
tree | 9a726460c3d64e438dada4e66b584aa189058d5f /tests/unit/ec2/test_networkinterface.py | |
parent | 3c56d13f56d4db34ea59eb526e221c1e07728c98 (diff) | |
parent | a00851636307f971b03e72e1ce812cd3242816f3 (diff) | |
download | boto-2.14.0.tar.gz |
Merge branch 'release-2.14.0'2.14.0
Diffstat (limited to 'tests/unit/ec2/test_networkinterface.py')
-rw-r--r-- | tests/unit/ec2/test_networkinterface.py | 148 |
1 files changed, 104 insertions, 44 deletions
diff --git a/tests/unit/ec2/test_networkinterface.py b/tests/unit/ec2/test_networkinterface.py index b23f6c36..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,7 +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.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 + ) def test_param_serialization(self): collection = NetworkInterfaceCollection(self.network_interfaces_spec1, @@ -62,34 +74,33 @@ 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.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', }) def test_add_prefix_to_serialization(self): - return collection = NetworkInterfaceCollection(self.network_interfaces_spec1, self.network_interfaces_spec2) params = {} @@ -98,43 +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.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() |