Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: third_party/gsutil/boto/tests/integration/ec2/vpc/test_connection.py

Issue 12317103: Added gsutil to depot tools (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: added readme Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 import unittest
24 import time
25
26 import boto
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 TestVPCConnection(unittest.TestCase):
33 def setUp(self):
34 self.api = boto.connect_vpc()
35 vpc = self.api.create_vpc('10.0.0.0/16')
36 self.addCleanup(self.api.delete_vpc, vpc.id)
37
38 self.subnet = self.api.create_subnet(vpc.id, '10.0.0.0/24')
39 self.addCleanup(self.api.delete_subnet, self.subnet.id)
40
41 def terminate_instance(self, instance):
42 instance.terminate()
43 for i in xrange(300):
44 instance.update()
45 if instance.state == 'terminated':
46 # Give it a litle more time to settle.
47 time.sleep(10)
48 return
49 else:
50 time.sleep(10)
51
52 def test_multi_ip_create(self):
53 interface = NetworkInterfaceSpecification(
54 device_index=0, subnet_id=self.subnet.id,
55 private_ip_address='10.0.0.21',
56 description="This is a test interface using boto.",
57 delete_on_termination=True, private_ip_addresses=[
58 PrivateIPAddress(private_ip_address='10.0.0.22',
59 primary=False),
60 PrivateIPAddress(private_ip_address='10.0.0.23',
61 primary=False),
62 PrivateIPAddress(private_ip_address='10.0.0.24',
63 primary=False)])
64 interfaces = NetworkInterfaceCollection(interface)
65
66 reservation = self.api.run_instances(image_id='ami-a0cd60c9', instance_t ype='m1.small',
67 network_interfaces=interfaces)
68 # Give it a few seconds to start up.
69 time.sleep(10)
70 instance = reservation.instances[0]
71 self.addCleanup(self.terminate_instance, instance)
72 retrieved = self.api.get_all_instances(instance_ids=[instance.id])
73 self.assertEqual(len(retrieved), 1)
74 retrieved_instances = retrieved[0].instances
75 self.assertEqual(len(retrieved_instances), 1)
76 retrieved_instance = retrieved_instances[0]
77
78 self.assertEqual(len(retrieved_instance.interfaces), 1)
79 interface = retrieved_instance.interfaces[0]
80
81 private_ip_addresses = interface.private_ip_addresses
82 self.assertEqual(len(private_ip_addresses), 4)
83 self.assertEqual(private_ip_addresses[0].private_ip_address,
84 '10.0.0.21')
85 self.assertEqual(private_ip_addresses[0].primary, True)
86 self.assertEqual(private_ip_addresses[1].private_ip_address,
87 '10.0.0.22')
88 self.assertEqual(private_ip_addresses[2].private_ip_address,
89 '10.0.0.23')
90 self.assertEqual(private_ip_addresses[3].private_ip_address,
91 '10.0.0.24')
92
93
94 if __name__ == '__main__':
95 unittest.main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698