OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 Amazon.com, Inc. or its affiliates. All Rights Reserved |
| 3 # |
| 4 # Permission is hereby granted, free of charge, to any person obtaining a |
| 5 # copy of this software and associated documentation files (the |
| 6 # "Software"), to deal in the Software without restriction, including |
| 7 # without limitation the rights to use, copy, modify, merge, publish, dis- |
| 8 # tribute, sublicense, and/or sell copies of the Software, and to permit |
| 9 # persons to whom the Software is furnished to do so, subject to the fol- |
| 10 # lowing conditions: |
| 11 # |
| 12 # The above copyright notice and this permission notice shall be included |
| 13 # in all copies or substantial portions of the Software. |
| 14 # |
| 15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- |
| 17 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT |
| 18 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 19 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 # IN THE SOFTWARE. |
| 22 # |
| 23 |
| 24 from tests.unit import unittest |
| 25 |
| 26 |
| 27 from boto.ec2.networkinterface import NetworkInterfaceCollection |
| 28 from boto.ec2.networkinterface import NetworkInterfaceSpecification |
| 29 from boto.ec2.networkinterface import PrivateIPAddress |
| 30 |
| 31 |
| 32 class TestNetworkInterfaceCollection(unittest.TestCase): |
| 33 maxDiff = None |
| 34 |
| 35 def setUp(self): |
| 36 self.private_ip_address1 = PrivateIPAddress( |
| 37 private_ip_address='10.0.0.10', primary=False) |
| 38 self.private_ip_address2 = PrivateIPAddress( |
| 39 private_ip_address='10.0.0.11', primary=False) |
| 40 self.network_interfaces_spec1 = NetworkInterfaceSpecification( |
| 41 device_index=1, subnet_id='subnet_id', |
| 42 description='description1', |
| 43 private_ip_address='10.0.0.54', delete_on_termination=False, |
| 44 private_ip_addresses=[self.private_ip_address1, |
| 45 self.private_ip_address2]) |
| 46 |
| 47 self.private_ip_address3 = PrivateIPAddress( |
| 48 private_ip_address='10.0.1.10', primary=False) |
| 49 self.private_ip_address4 = PrivateIPAddress( |
| 50 private_ip_address='10.0.1.11', primary=False) |
| 51 self.network_interfaces_spec2 = NetworkInterfaceSpecification( |
| 52 device_index=2, subnet_id='subnet_id2', |
| 53 description='description2', |
| 54 groups=['group_id1', 'group_id2'], |
| 55 private_ip_address='10.0.1.54', delete_on_termination=False, |
| 56 private_ip_addresses=[self.private_ip_address3, |
| 57 self.private_ip_address4]) |
| 58 |
| 59 def test_param_serialization(self): |
| 60 collection = NetworkInterfaceCollection(self.network_interfaces_spec1, |
| 61 self.network_interfaces_spec2) |
| 62 params = {} |
| 63 collection.build_list_params(params) |
| 64 self.assertDictEqual(params, { |
| 65 'NetworkInterface.1.DeviceIndex': '1', |
| 66 'NetworkInterface.1.DeleteOnTermination': 'false', |
| 67 'NetworkInterface.1.Description': 'description1', |
| 68 'NetworkInterface.1.PrivateIpAddress': '10.0.0.54', |
| 69 'NetworkInterface.1.SubnetId': 'subnet_id', |
| 70 'NetworkInterface.1.PrivateIpAddresses.1.Primary': 'false', |
| 71 'NetworkInterface.1.PrivateIpAddresses.1.PrivateIpAddress': |
| 72 '10.0.0.10', |
| 73 'NetworkInterface.1.PrivateIpAddresses.2.Primary': 'false', |
| 74 'NetworkInterface.1.PrivateIpAddresses.2.PrivateIpAddress': |
| 75 '10.0.0.11', |
| 76 'NetworkInterface.2.DeviceIndex': '2', |
| 77 'NetworkInterface.2.Description': 'description2', |
| 78 'NetworkInterface.2.DeleteOnTermination': 'false', |
| 79 'NetworkInterface.2.PrivateIpAddress': '10.0.1.54', |
| 80 'NetworkInterface.2.SubnetId': 'subnet_id2', |
| 81 'NetworkInterface.2.SecurityGroupId.1': 'group_id1', |
| 82 'NetworkInterface.2.SecurityGroupId.2': 'group_id2', |
| 83 'NetworkInterface.2.PrivateIpAddresses.1.Primary': 'false', |
| 84 'NetworkInterface.2.PrivateIpAddresses.1.PrivateIpAddress': |
| 85 '10.0.1.10', |
| 86 'NetworkInterface.2.PrivateIpAddresses.2.Primary': 'false', |
| 87 'NetworkInterface.2.PrivateIpAddresses.2.PrivateIpAddress': |
| 88 '10.0.1.11', |
| 89 }) |
| 90 |
| 91 def test_add_prefix_to_serialization(self): |
| 92 return |
| 93 collection = NetworkInterfaceCollection(self.network_interfaces_spec1, |
| 94 self.network_interfaces_spec2) |
| 95 params = {} |
| 96 collection.build_list_params(params, prefix='LaunchSpecification.') |
| 97 # We already tested the actual serialization previously, so |
| 98 # we're just checking a few keys to make sure we get the proper |
| 99 # prefix. |
| 100 self.assertDictEqual(params, { |
| 101 'LaunchSpecification.NetworkInterface.1.DeviceIndex': '1', |
| 102 'LaunchSpecification.NetworkInterface.1.DeleteOnTermination': |
| 103 'false', |
| 104 'LaunchSpecification.NetworkInterface.1.Description': |
| 105 'description1', |
| 106 'LaunchSpecification.NetworkInterface.1.PrivateIpAddress': |
| 107 '10.0.0.54', |
| 108 'LaunchSpecification.NetworkInterface.1.SubnetId': 'subnet_id', |
| 109 'LaunchSpecification.NetworkInterface.1.PrivateIpAddresses.1.Primary
': |
| 110 'false', |
| 111 'LaunchSpecification.NetworkInterface.1.PrivateIpAddresses.1.Private
IpAddress': |
| 112 '10.0.0.10', |
| 113 'LaunchSpecification.NetworkInterface.1.PrivateIpAddresses.2.Primary
': 'false', |
| 114 'LaunchSpecification.NetworkInterface.1.PrivateIpAddresses.2.Private
IpAddress': |
| 115 '10.0.0.11', |
| 116 'LaunchSpecification.NetworkInterface.2.DeviceIndex': '2', |
| 117 'LaunchSpecification.NetworkInterface.2.Description': |
| 118 'description2', |
| 119 'LaunchSpecification.NetworkInterface.2.DeleteOnTermination': |
| 120 'false', |
| 121 'LaunchSpecification.NetworkInterface.2.PrivateIpAddress': |
| 122 '10.0.1.54', |
| 123 'LaunchSpecification.NetworkInterface.2.SubnetId': 'subnet_id2', |
| 124 'LaunchSpecification.NetworkInterface.2.SecurityGroupId.1': |
| 125 'group_id1', |
| 126 'LaunchSpecification.NetworkInterface.2.SecurityGroupId.2': |
| 127 'group_id2', |
| 128 'LaunchSpecification.NetworkInterface.2.PrivateIpAddresses.1.Primary
': |
| 129 'false', |
| 130 'LaunchSpecification.NetworkInterface.2.PrivateIpAddresses.1.Private
IpAddress': |
| 131 '10.0.1.10', |
| 132 'LaunchSpecification.NetworkInterface.2.PrivateIpAddresses.2.Primary
': |
| 133 'false', |
| 134 'LaunchSpecification.NetworkInterface.2.PrivateIpAddresses.2.Private
IpAddress': |
| 135 '10.0.1.11', |
| 136 }) |
| 137 |
| 138 |
| 139 if __name__ == '__main__': |
| 140 unittest.main() |
OLD | NEW |