summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorghanshyam <gmann@ghanshyammann.com>2018-01-30 07:33:41 +0000
committerGhanshyam Mann <gmann@ghanshyammann.com>2018-03-18 03:27:03 +0000
commitf5983d7cdc54375e33aa3c4311e94410b9288626 (patch)
treebf8da513a5d704af8f20810d0e04fc9262619e7e
parent30ae9db6a1033843c8bf3cd5da2eb457a2758d8f (diff)
Remove intree ec2-api tempest tests
ec2-api jobs have been switched to use ec2api-tempest-plugin for ec2-api tests, so we can remove the in-tree tempest tests now. Change-Id: I82ace9ebd1ca5216c2e3fc3d75f07146417ebf94
Notes
Notes (review): Code-Review+2: Andrey Pavlov <andrey.mp@gmail.com> Workflow+1: Andrey Pavlov <andrey.mp@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Thu, 22 Mar 2018 08:13:56 +0000 Reviewed-on: https://review.openstack.org/539122 Project: openstack/ec2-api Branch: refs/heads/master
-rw-r--r--ec2api/tests/botocoreclient.py (renamed from ec2api/tests/functional/botocoreclient.py)0
-rw-r--r--ec2api/tests/functional/__init__.py0
-rw-r--r--ec2api/tests/functional/api/__init__.py0
-rw-r--r--ec2api/tests/functional/api/test_addresses.py436
-rw-r--r--ec2api/tests/functional/api/test_customer_gateways.py57
-rw-r--r--ec2api/tests/functional/api/test_dhcp_options.py182
-rw-r--r--ec2api/tests/functional/api/test_images.py359
-rw-r--r--ec2api/tests/functional/api/test_instance_attributes.py365
-rw-r--r--ec2api/tests/functional/api/test_instances.py252
-rw-r--r--ec2api/tests/functional/api/test_instances_ebs.py92
-rw-r--r--ec2api/tests/functional/api/test_instances_vpc.py282
-rw-r--r--ec2api/tests/functional/api/test_internet_gateways.py223
-rw-r--r--ec2api/tests/functional/api/test_key_pairs.py149
-rw-r--r--ec2api/tests/functional/api/test_network_interfaces.py582
-rw-r--r--ec2api/tests/functional/api/test_regions.py47
-rw-r--r--ec2api/tests/functional/api/test_routes.py338
-rw-r--r--ec2api/tests/functional/api/test_security_groups.py324
-rw-r--r--ec2api/tests/functional/api/test_snapshots.py267
-rw-r--r--ec2api/tests/functional/api/test_subnets.py191
-rw-r--r--ec2api/tests/functional/api/test_tags.py509
-rw-r--r--ec2api/tests/functional/api/test_volumes.py411
-rw-r--r--ec2api/tests/functional/api/test_vpcs.py208
-rw-r--r--ec2api/tests/functional/api/test_vpn_connections.py113
-rw-r--r--ec2api/tests/functional/api/test_vpn_gateways.py93
-rw-r--r--ec2api/tests/functional/base.py888
-rw-r--r--ec2api/tests/functional/config.py89
-rw-r--r--ec2api/tests/functional/config_opts.py96
-rw-r--r--ec2api/tests/functional/obsolete/base.py86
-rw-r--r--ec2api/tests/functional/obsolete/thirdparty/scenario/aws_compat/base.py361
-rw-r--r--ec2api/tests/functional/obsolete/thirdparty/scenario/aws_compat/test_ec2_instance_mysql.py225
-rw-r--r--ec2api/tests/functional/obsolete/thirdparty/scenario/aws_compat/test_ec2_unixbench.py110
-rw-r--r--ec2api/tests/functional/obsolete/thirdparty/scenario/aws_compat/test_ec2_volume_benchmark.py250
-rw-r--r--ec2api/tests/functional/obsolete/thirdparty/scenario/aws_compat/test_vpc_behavior.py297
-rw-r--r--ec2api/tests/functional/obsolete/thirdparty/scenario/aws_compat/test_vpc_benchmark.py188
-rw-r--r--ec2api/tests/functional/obsolete/thirdparty/scenario/aws_compat/test_vpc_nat_scenario.py451
-rw-r--r--ec2api/tests/functional/obsolete/thirdparty/scenario/aws_compat/test_vpc_scenario.py379
-rw-r--r--ec2api/tests/functional/obsolete/utils.py35
-rw-r--r--ec2api/tests/functional/plugin.py52
-rw-r--r--ec2api/tests/functional/scenario/__init__.py0
-rw-r--r--ec2api/tests/functional/scenario/base.py135
-rw-r--r--ec2api/tests/functional/scenario/test_ebs_instances.py455
-rw-r--r--ec2api/tests/functional/scenario/test_instance_restart.py95
-rw-r--r--ec2api/tests/functional/scenario/test_instances.py180
-rw-r--r--ec2api/tests/functional/scenario/test_instances_in_vpc.py170
-rw-r--r--ec2api/tests/functional/scenario/test_paging.py410
-rw-r--r--ec2api/tests/functional/scenario/test_vpc_addresses.py157
-rw-r--r--ec2api/tests/functional/scenario/test_vpn.py278
-rw-r--r--rally-scenarios/plugins/context_plugin_ec2_objects.py2
-rw-r--r--rally-scenarios/plugins/context_plugin_images.py2
-rw-r--r--rally-scenarios/plugins/ec2api_plugin.py3
-rw-r--r--setup.cfg3
-rw-r--r--tox.ini2
52 files changed, 5 insertions, 10874 deletions
diff --git a/ec2api/tests/functional/botocoreclient.py b/ec2api/tests/botocoreclient.py
index 848be8c..848be8c 100644
--- a/ec2api/tests/functional/botocoreclient.py
+++ b/ec2api/tests/botocoreclient.py
diff --git a/ec2api/tests/functional/__init__.py b/ec2api/tests/functional/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/ec2api/tests/functional/__init__.py
+++ /dev/null
diff --git a/ec2api/tests/functional/api/__init__.py b/ec2api/tests/functional/api/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/ec2api/tests/functional/api/__init__.py
+++ /dev/null
diff --git a/ec2api/tests/functional/api/test_addresses.py b/ec2api/tests/functional/api/test_addresses.py
deleted file mode 100644
index 534dc1c..0000000
--- a/ec2api/tests/functional/api/test_addresses.py
+++ /dev/null
@@ -1,436 +0,0 @@
1# Copyright 2014 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16import time
17
18import botocore.exceptions
19from oslo_log import log
20from tempest.lib import decorators
21import testtools
22
23from ec2api.tests.functional import base
24from ec2api.tests.functional import config
25
26CONF = config.CONF
27LOG = log.getLogger(__name__)
28
29
30class AddressTest(base.EC2TestCase):
31
32 @base.skip_without_vpc()
33 @decorators.idempotent_id('218a4b6b-c3a9-44b0-8148-4bd0bc36bd7d')
34 def test_create_delete_vpc_address(self):
35 kwargs = {
36 'Domain': 'vpc',
37 }
38 data = self.client.allocate_address(*[], **kwargs)
39 id = data['AllocationId']
40 res_clean = self.addResourceCleanUp(self.client.release_address,
41 AllocationId=id)
42 self.assertEqual('vpc', data['Domain'])
43
44 data = self.client.release_address(AllocationId=id)
45 self.cancelResourceCleanUp(res_clean)
46
47 @base.skip_without_ec2()
48 @decorators.idempotent_id('285b8b4e-5aef-4e7f-be9e-37e6475be21b')
49 def test_create_delete_standard_address(self):
50 data = self.client.allocate_address()
51 ip = data['PublicIp']
52 res_clean = self.addResourceCleanUp(self.client.release_address,
53 PublicIp=ip)
54
55 data = self.client.release_address(PublicIp=ip)
56 self.cancelResourceCleanUp(res_clean)
57
58 @base.skip_without_vpc()
59 @decorators.idempotent_id('5be3ad8d-b071-472b-b92a-7199c82334a2')
60 def test_invalid_delete_vpc_address(self):
61 kwargs = {
62 'Domain': 'vpc',
63 }
64 data = self.client.allocate_address(*[], **kwargs)
65 ip = data['PublicIp']
66 id = data['AllocationId']
67 res_clean = self.addResourceCleanUp(self.client.release_address,
68 AllocationId=id)
69 self.assertEqual('vpc', data['Domain'])
70
71 self.assertRaises('InvalidParameterCombination',
72 self.client.release_address,
73 PublicIp=ip, AllocationId=id)
74
75 self.assertRaises('InvalidParameterValue',
76 self.client.release_address,
77 PublicIp=ip)
78
79 data = self.client.release_address(AllocationId=id)
80 self.cancelResourceCleanUp(res_clean)
81
82 if CONF.aws.run_incompatible_tests:
83 self.assertRaises('AuthFailure',
84 self.client.release_address,
85 PublicIp=ip)
86
87 self.assertRaises('InvalidAllocationID.NotFound',
88 self.client.release_address,
89 AllocationId=id)
90
91 kwargs = {
92 "AllocationId": 'eipalloc-00000000',
93 }
94 self.assertRaises('InvalidAllocationID.NotFound',
95 self.client.release_address,
96 **kwargs)
97
98 if CONF.aws.run_incompatible_tests:
99 self.assertRaises('InvalidParameterValue',
100 self.client.release_address,
101 PublicIp='ip')
102
103 @decorators.idempotent_id('e8171637-9ccd-471a-97da-c78a36ba3c4b')
104 def test_invalid_create_address(self):
105 kwargs = {
106 'Domain': 'invalid',
107 }
108 try:
109 data = self.client.allocate_address(*[], **kwargs)
110 allocation_id = data.get('AllocationId')
111 if allocation_id:
112 self.client.release_address(AllocationId=allocation_id)
113 else:
114 public_ip = data.get('PublicIp')
115 self.client.release_address(PublicIp=public_ip)
116 except botocore.exceptions.ClientError as e:
117 self.assertEqual('InvalidParameterValue',
118 e.response['Error']['Code'])
119
120 @base.skip_without_vpc()
121 @decorators.idempotent_id('b0d0b498-1fe2-479e-995c-80ace2f339a7')
122 def test_describe_vpc_addresses(self):
123 kwargs = {
124 'Domain': 'vpc',
125 }
126 data = self.client.allocate_address(*[], **kwargs)
127 ip = data['PublicIp']
128 id = data['AllocationId']
129 res_clean = self.addResourceCleanUp(self.client.release_address,
130 AllocationId=id)
131
132 data = self.client.describe_addresses(*[], **{})
133 for address in data['Addresses']:
134 if address.get('AllocationId') == id:
135 self.assertEqual('vpc', address['Domain'])
136 self.assertEqual(ip, address['PublicIp'])
137 break
138 else:
139 self.fail('Created address could not be found')
140
141 kwargs = {
142 'PublicIps': [ip],
143 }
144 data = self.client.describe_addresses(*[], **kwargs)
145 self.assertEqual(1, len(data['Addresses']))
146 self.assertEqual(id, data['Addresses'][0]['AllocationId'])
147
148 kwargs = {
149 'AllocationIds': [id],
150 }
151 data = self.client.describe_addresses(*[], **kwargs)
152 self.assertEqual(1, len(data['Addresses']))
153 self.assertEqual(ip, data['Addresses'][0]['PublicIp'])
154
155 kwargs = {
156 'PublicIps': ['invalidIp'],
157 }
158 self.assertRaises('InvalidParameterValue',
159 self.client.describe_addresses,
160 **kwargs)
161
162 kwargs = {
163 'AllocationIds': ['eipalloc-00000000'],
164 }
165 self.assertRaises('InvalidAllocationID.NotFound',
166 self.client.describe_addresses,
167 **kwargs)
168
169 kwargs = {
170 'Domain': 'vpc',
171 }
172 data = self.client.allocate_address(*[], **kwargs)
173 id2 = data['AllocationId']
174 res_clean2 = self.addResourceCleanUp(self.client.release_address,
175 AllocationId=id2)
176
177 kwargs = {
178 'PublicIps': [ip],
179 'AllocationIds': [id2],
180 }
181 data = self.client.describe_addresses(*[], **kwargs)
182 self.assertEqual(2, len(data['Addresses']))
183
184 # NOTE(andrey-mp): wait abit before releasing
185 time.sleep(3)
186
187 self.client.release_address(AllocationId=id)
188 self.cancelResourceCleanUp(res_clean)
189
190 self.client.release_address(AllocationId=id2)
191 self.cancelResourceCleanUp(res_clean2)
192
193 @base.skip_without_ec2()
194 @decorators.idempotent_id('a5c09f47-3be3-4d46-b59d-25195d67e6d5')
195 def test_describe_standard_addresses(self):
196 data = self.client.allocate_address(*[], **{})
197 ip = data['PublicIp']
198 res_clean = self.addResourceCleanUp(self.client.release_address,
199 PublicIp=ip)
200
201 data = self.client.describe_addresses(*[], **{})
202 for address in data['Addresses']:
203 if address['PublicIp'] == ip:
204 self.assertEqual('standard', address['Domain'])
205 break
206 else:
207 self.fail('Created address could not be found')
208
209 kwargs = {
210 'PublicIps': [ip],
211 }
212 data = self.client.describe_addresses(*[], **kwargs)
213 self.assertEqual(1, len(data['Addresses']))
214 self.assertEqual(ip, data['Addresses'][0]['PublicIp'])
215
216 kwargs = {
217 'PublicIps': ['invalidIp'],
218 }
219 self.assertRaises('InvalidParameterValue',
220 self.client.describe_addresses,
221 PublicIps=['invalidIp'])
222
223 # NOTE(andrey-mp): wait abit before releasing
224 time.sleep(3)
225
226 self.client.release_address(PublicIp=ip)
227 self.cancelResourceCleanUp(res_clean)
228
229 @base.skip_without_vpc()
230 @decorators.idempotent_id('6f154e48-f260-4d8d-b1d1-a1cf174f58fa')
231 @testtools.skipUnless(CONF.aws.image_id, "image id is not defined")
232 def test_associate_disassociate_vpc_addresses(self):
233 aws_zone = CONF.aws.aws_zone
234
235 base_net = '10.3.0.0'
236 data = self.client.create_vpc(CidrBlock=base_net + '/20')
237 vpc_id = data['Vpc']['VpcId']
238 clean_vpc = self.addResourceCleanUp(self.client.delete_vpc,
239 VpcId=vpc_id)
240 self.get_vpc_waiter().wait_available(vpc_id)
241
242 cidr = base_net + '/24'
243 data = self.client.create_subnet(VpcId=vpc_id, CidrBlock=cidr,
244 AvailabilityZone=aws_zone)
245 subnet_id = data['Subnet']['SubnetId']
246 clean_subnet = self.addResourceCleanUp(self.client.delete_subnet,
247 SubnetId=subnet_id)
248
249 instance_id = self.run_instance(SubnetId=subnet_id)
250
251 data = self.client.allocate_address(Domain='vpc')
252 alloc_id = data['AllocationId']
253 clean_a = self.addResourceCleanUp(self.client.release_address,
254 AllocationId=alloc_id)
255
256 self.assertRaises('Gateway.NotAttached',
257 self.client.associate_address,
258 InstanceId=instance_id, AllocationId=alloc_id)
259
260 # Create internet gateway and try to associate again
261 data = self.client.create_internet_gateway()
262 gw_id = data['InternetGateway']['InternetGatewayId']
263 clean_ig = self.addResourceCleanUp(self.client.delete_internet_gateway,
264 InternetGatewayId=gw_id)
265 data = self.client.attach_internet_gateway(VpcId=vpc_id,
266 InternetGatewayId=gw_id)
267 clean_aig = self.addResourceCleanUp(
268 self.client.detach_internet_gateway,
269 VpcId=vpc_id,
270 InternetGatewayId=gw_id)
271
272 self.prepare_route(vpc_id, gw_id)
273
274 data = self.client.associate_address(InstanceId=instance_id,
275 AllocationId=alloc_id)
276 assoc_id = data['AssociationId']
277 clean_aa = self.addResourceCleanUp(self.client.disassociate_address,
278 AssociationId=assoc_id)
279 self.get_address_assoc_waiter().wait_available(
280 {'AllocationId': alloc_id})
281
282 kwargs = {
283 'AllocationIds': [alloc_id],
284 }
285 data = self.client.describe_addresses(*[], **kwargs)
286 self.assertEqual(instance_id, data['Addresses'][0]['InstanceId'])
287
288 data = self.client.disassociate_address(AssociationId=assoc_id)
289 self.cancelResourceCleanUp(clean_aa)
290 self.get_address_assoc_waiter().wait_delete({'AllocationId': alloc_id})
291
292 # NOTE(andrey-mp): cleanup
293 time.sleep(3)
294
295 self.client.detach_internet_gateway(VpcId=vpc_id,
296 InternetGatewayId=gw_id)
297 self.cancelResourceCleanUp(clean_aig)
298
299 self.client.delete_internet_gateway(InternetGatewayId=gw_id)
300 self.cancelResourceCleanUp(clean_ig)
301
302 self.client.release_address(AllocationId=alloc_id)
303 self.cancelResourceCleanUp(clean_a)
304
305 self.client.terminate_instances(InstanceIds=[instance_id])
306 self.get_instance_waiter().wait_delete(instance_id)
307
308 self.client.delete_subnet(SubnetId=subnet_id)
309 self.cancelResourceCleanUp(clean_subnet)
310 self.get_subnet_waiter().wait_delete(subnet_id)
311
312 self.client.delete_vpc(VpcId=vpc_id)
313 self.cancelResourceCleanUp(clean_vpc)
314 self.get_vpc_waiter().wait_delete(vpc_id)
315
316 @decorators.idempotent_id('4aaf01d2-ade5-4e8b-b24a-ab22448b3236')
317 @testtools.skipUnless(CONF.aws.image_id, "image id is not defined")
318 # skip this test for nova network due to bug #1607350
319 @base.skip_without_vpc()
320 # this is a correct skip
321 @base.skip_without_ec2()
322 def test_associate_disassociate_standard_addresses(self):
323 instance_id = self.run_instance()
324
325 data = self.client.allocate_address(*[], **{})
326 ip = data['PublicIp']
327 clean_a = self.addResourceCleanUp(self.client.release_address,
328 PublicIp=ip)
329
330 data = self.client.associate_address(InstanceId=instance_id,
331 PublicIp=ip)
332 clean_aa = self.addResourceCleanUp(self.client.disassociate_address,
333 PublicIp=ip)
334 self.get_address_assoc_waiter().wait_available({'PublicIp': ip})
335
336 kwargs = {
337 'PublicIps': [ip],
338 }
339 data = self.client.describe_addresses(*[], **kwargs)
340 self.assertEqual(instance_id, data['Addresses'][0]['InstanceId'])
341
342 data = self.client.disassociate_address(PublicIp=ip)
343 self.cancelResourceCleanUp(clean_aa)
344 self.get_address_assoc_waiter().wait_delete({'PublicIp': ip})
345
346 time.sleep(3)
347
348 data = self.client.release_address(PublicIp=ip)
349 self.cancelResourceCleanUp(clean_a)
350
351 data = self.client.terminate_instances(InstanceIds=[instance_id])
352 self.get_instance_waiter().wait_delete(instance_id)
353
354 @base.skip_without_vpc()
355 @decorators.idempotent_id('3c0ab7f5-ee9c-4966-8d43-e89f5520f245')
356 def test_disassociate_not_associated_vpc_addresses(self):
357 aws_zone = CONF.aws.aws_zone
358
359 base_net = '10.3.0.0'
360 data = self.client.create_vpc(CidrBlock=base_net + '/20')
361 vpc_id = data['Vpc']['VpcId']
362 clean_vpc = self.addResourceCleanUp(self.client.delete_vpc,
363 VpcId=vpc_id)
364 self.get_vpc_waiter().wait_available(vpc_id)
365
366 cidr = base_net + '/24'
367 data = self.client.create_subnet(VpcId=vpc_id, CidrBlock=cidr,
368 AvailabilityZone=aws_zone)
369 subnet_id = data['Subnet']['SubnetId']
370 clean_subnet = self.addResourceCleanUp(self.client.delete_subnet,
371 SubnetId=subnet_id)
372
373 data = self.client.allocate_address(Domain='vpc')
374 alloc_id = data['AllocationId']
375 ip = data['PublicIp']
376 clean_a = self.addResourceCleanUp(self.client.release_address,
377 AllocationId=alloc_id)
378
379 assoc_id = 'eipassoc-00000001'
380 self.assertRaises('InvalidAssociationID.NotFound',
381 self.client.disassociate_address,
382 AssociationId=assoc_id)
383
384 self.assertRaises('InvalidParameterValue',
385 self.client.disassociate_address,
386 PublicIp=ip)
387
388 self.client.release_address(AllocationId=alloc_id)
389 self.cancelResourceCleanUp(clean_a)
390
391 self.client.delete_subnet(SubnetId=subnet_id)
392 self.cancelResourceCleanUp(clean_subnet)
393 self.get_subnet_waiter().wait_delete(subnet_id)
394
395 self.client.delete_vpc(VpcId=vpc_id)
396 self.cancelResourceCleanUp(clean_vpc)
397 self.get_vpc_waiter().wait_delete(vpc_id)
398
399 @base.skip_without_ec2()
400 @decorators.idempotent_id('a70babef-18ec-4340-a3a2-63388cfc3cb5')
401 def test_disassociate_not_associated_standard_addresses(self):
402 data = self.client.allocate_address(Domain='standard')
403 ip = data['PublicIp']
404 clean_a = self.addResourceCleanUp(self.client.release_address,
405 PublicIp=ip)
406
407 data = self.client.disassociate_address(PublicIp=ip)
408
409 data = self.client.release_address(PublicIp=ip)
410 self.cancelResourceCleanUp(clean_a)
411
412 @base.skip_without_vpc()
413 @decorators.idempotent_id('91b971f5-2674-478e-84df-115fef506c5b')
414 @testtools.skipUnless(CONF.aws.run_incompatible_tests,
415 'preliminary address association is not supported')
416 def test_preliminary_associate_address(self):
417 # NOTE(ft): AWS can associate an address to a subnet IP if the subnet
418 # has no internet access
419 vpc_id, subnet_id = self.create_vpc_and_subnet('10.3.0.0/20')
420 self.create_and_attach_internet_gateway(vpc_id)
421 data = self.client.allocate_address(Domain='vpc')
422 alloc_id = data['AllocationId']
423 self.addResourceCleanUp(self.client.release_address,
424 AllocationId=alloc_id)
425
426 data = self.client.create_network_interface(SubnetId=subnet_id)
427 ni_id = data['NetworkInterface']['NetworkInterfaceId']
428 self.addResourceCleanUp(self.client.delete_network_interface,
429 NetworkInterfaceId=ni_id)
430 self.get_network_interface_waiter().wait_available(ni_id)
431
432 data = self.client.associate_address(
433 AllocationId=alloc_id, NetworkInterfaceId=ni_id)
434 assoc_id = data['AssociationId']
435 self.addResourceCleanUp(self.client.disassociate_address,
436 AssociationId=assoc_id)
diff --git a/ec2api/tests/functional/api/test_customer_gateways.py b/ec2api/tests/functional/api/test_customer_gateways.py
deleted file mode 100644
index 4b5519d..0000000
--- a/ec2api/tests/functional/api/test_customer_gateways.py
+++ /dev/null
@@ -1,57 +0,0 @@
1# Copyright 2014 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16import botocore.exceptions
17from tempest.lib import decorators
18
19from ec2api.tests.functional import base
20from ec2api.tests.functional import config
21
22CONF = config.CONF
23
24
25class CustomerGatewayTest(base.EC2TestCase):
26
27 CUSTOMER_GATEWAY_IP = '198.51.100.77'
28
29 @classmethod
30 @base.safe_setup
31 def setUpClass(cls):
32 super(CustomerGatewayTest, cls).setUpClass()
33 if not base.TesterStateHolder().get_vpc_enabled():
34 raise cls.skipException('VPC is disabled')
35 base.check_network_feature_enabled('vpnaas')
36
37 @decorators.idempotent_id('54a40b66-1675-44b1-938d-0cad2eb6afe4')
38 def test_create_delete_customer_gateway(self):
39 data = self.client.create_customer_gateway(
40 Type='ipsec.1', PublicIp=self.CUSTOMER_GATEWAY_IP, BgpAsn=65000)
41 cgw_id = data['CustomerGateway']['CustomerGatewayId']
42 cgw_clean = self.addResourceCleanUp(
43 self.client.delete_customer_gateway, CustomerGatewayId=cgw_id)
44 self.assertEqual(self.CUSTOMER_GATEWAY_IP,
45 data['CustomerGateway']['IpAddress'])
46
47 self.client.delete_customer_gateway(CustomerGatewayId=cgw_id)
48 self.cancelResourceCleanUp(cgw_clean)
49
50 try:
51 data = self.client.describe_customer_gateways(
52 CustomerGatewayIds=[cgw_id])
53 self.assertEqual(1, len(data['CustomerGateways']))
54 self.assertEqual('deleted', data['CustomerGateways'][0]['State'])
55 except botocore.exceptions.ClientError as ex:
56 self.assertEqual('InvalidCustomerGatewayID.NotFound',
57 ex.response['Error']['Code'])
diff --git a/ec2api/tests/functional/api/test_dhcp_options.py b/ec2api/tests/functional/api/test_dhcp_options.py
deleted file mode 100644
index bc939c5..0000000
--- a/ec2api/tests/functional/api/test_dhcp_options.py
+++ /dev/null
@@ -1,182 +0,0 @@
1# Copyright 2014 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16import time
17
18from oslo_log import log
19from tempest.lib import decorators
20
21from ec2api.tests.functional import base
22from ec2api.tests.functional import config
23
24CONF = config.CONF
25LOG = log.getLogger(__name__)
26
27
28class DhcpOptionsTest(base.EC2TestCase):
29
30 @classmethod
31 @base.safe_setup
32 def setUpClass(cls):
33 super(DhcpOptionsTest, cls).setUpClass()
34 if not base.TesterStateHolder().get_vpc_enabled():
35 raise cls.skipException('VPC is disabled')
36
37 @decorators.idempotent_id('2331fc49-50e0-4df3-8c45-bd6f61cc86bf')
38 def test_create_delete_dhcp_options(self):
39 kwargs = {
40 'DhcpConfigurations': [
41 {'Key': 'domain-name',
42 'Values': ['my.com', 'it.com']},
43 {'Key': 'domain-name-servers',
44 'Values': ['8.8.8.8', '8.8.4.4']},
45 {'Key': 'ntp-servers',
46 'Values': ['1.2.3.4']},
47 {'Key': 'netbios-name-servers',
48 'Values': ['4.3.2.1']},
49 {'Key': 'netbios-node-type',
50 'Values': ['2']},
51 ],
52 }
53 data = self.client.create_dhcp_options(*[], **kwargs)
54 options = data['DhcpOptions']
55 id = options['DhcpOptionsId']
56 res_clean = self.addResourceCleanUp(self.client.delete_dhcp_options,
57 DhcpOptionsId=id)
58 self.assertEqual(5, len(options['DhcpConfigurations']))
59 for cfg in options['DhcpConfigurations']:
60 self.assertEqual(2, len(cfg))
61 if cfg['Key'] == 'domain-name':
62 self.assertEqual(2, len(cfg['Values']))
63 values = [i['Value'] for i in cfg['Values']]
64 self.assertIn('my.com', values)
65 self.assertIn('it.com', values)
66 elif cfg['Key'] == 'domain-name-servers':
67 self.assertEqual(2, len(cfg['Values']))
68 values = [i['Value'] for i in cfg['Values']]
69 self.assertIn('8.8.8.8', values)
70 self.assertIn('8.8.4.4', values)
71 elif cfg['Key'] == 'ntp-servers':
72 self.assertEqual(1, len(cfg['Values']))
73 self.assertEqual('1.2.3.4', cfg['Values'][0]['Value'])
74 elif cfg['Key'] == 'netbios-name-servers':
75 self.assertEqual(1, len(cfg['Values']))
76 self.assertEqual('4.3.2.1', cfg['Values'][0]['Value'])
77 elif cfg['Key'] == 'netbios-node-type':
78 self.assertEqual(1, len(cfg['Values']))
79 self.assertEqual('2', cfg['Values'][0]['Value'])
80 else:
81 self.fail('Unknown key name in result - %s' % cfg['Key'])
82
83 data = self.client.delete_dhcp_options(DhcpOptionsId=id)
84 self.cancelResourceCleanUp(res_clean)
85
86 @decorators.idempotent_id('ff1d4f6e-97fc-4053-b98f-ff59e7e8d061')
87 def test_invalid_create_delete(self):
88 def _rollback(fn_data):
89 self.client.delete_dhcp_options(
90 DhcpOptionsId=fn_data['DhcpOptions']['DhcpOptionsId'])
91
92 kwargs = {
93 'DhcpConfigurations': [
94 ],
95 }
96 self.assertRaises('MissingParameter',
97 self.client.create_dhcp_options,
98 **kwargs)
99
100 kwargs = {
101 'DhcpConfigurations': [{'Key': 'aaa', 'Values': []}],
102 }
103 self.assertRaises('InvalidParameterValue',
104 self.client.create_dhcp_options, rollback_fn=_rollback,
105 **kwargs)
106
107 kwargs = {
108 'DhcpConfigurations': [{'Key': 'domain-name', 'Values': []}],
109 }
110 self.assertRaises('InvalidParameterValue',
111 self.client.create_dhcp_options, rollback_fn=_rollback,
112 **kwargs)
113
114 @decorators.idempotent_id('1c3e8ff9-bb3b-40ba-889e-d2306a92f418')
115 def test_describe_dhcp_options(self):
116 kwargs = {
117 'DhcpConfigurations': [
118 {'Key': 'domain-name',
119 'Values': ['my.com']},
120 ],
121 }
122 data = self.client.create_dhcp_options(*[], **kwargs)
123 options = data['DhcpOptions']
124 id = options['DhcpOptionsId']
125 res_clean = self.addResourceCleanUp(self.client.delete_dhcp_options,
126 DhcpOptionsId=id)
127
128 time.sleep(10)
129
130 kwargs = {
131 'DhcpOptionsIds': [id],
132 }
133 data = self.client.describe_dhcp_options(*[], **kwargs)
134 self.assertEqual(1, len(data['DhcpOptions']))
135 options = data['DhcpOptions'][0]
136 self.assertEqual(id, options['DhcpOptionsId'])
137 self.assertEqual(1, len(options['DhcpConfigurations']))
138 cfg = options['DhcpConfigurations'][0]
139 self.assertEqual(2, len(cfg))
140 self.assertEqual('domain-name', cfg['Key'])
141 self.assertEqual(1, len(cfg['Values']))
142 self.assertIn('my.com', cfg['Values'][0]['Value'])
143
144 data = self.client.delete_dhcp_options(DhcpOptionsId=id)
145 self.cancelResourceCleanUp(res_clean)
146
147 @decorators.idempotent_id('1b4d678a-c2a2-4c73-9e62-789fe2f6b173')
148 def test_associate_dhcp_options(self):
149 kwargs = {
150 'DhcpConfigurations': [
151 {'Key': 'domain-name',
152 'Values': ['my.com']},
153 ],
154 }
155 data = self.client.create_dhcp_options(*[], **kwargs)
156 options = data['DhcpOptions']
157 id = options['DhcpOptionsId']
158 res_clean = self.addResourceCleanUp(self.client.delete_dhcp_options,
159 DhcpOptionsId=id)
160
161 cidr = '10.0.0.0/24'
162 data = self.client.create_vpc(CidrBlock=cidr)
163 vpc_id = data['Vpc']['VpcId']
164 dv_clean = self.addResourceCleanUp(self.client.delete_vpc,
165 VpcId=vpc_id)
166
167 kwargs = {
168 'DhcpOptionsId': id,
169 'VpcId': vpc_id,
170 }
171 data = self.client.associate_dhcp_options(*[], **kwargs)
172
173 self.assertRaises('DependencyViolation',
174 self.client.delete_dhcp_options,
175 DhcpOptionsId=id)
176
177 data = self.client.delete_vpc(VpcId=vpc_id)
178 self.cancelResourceCleanUp(dv_clean)
179 self.get_vpc_waiter().wait_delete(vpc_id)
180
181 data = self.client.delete_dhcp_options(DhcpOptionsId=id)
182 self.cancelResourceCleanUp(res_clean)
diff --git a/ec2api/tests/functional/api/test_images.py b/ec2api/tests/functional/api/test_images.py
deleted file mode 100644
index 7f7bb60..0000000
--- a/ec2api/tests/functional/api/test_images.py
+++ /dev/null
@@ -1,359 +0,0 @@
1# Copyright 2014 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from tempest.lib.common.utils import data_utils
17from tempest.lib import decorators
18import testtools
19
20from ec2api.tests.functional import base
21from ec2api.tests.functional import config
22
23CONF = config.CONF
24
25
26class ImageTest(base.EC2TestCase):
27
28 @decorators.idempotent_id('19a2fda6-0b78-4544-a6c5-ac16f39811c8')
29 @testtools.skipUnless(CONF.aws.ebs_image_id, "EBS image id is not defined")
30 def test_check_ebs_image_type(self):
31 image_id = CONF.aws.ebs_image_id
32 data = self.client.describe_images(ImageIds=[image_id])
33 self.assertEqual(1, len(data['Images']))
34 image = data['Images'][0]
35 self.assertEqual("ebs", image['RootDeviceType'],
36 "Image is not EBS image")
37
38 @decorators.idempotent_id('d45be578-5968-4189-8f25-56bf8ef23d20')
39 @testtools.skipUnless(CONF.aws.ebs_image_id, "EBS image id is not defined")
40 def test_check_ebs_image_volume_properties(self):
41 image_id = CONF.aws.ebs_image_id
42 data = self.client.describe_images(ImageIds=[image_id])
43 self.assertEqual(1, len(data['Images']))
44 image = data['Images'][0]
45 self.assertTrue(image['RootDeviceName'])
46 self.assertTrue(image['BlockDeviceMappings'])
47 device_name = image['RootDeviceName']
48 bdm = image['BlockDeviceMappings']
49 bdm = [v for v in bdm if v['DeviceName'] == device_name]
50 self.assertEqual(1, len(bdm))
51 bdm = bdm[0]
52 self.assertIn('Ebs', bdm)
53 ebs = bdm['Ebs']
54 self.assertIsNotNone(ebs.get('SnapshotId'))
55 self.assertIsNotNone(ebs.get('DeleteOnTermination'))
56 self.assertIsNotNone(ebs.get('VolumeSize'))
57 if CONF.aws.run_incompatible_tests:
58 self.assertIsNotNone(ebs.get('Encrypted'))
59 self.assertFalse(ebs.get('Encrypted'))
60 self.assertIsNotNone(ebs.get('VolumeType'))
61
62 @decorators.idempotent_id('a139f5ea-45fd-4b3e-9a52-32de0f8c3bca')
63 @testtools.skipUnless(CONF.aws.ebs_image_id, "EBS image id is not defined")
64 def test_describe_image_with_filters(self):
65 image_id = CONF.aws.ebs_image_id
66 data = self.client.describe_images(ImageIds=[image_id])
67 self.assertEqual(1, len(data['Images']))
68
69 data = self.client.describe_images(
70 # NOTE(ft): limit output to prevent timeout over AWS
71 Filters=[{'Name': 'image-type', 'Values': ['kernel', 'ramdisk']}])
72 if len(data['Images']) < 2:
73 self.skipTest("Insufficient images to check filters")
74 data = self.client.describe_images(
75 Filters=[{'Name': 'image-id', 'Values': [image_id]}])
76 self.assertEqual(1, len(data['Images']))
77 self.assertEqual(image_id, data['Images'][0]['ImageId'])
78
79 @decorators.idempotent_id('743e1f87-e0b6-4787-ab22-176379030007')
80 @testtools.skipUnless(CONF.aws.image_id, "Image id is not defined")
81 def test_check_image_operations_negative(self):
82 # NOTE(andrey-mp): image_id is a public image created by admin
83 image_id = CONF.aws.image_id
84
85 self.assertRaises('InvalidRequest',
86 self.client.describe_image_attribute,
87 ImageId=image_id, Attribute='unsupported')
88
89 self.assertRaises('AuthFailure',
90 self.client.describe_image_attribute,
91 ImageId=image_id, Attribute='description')
92
93 self.assertRaises('InvalidParameterCombination',
94 self.client.modify_image_attribute,
95 ImageId=image_id, Attribute='unsupported')
96
97 self.assertRaises('InvalidParameter',
98 self.client.modify_image_attribute,
99 ImageId=image_id, Attribute='blockDeviceMapping')
100
101 self.assertRaises('InvalidParameterCombination',
102 self.client.modify_image_attribute,
103 ImageId=image_id)
104
105 self.assertRaises('AuthFailure',
106 self.client.modify_image_attribute,
107 ImageId=image_id, Description={'Value': 'fake'})
108
109 self.assertRaises('AuthFailure',
110 self.client.modify_image_attribute,
111 ImageId=image_id, LaunchPermission={'Add': [{'Group': 'all'}]})
112
113 self.assertRaises('MissingParameter',
114 self.client.modify_image_attribute,
115 ImageId=image_id, Attribute='description')
116
117 self.assertRaises('InvalidParameterCombination',
118 self.client.modify_image_attribute,
119 ImageId=image_id, Attribute='launchPermission')
120
121 self.assertRaises('InvalidRequest',
122 self.client.reset_image_attribute,
123 ImageId=image_id, Attribute='fake')
124
125 self.assertRaises('AuthFailure',
126 self.client.reset_image_attribute,
127 ImageId=image_id, Attribute='launchPermission')
128
129 self.assertRaises('AuthFailure',
130 self.client.deregister_image,
131 ImageId=image_id)
132
133 @decorators.idempotent_id('a948dad1-9128-446b-86ee-82db13342054')
134 @testtools.skipUnless(CONF.aws.image_id, 'image id is not defined')
135 def test_create_image_from_non_ebs_instance(self):
136 image_id = CONF.aws.image_id
137 data = self.client.describe_images(ImageIds=[image_id])
138 image = data['Images'][0]
139 if 'RootDeviceType' in image and 'ebs' in image['RootDeviceType']:
140 raise self.skipException('image_id should not be EBS image.')
141
142 instance_id = self.run_instance(ImageId=image_id)
143
144 def _rollback(fn_data):
145 self.client.deregister_image(ImageId=fn_data['ImageId'])
146
147 self.assertRaises('InvalidParameterValue',
148 self.client.create_image, rollback_fn=_rollback,
149 InstanceId=instance_id, Name='name', Description='desc')
150
151 data = self.client.terminate_instances(InstanceIds=[instance_id])
152 self.get_instance_waiter().wait_delete(instance_id)
153
154 def _create_image(self, name, desc, extra_run_instance_args={}):
155 image_id = CONF.aws.ebs_image_id
156 data = self.client.describe_images(ImageIds=[image_id])
157 image = data['Images'][0]
158 self.assertTrue('RootDeviceType' in image
159 and 'ebs' in image['RootDeviceType'])
160
161 instance_id = self.run_instance(ImageId=image_id,
162 **extra_run_instance_args)
163 instance = self.get_instance(instance_id)
164 for bdm in instance.get('BlockDeviceMappings', []):
165 if 'Ebs' in bdm:
166 self.addResourceCleanUp(self.client.delete_volume,
167 VolumeId=bdm['Ebs']['VolumeId'])
168
169 data = self.client.create_image(InstanceId=instance_id,
170 Name=name, Description=desc)
171 image_id = data['ImageId']
172 image_clean = self.addResourceCleanUp(self.client.deregister_image,
173 ImageId=image_id)
174 self.get_image_waiter().wait_available(image_id)
175
176 data = self.client.describe_images(ImageIds=[image_id])
177 for bdm in data['Images'][0].get('BlockDeviceMappings', []):
178 if 'Ebs' in bdm and 'SnapshotId' in bdm['Ebs']:
179 snapshot_id = bdm['Ebs']['SnapshotId']
180 self.addResourceCleanUp(self.client.delete_snapshot,
181 SnapshotId=snapshot_id)
182
183 data = self.client.terminate_instances(InstanceIds=[instance_id])
184 self.get_instance_waiter().wait_delete(instance_id)
185
186 return image_id, image_clean
187
188 @decorators.idempotent_id('f4fbb311-8a59-443d-a60a-11779917c757')
189 @testtools.skipUnless(CONF.aws.ebs_image_id, "EBS image id is not defined")
190 def test_create_image_from_ebs_instance(self):
191 name = data_utils.rand_name('image')
192 desc = data_utils.rand_name('description')
193 image_id, image_clean = self._create_image(name, desc)
194
195 data = self.client.describe_images(ImageIds=[image_id])
196 self.assertEqual(1, len(data['Images']))
197 image = data['Images'][0]
198
199 self.assertIsNotNone(image['CreationDate'])
200 self.assertEqual("ebs", image['RootDeviceType'])
201 self.assertFalse(image['Public'])
202 self.assertEqual(name, image['Name'])
203 self.assertEqual(desc, image['Description'])
204 self.assertEqual('machine', image['ImageType'])
205 self.assertNotEmpty(image['BlockDeviceMappings'])
206 for bdm in image['BlockDeviceMappings']:
207 self.assertIn('DeviceName', bdm)
208
209 data = self.client.deregister_image(ImageId=image_id)
210 self.cancelResourceCleanUp(image_clean)
211
212 @decorators.idempotent_id('b9aba1f7-0a7e-4717-b879-efe3bbea74e2')
213 @testtools.skipUnless(CONF.aws.ebs_image_id, "EBS image id is not defined")
214 def test_check_simple_image_attributes(self):
215 data = self.client.describe_images(ImageIds=[CONF.aws.ebs_image_id])
216 base_image = data['Images'][0]
217
218 name = data_utils.rand_name('image')
219 desc = data_utils.rand_name('desc for image')
220 image_id, image_clean = self._create_image(name, desc)
221
222 data = self.client.describe_image_attribute(
223 ImageId=image_id, Attribute='kernel')
224 if 'KernelId' in base_image:
225 self.assertIn('KernelId', data)
226 else:
227 self.assertNotIn('KernelId', data)
228
229 data = self.client.describe_image_attribute(
230 ImageId=image_id, Attribute='ramdisk')
231 if 'RamdiskId' in base_image:
232 self.assertIn('RamdiskId', data)
233 else:
234 self.assertNotIn('RamdiskId', data)
235
236 # description
237 data = self.client.describe_image_attribute(
238 ImageId=image_id, Attribute='description')
239 self.assertIn('Description', data)
240 self.assertIn('Value', data['Description'])
241 self.assertEqual(desc, data['Description']['Value'])
242
243 def _modify_description(**kwargs):
244 self.client.modify_image_attribute(ImageId=image_id, **kwargs)
245 data = self.client.describe_image_attribute(
246 ImageId=image_id, Attribute='description')
247 self.assertEqual(new_desc, data['Description']['Value'])
248
249 new_desc = data_utils.rand_name('new desc')
250 _modify_description(Attribute='description', Value=new_desc)
251 _modify_description(Description={'Value': new_desc})
252
253 data = self.client.deregister_image(ImageId=image_id)
254 self.cancelResourceCleanUp(image_clean)
255
256 @decorators.idempotent_id('680963cf-84f2-488d-bcdb-fc6f9b39f78c')
257 @testtools.skipUnless(CONF.aws.ebs_image_id, "EBS image id is not defined")
258 def test_check_bdm_in_image(self):
259 image_id = CONF.aws.ebs_image_id
260 data = self.client.describe_images(ImageIds=[image_id])
261 root_device_name = data['Images'][0]['RootDeviceName']
262 device_name_prefix = base.get_device_name_prefix(root_device_name)
263 device_name = device_name_prefix + 'h'
264
265 name = data_utils.rand_name('image')
266 desc = data_utils.rand_name('description')
267 image_id, image_clean = self._create_image(
268 name, desc,
269 extra_run_instance_args={
270 'BlockDeviceMappings': [{'DeviceName': device_name,
271 'Ebs': {'VolumeSize': 1}}]})
272
273 data = self.client.describe_images(ImageIds=[image_id])
274 image = data['Images'][0]
275
276 for bdm in image['BlockDeviceMappings']:
277 self.assertTrue('DeviceName', bdm)
278
279 data = self.client.deregister_image(ImageId=image_id)
280 self.cancelResourceCleanUp(image_clean)
281
282 @decorators.idempotent_id('1c244c9a-af3e-47f0-bc85-034e24b051e4')
283 @testtools.skipUnless(CONF.aws.run_incompatible_tests,
284 'By default glance is configured as "publicize_image": "role:admin"')
285 @testtools.skipUnless(CONF.aws.run_incompatible_tests,
286 'skip due to bug #1439819')
287 @testtools.skipUnless(CONF.aws.ebs_image_id, "EBS image id is not defined")
288 def test_check_launch_permission_attribute(self):
289 name = data_utils.rand_name('image')
290 desc = data_utils.rand_name('desc for image')
291 image_id, image_clean = self._create_image(name, desc)
292
293 # launch permission
294 data = self.client.describe_image_attribute(
295 ImageId=image_id, Attribute='launchPermission')
296 self.assertIn('LaunchPermissions', data)
297 self.assertEmpty(data['LaunchPermissions'])
298
299 def _modify_launch_permission(**kwargs):
300 self.client.modify_image_attribute(ImageId=image_id, **kwargs)
301 data = self.client.describe_image_attribute(
302 ImageId=image_id, Attribute='launchPermission')
303 self.assertIn('LaunchPermissions', data)
304 self.assertNotEmpty(data['LaunchPermissions'])
305 self.assertIn('Group', data['LaunchPermissions'][0])
306 self.assertEqual('all', data['LaunchPermissions'][0]['Group'])
307 data = self.client.describe_images(ImageIds=[image_id])
308 self.assertTrue(data['Images'][0]['Public'])
309
310 self.client.reset_image_attribute(
311 ImageId=image_id, Attribute='launchPermission')
312 data = self.client.describe_image_attribute(
313 ImageId=image_id, Attribute='launchPermission')
314 self.assertEmpty(data['LaunchPermissions'])
315 data = self.client.describe_images(ImageIds=[image_id])
316 self.assertFalse(data['Images'][0]['Public'])
317
318 _modify_launch_permission(Attribute='launchPermission',
319 OperationType='add', UserGroups=['all'])
320 _modify_launch_permission(LaunchPermission={'Add': [{'Group': 'all'}]})
321
322 data = self.client.deregister_image(ImageId=image_id)
323 self.cancelResourceCleanUp(image_clean)
324
325
326class ImageRegisterTest(base.EC2TestCase):
327
328 valid_image_state = set(('available', 'pending', 'failed'))
329
330 @classmethod
331 @base.safe_setup
332 def setUpClass(cls):
333 super(ImageRegisterTest, cls).setUpClass()
334 cls.image_location = CONF.aws.ami_image_location
335 if not cls.image_location:
336 raise cls.skipException('Image materials are not ready in S3')
337
338 @decorators.idempotent_id('3e25269d-c8a2-4438-ab25-c343cb53db79')
339 def test_register_get_deregister_ami_image(self):
340 image_name = data_utils.rand_name("ami-name")
341 data = self.client.register_image(
342 Name=image_name, ImageLocation=self.image_location)
343 image_id = data['ImageId']
344 image_clean = self.addResourceCleanUp(self.client.deregister_image,
345 ImageId=image_id)
346 self.assertEqual(image_id[0:3], "ami")
347
348 data = self.client.describe_images(ImageIds=[image_id])
349 self.assertEqual(1, len(data['Images']))
350 image = data['Images'][0]
351 self.assertEqual(image_name, image['Name'])
352 self.assertEqual(image_id, image['ImageId'])
353 self.assertIn(image['State'], self.valid_image_state)
354
355 self.get_image_waiter().wait_available(image_id)
356
357 self.client.deregister_image(ImageId=image_id)
358 self.cancelResourceCleanUp(image_clean)
359 self.get_image_waiter().wait_delete(image_id)
diff --git a/ec2api/tests/functional/api/test_instance_attributes.py b/ec2api/tests/functional/api/test_instance_attributes.py
deleted file mode 100644
index e1c8db5..0000000
--- a/ec2api/tests/functional/api/test_instance_attributes.py
+++ /dev/null
@@ -1,365 +0,0 @@
1# Copyright 2014 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16import time
17
18from oslo_log import log
19from tempest.lib.common.utils import data_utils
20from tempest.lib import decorators
21import testtools
22
23from ec2api.tests.functional import base
24from ec2api.tests.functional import config
25
26CONF = config.CONF
27LOG = log.getLogger(__name__)
28
29
30class InstanceAttributeTest(base.EC2TestCase):
31
32 @decorators.idempotent_id('485107d8-f65f-4441-9558-2ff783e52e22')
33 @testtools.skipUnless(CONF.aws.ebs_image_id, "EBS image id is not defined")
34 def test_describe_instance_attributes(self):
35 instance_id = self.run_instance(ImageId=CONF.aws.ebs_image_id)
36
37 data = self.client.describe_instance_attribute(
38 InstanceId=instance_id, Attribute='blockDeviceMapping')
39 bdms = data.get('BlockDeviceMappings', [])
40 self.assertNotEmpty(bdms)
41 self.assertEqual(1, len(bdms))
42 self.assertIn('DeviceName', bdms[0])
43 self.assertIn('Ebs', bdms[0])
44
45 data = self.client.describe_instance_attribute(
46 InstanceId=instance_id, Attribute='disableApiTermination')
47 self.assertIn('DisableApiTermination', data)
48 self.assertIn('Value', data['DisableApiTermination'])
49 self.assertFalse(data['DisableApiTermination']['Value'])
50
51 data = self.client.describe_instance_attribute(
52 InstanceId=instance_id, Attribute='groupSet')
53 self.assertIn('Groups', data)
54 self.assertNotEmpty(data['Groups'], data)
55 self.assertTrue('GroupId' in data['Groups'][0]
56 or 'GroupName' in data['Groups'][0])
57 self.assertTrue(data['Groups'][0].get('GroupId')
58 or data['Groups'][0].get('GroupName'))
59
60 data = self.client.describe_instance_attribute(
61 InstanceId=instance_id, Attribute='instanceType')
62 self.assertIn('InstanceType', data)
63 self.assertIn('Value', data['InstanceType'])
64 self.assertEqual(CONF.aws.instance_type, data['InstanceType']['Value'])
65
66 data = self.client.describe_instance_attribute(
67 InstanceId=instance_id, Attribute='kernel')
68 self.assertIn('KernelId', data)
69
70 data = self.client.describe_instance_attribute(
71 InstanceId=instance_id, Attribute='ramdisk')
72 self.assertIn('RamdiskId', data)
73
74 data = self.client.describe_instance_attribute(
75 InstanceId=instance_id, Attribute='rootDeviceName')
76 self.assertIn('RootDeviceName', data)
77 self.assertIn('Value', data['RootDeviceName'])
78 self.assertTrue(data['RootDeviceName']['Value'])
79
80 self.client.terminate_instances(InstanceIds=[instance_id])
81 self.get_instance_waiter().wait_delete(instance_id)
82
83 @decorators.idempotent_id('391f6645-d014-42c7-a727-f3a6e7a13a4c')
84 @testtools.skipUnless(CONF.aws.image_id, "image id is not defined")
85 def test_disable_api_termination_attribute(self):
86 instance_id = self.run_instance(DisableApiTermination=True)
87 res_clean = self.addResourceCleanUp(
88 self.client.modify_instance_attribute,
89 InstanceId=instance_id,
90 DisableApiTermination={'Value': False})
91
92 data = self.client.describe_instance_attribute(
93 InstanceId=instance_id, Attribute='disableApiTermination')
94 self.assertIn('DisableApiTermination', data)
95 self.assertIn('Value', data['DisableApiTermination'])
96 self.assertTrue(data['DisableApiTermination']['Value'])
97
98 data = self.client.modify_instance_attribute(InstanceId=instance_id,
99 Attribute='disableApiTermination', Value='False')
100 data = self.client.describe_instance_attribute(
101 InstanceId=instance_id, Attribute='disableApiTermination')
102 self.assertFalse(data['DisableApiTermination']['Value'])
103
104 data = self.client.modify_instance_attribute(InstanceId=instance_id,
105 Attribute='disableApiTermination', Value='True')
106 data = self.client.describe_instance_attribute(
107 InstanceId=instance_id, Attribute='disableApiTermination')
108 self.assertTrue(data['DisableApiTermination']['Value'])
109
110 self.assertRaises('OperationNotPermitted',
111 self.client.terminate_instances,
112 InstanceIds=[instance_id])
113
114 data = self.client.modify_instance_attribute(InstanceId=instance_id,
115 DisableApiTermination={'Value': False})
116 data = self.client.describe_instance_attribute(
117 InstanceId=instance_id, Attribute='disableApiTermination')
118 self.assertFalse(data['DisableApiTermination']['Value'])
119
120 self.client.terminate_instances(InstanceIds=[instance_id])
121 self.cancelResourceCleanUp(res_clean)
122 self.get_instance_waiter().wait_delete(instance_id)
123
124 @decorators.idempotent_id('50671a21-99bf-4514-acb0-97617f92e868')
125 @testtools.skipUnless(CONF.aws.image_id, "image id is not defined")
126 def test_instance_attributes_negative(self):
127 instance_id = self.run_instance()
128
129 self.assertRaises('InvalidParameterValue',
130 self.client.describe_instance_attribute,
131 InstanceId=instance_id, Attribute='fake_attribute')
132 self.assertRaises('InvalidInstanceID.NotFound',
133 self.client.describe_instance_attribute,
134 InstanceId='i-0', Attribute='disableApiTermination')
135 if base.TesterStateHolder().get_ec2_enabled():
136 self.assertRaises('InvalidParameterCombination',
137 self.client.describe_instance_attribute,
138 InstanceId=instance_id, Attribute='sourceDestCheck')
139
140 self.assertRaises('InvalidParameterValue',
141 self.client.modify_instance_attribute,
142 InstanceId=instance_id, Attribute='fake_attribute')
143 self.assertRaises('MissingParameter',
144 self.client.modify_instance_attribute,
145 InstanceId=instance_id, Attribute='disableApiTermination')
146 self.assertRaises('InvalidParameterCombination',
147 self.client.modify_instance_attribute,
148 InstanceId=instance_id)
149 self.assertRaises('InvalidParameterCombination',
150 self.client.modify_instance_attribute,
151 InstanceId=instance_id, Attribute='disableApiTermination',
152 Value='True', DisableApiTermination={'Value': False})
153
154 ex_str = ('InvalidParameterCombination'
155 if base.TesterStateHolder().get_ec2_enabled() else
156 'InvalidGroup.NotFound')
157 self.assertRaises(ex_str,
158 self.client.modify_instance_attribute,
159 InstanceId=instance_id, Groups=['sg-0'])
160 if base.TesterStateHolder().get_ec2_enabled():
161 self.assertRaises('InvalidParameterCombination',
162 self.client.modify_instance_attribute,
163 InstanceId=instance_id, Attribute='sourceDestCheck',
164 Value='False')
165
166 self.assertRaises('InvalidParameterValue',
167 self.client.reset_instance_attribute,
168 InstanceId=instance_id, Attribute='fake_attribute')
169 self.assertRaises('InvalidParameterValue',
170 self.client.reset_instance_attribute,
171 InstanceId=instance_id, Attribute='disableApiTermination')
172 self.assertRaises('InvalidParameterValue',
173 self.client.reset_instance_attribute,
174 InstanceId='i-0', Attribute='disableApiTermination')
175 self.assertRaises('InvalidParameterValue',
176 self.client.reset_instance_attribute,
177 InstanceId=instance_id, Attribute='groupSet')
178 self.assertRaises('InvalidParameterValue',
179 self.client.reset_instance_attribute,
180 InstanceId=instance_id, Attribute='instanceType')
181
182 if base.TesterStateHolder().get_ec2_enabled():
183 self.assertRaises('InvalidParameterCombination',
184 self.client.reset_instance_attribute,
185 InstanceId=instance_id, Attribute='sourceDestCheck')
186
187 self.assertRaises('IncorrectInstanceState',
188 self.client.modify_instance_attribute,
189 InstanceId=instance_id, Attribute='instanceType',
190 Value=CONF.aws.instance_type)
191 self.assertRaises('IncorrectInstanceState',
192 self.client.modify_instance_attribute,
193 InstanceId=instance_id,
194 InstanceType={'Value': CONF.aws.instance_type})
195
196 self.client.terminate_instances(InstanceIds=[instance_id])
197 self.get_instance_waiter().wait_delete(instance_id)
198
199 @base.skip_without_vpc()
200 @decorators.idempotent_id('6fd2c8eb-f7f9-420d-a8ae-5d5af3a49a35')
201 @testtools.skipUnless(CONF.aws.image_id, "image id is not defined")
202 def test_attributes_for_multiple_interfaces_negative(self):
203 vpc_id, subnet_id = self.create_vpc_and_subnet('10.30.0.0/24')
204
205 name = data_utils.rand_name('sgName')
206 desc = data_utils.rand_name('sgDesc')
207 data = self.client.create_security_group(VpcId=vpc_id, GroupName=name,
208 Description=desc)
209 group_id = data['GroupId']
210 self.addResourceCleanUp(self.client.delete_security_group,
211 GroupId=group_id)
212 time.sleep(2)
213 data = self.client.create_network_interface(SubnetId=subnet_id,
214 Groups=[group_id])
215 ni_id2 = data['NetworkInterface']['NetworkInterfaceId']
216 self.addResourceCleanUp(self.client.delete_network_interface,
217 NetworkInterfaceId=ni_id2)
218 self.get_network_interface_waiter().wait_available(ni_id2)
219
220 instance_id = self.run_instance(SubnetId=subnet_id)
221
222 kwargs = {
223 'DeviceIndex': 2,
224 'InstanceId': instance_id,
225 'NetworkInterfaceId': ni_id2
226 }
227 data = self.client.attach_network_interface(*[], **kwargs)
228
229 self.assertRaises('InvalidInstanceID',
230 self.client.describe_instance_attribute,
231 InstanceId=instance_id, Attribute='groupSet')
232 self.assertRaises('InvalidInstanceID',
233 self.client.modify_instance_attribute,
234 InstanceId=instance_id, Groups=['sg-0'])
235
236 self.assertRaises('InvalidInstanceID',
237 self.client.describe_instance_attribute,
238 InstanceId=instance_id, Attribute='sourceDestCheck')
239 self.assertRaises('InvalidInstanceID',
240 self.client.modify_instance_attribute,
241 InstanceId=instance_id, SourceDestCheck={'Value': False})
242 self.assertRaises('InvalidInstanceID',
243 self.client.reset_instance_attribute,
244 InstanceId=instance_id, Attribute='sourceDestCheck')
245
246 self.client.terminate_instances(InstanceIds=[instance_id])
247 self.get_instance_waiter().wait_delete(instance_id)
248
249 @base.skip_without_vpc()
250 @decorators.idempotent_id('da26cc0d-6c2d-4638-97f1-1abfae8f00b5')
251 @testtools.skipUnless(CONF.aws.image_id, "image id is not defined")
252 def test_group_set_attribute(self):
253 vpc_id, subnet_id = self.create_vpc_and_subnet('10.30.0.0/24')
254
255 instance_id = self.run_instance(SubnetId=subnet_id)
256
257 data = self.client.describe_instance_attribute(
258 InstanceId=instance_id, Attribute='groupSet')
259 self.assertIn('Groups', data)
260 self.assertEqual(1, len(data['Groups']))
261 default_group_id = data['Groups'][0]['GroupId']
262
263 name = data_utils.rand_name('sgName')
264 desc = data_utils.rand_name('sgDesc')
265 data = self.client.create_security_group(VpcId=vpc_id, GroupName=name,
266 Description=desc)
267 group_id = data['GroupId']
268 self.addResourceCleanUp(self.client.delete_security_group,
269 GroupId=group_id)
270 time.sleep(2)
271
272 try:
273 data = self.client.modify_instance_attribute(
274 InstanceId=instance_id, Groups=[group_id])
275 data = self.client.describe_instance_attribute(
276 InstanceId=instance_id, Attribute='groupSet')
277 self.assertIn('Groups', data)
278 self.assertEqual(1, len(data['Groups']))
279 self.assertNotEqual(default_group_id, data['Groups'][0]['GroupId'])
280
281 self.assertRaises('DependencyViolation',
282 self.client.delete_security_group,
283 GroupId=group_id)
284 finally:
285 self.client.modify_instance_attribute(InstanceId=instance_id,
286 Groups=[default_group_id])
287
288 data = self.client.describe_instance_attribute(
289 InstanceId=instance_id, Attribute='groupSet')
290 self.assertIn('Groups', data)
291 self.assertEqual(1, len(data['Groups']))
292 self.assertEqual(default_group_id, data['Groups'][0]['GroupId'])
293
294 self.client.terminate_instances(InstanceIds=[instance_id])
295 self.get_instance_waiter().wait_delete(instance_id)
296
297 @base.skip_without_vpc()
298 @decorators.idempotent_id('8e7b37b5-1f2d-4c38-b51e-dcd0e726edb3')
299 @testtools.skipUnless(CONF.aws.image_id, "image id is not defined")
300 def test_source_dest_check_attribute(self):
301 vpc_id, subnet_id = self.create_vpc_and_subnet('10.30.0.0/24')
302
303 instance_id = self.run_instance(SubnetId=subnet_id)
304
305 def do_check(value):
306 data = self.client.describe_instance_attribute(
307 InstanceId=instance_id, Attribute='sourceDestCheck')
308 self.assertIn('SourceDestCheck', data)
309 self.assertEqual(value, data['SourceDestCheck'].get('Value'))
310
311 do_check(True)
312
313 self.client.modify_instance_attribute(
314 InstanceId=instance_id, Attribute='sourceDestCheck',
315 Value='False')
316 do_check(False)
317
318 self.client.reset_instance_attribute(
319 InstanceId=instance_id, Attribute='sourceDestCheck')
320 do_check(True)
321
322 self.client.modify_instance_attribute(
323 InstanceId=instance_id, Attribute='sourceDestCheck',
324 Value='False')
325 do_check(False)
326
327 self.client.terminate_instances(InstanceIds=[instance_id])
328 self.get_instance_waiter().wait_delete(instance_id)
329
330 @decorators.idempotent_id('a2640ab1-6aaa-4626-9f23-4aba52e3b88a')
331 @testtools.skipUnless(CONF.aws.ebs_image_id, "EBS image id is not defined")
332 @testtools.skipUnless(CONF.aws.instance_type_alt,
333 "Alternative instance type is not defined")
334 @testtools.skipUnless(CONF.aws.instance_type_alt != CONF.aws.instance_type,
335 "Alternative instance type is not defined")
336 def test_instance_type_attribute(self):
337 instance_id = self.run_instance(ImageId=CONF.aws.ebs_image_id)
338
339 self.client.stop_instances(InstanceIds=[instance_id])
340 self.get_instance_waiter().wait_available(instance_id,
341 final_set=('stopped'))
342 instance = self.get_instance(instance_id)
343 self.assertEqual(CONF.aws.instance_type, instance['InstanceType'])
344
345 self.client.modify_instance_attribute(
346 InstanceId=instance_id, Attribute='instanceType',
347 Value=CONF.aws.instance_type)
348 instance = self.get_instance(instance_id)
349 self.assertEqual(CONF.aws.instance_type, instance['InstanceType'])
350
351 self.client.modify_instance_attribute(
352 InstanceId=instance_id,
353 InstanceType={'Value': CONF.aws.instance_type_alt})
354 instance = self.get_instance(instance_id)
355 self.assertEqual(CONF.aws.instance_type_alt, instance['InstanceType'])
356
357 self.client.start_instances(InstanceIds=[instance_id])
358 self.get_instance_waiter().wait_available(instance_id,
359 final_set=('running'))
360
361 instance = self.get_instance(instance_id)
362 self.assertEqual(CONF.aws.instance_type_alt, instance['InstanceType'])
363
364 self.client.terminate_instances(InstanceIds=[instance_id])
365 self.get_instance_waiter().wait_delete(instance_id)
diff --git a/ec2api/tests/functional/api/test_instances.py b/ec2api/tests/functional/api/test_instances.py
deleted file mode 100644
index deac2d5..0000000
--- a/ec2api/tests/functional/api/test_instances.py
+++ /dev/null
@@ -1,252 +0,0 @@
1# Copyright 2014 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from oslo_log import log
17from tempest.lib.common.utils import data_utils
18from tempest.lib import decorators
19import testtools
20
21from ec2api.tests.functional import base
22from ec2api.tests.functional import config
23
24CONF = config.CONF
25LOG = log.getLogger(__name__)
26
27
28class InstanceTest(base.EC2TestCase):
29
30 @classmethod
31 @base.safe_setup
32 def setUpClass(cls):
33 super(InstanceTest, cls).setUpClass()
34 if not CONF.aws.image_id:
35 raise cls.skipException('aws image_id does not provided')
36 cls.zone = CONF.aws.aws_zone
37
38 @decorators.idempotent_id('5604e461-c36a-4fea-84bc-eddfe702ae4f')
39 def test_create_delete_instance(self):
40 instance_type = CONF.aws.instance_type
41 image_id = CONF.aws.image_id
42 data = self.client.run_instances(
43 ImageId=image_id, InstanceType=instance_type,
44 Placement={'AvailabilityZone': self.zone}, MinCount=1, MaxCount=1)
45 instance_id = data['Instances'][0]['InstanceId']
46 res_clean = self.addResourceCleanUp(self.client.terminate_instances,
47 InstanceIds=[instance_id])
48 self.assertEqual(1, len(data['Instances']))
49 self.get_instance_waiter().wait_available(instance_id,
50 final_set=('running'))
51
52 data = self.client.describe_instances(InstanceIds=[instance_id])
53 reservations = data.get('Reservations', [])
54 self.assertNotEmpty(reservations)
55 instances = reservations[0].get('Instances', [])
56 self.assertEqual(1, len(instances))
57 self.assertEqual(1, len(instances[0]['SecurityGroups']))
58 groups = reservations[0].get('Groups', [])
59 if base.TesterStateHolder().get_ec2_enabled():
60 self.assertEqual(1, len(groups))
61 self.assertEqual(groups[0]['GroupName'],
62 instances[0]['SecurityGroups'][0]['GroupName'])
63 else:
64 self.assertEqual(0, len(groups))
65
66 self.client.terminate_instances(InstanceIds=[instance_id])
67 self.cancelResourceCleanUp(res_clean)
68 self.get_instance_waiter().wait_delete(instance_id)
69
70 # NOTE(andrey-mp): There is difference between Openstack and Amazon.
71 # Amazon returns instance in 'terminated' state some time after
72 # instance deletion. But Openstack doesn't return such instance.
73
74 @decorators.idempotent_id('40b273e5-3d43-4529-99b0-da5dd7e6764e')
75 def test_create_idempotent_instance(self):
76 client_token = data_utils.rand_name('t')
77 instance_type = CONF.aws.instance_type
78 image_id = CONF.aws.image_id
79 data = self.client.run_instances(
80 ImageId=image_id, InstanceType=instance_type,
81 Placement={'AvailabilityZone': self.zone}, MinCount=1, MaxCount=1,
82 ClientToken=client_token)
83 instance_id = data['Instances'][0]['InstanceId']
84 res_clean = self.addResourceCleanUp(self.client.terminate_instances,
85 InstanceIds=[instance_id])
86 self.assertEqual(1, len(data['Instances']))
87 reservation_id = data['ReservationId']
88 self.get_instance_waiter().wait_available(instance_id,
89 final_set=('running'))
90
91 data = self.client.run_instances(
92 ImageId=image_id, InstanceType=instance_type,
93 Placement={'AvailabilityZone': self.zone}, MinCount=1, MaxCount=1,
94 ClientToken=client_token)
95
96 # NOTE(andrey-mp): if idempotent run will fail this will terminate
97 # second instance
98 self.addResourceCleanUp(self.client.terminate_instances,
99 InstanceIds=[data['Instances'][0]['InstanceId']])
100
101 self.assertEqual(1, len(data['Instances']))
102 self.assertEqual(reservation_id, data['ReservationId'])
103 self.assertEqual(instance_id, data['Instances'][0]['InstanceId'])
104
105 self.client.terminate_instances(InstanceIds=[instance_id])
106 self.cancelResourceCleanUp(res_clean)
107 self.get_instance_waiter().wait_delete(instance_id)
108
109 @decorators.idempotent_id('4c3c709a-72e2-4c87-bab2-e3a16fc5d1fe')
110 def test_describe_instances_filter(self):
111 instance_type = CONF.aws.instance_type
112 image_id = CONF.aws.image_id
113 data = self.client.run_instances(
114 ImageId=image_id, InstanceType=instance_type,
115 Placement={'AvailabilityZone': self.zone}, MinCount=1, MaxCount=1)
116 instance_id = data['Instances'][0]['InstanceId']
117 res_clean = self.addResourceCleanUp(self.client.terminate_instances,
118 InstanceIds=[instance_id])
119 self.get_instance_waiter().wait_available(instance_id,
120 final_set=('running'))
121
122 # NOTE(andrey-mp): by real id
123 data = self.client.describe_instances(InstanceIds=[instance_id])
124 self._assert_instance(data, instance_id)
125 instances = data['Reservations'][0]['Instances']
126 private_dns = instances[0]['PrivateDnsName']
127 private_ip = instances[0]['PrivateIpAddress']
128
129 # NOTE(andrey-mp): by fake id
130 self.assertRaises('InvalidInstanceID.NotFound',
131 self.client.describe_instances,
132 InstanceIds=['i-0'])
133
134 # NOTE(andrey-mp): by private ip
135 data = self.client.describe_instances(
136 Filters=[{'Name': 'private-ip-address', 'Values': ['1.2.3.4']}])
137 self.assertEqual(0, len(data['Reservations']))
138
139 data = self.client.describe_instances(
140 Filters=[{'Name': 'private-ip-address', 'Values': [private_ip]}])
141 self._assert_instance(data, instance_id)
142
143 # NOTE(andrey-mp): by private dns
144 data = self.client.describe_instances(
145 Filters=[{'Name': 'private-dns-name', 'Values': ['fake.com']}])
146 self.assertEqual(0, len(data['Reservations']))
147
148 data = self.client.describe_instances(
149 Filters=[{'Name': 'private-dns-name', 'Values': [private_dns]}])
150 self._assert_instance(data, instance_id)
151
152 self.client.terminate_instances(InstanceIds=[instance_id])
153 self.cancelResourceCleanUp(res_clean)
154 self.get_instance_waiter().wait_delete(instance_id)
155
156 def _assert_instance(self, data, instance_id):
157 reservations = data.get('Reservations', [])
158 self.assertNotEmpty(reservations)
159 instances = reservations[0].get('Instances', [])
160 self.assertNotEmpty(instances)
161 self.assertEqual(instance_id, instances[0]['InstanceId'])
162
163 @decorators.idempotent_id('d40bf881-4220-46a9-b04a-fca9054c9731')
164 def test_get_password_data_and_console_output(self):
165 instance_type = CONF.aws.instance_type
166 image_id = CONF.aws.image_id
167 data = self.client.run_instances(
168 ImageId=image_id, InstanceType=instance_type,
169 Placement={'AvailabilityZone': self.zone}, MinCount=1, MaxCount=1)
170 instance_id = data['Instances'][0]['InstanceId']
171 res_clean = self.addResourceCleanUp(self.client.terminate_instances,
172 InstanceIds=[instance_id])
173 self.get_instance_waiter().wait_available(instance_id,
174 final_set=('running'))
175
176 data = self.client.get_password_data(InstanceId=instance_id)
177 self.assertEqual(instance_id, data['InstanceId'])
178 self.assertIsNotNone(data['Timestamp'])
179 self.assertIn('PasswordData', data)
180
181 def _wait_for_output(*args, **kwargs):
182 data = self.client.get_console_output(*args, **kwargs)
183 self.assertIn('Output', data)
184
185 waiter = base.EC2Waiter(_wait_for_output)
186 waiter.wait_no_exception(InstanceId=instance_id)
187
188 data = self.client.get_console_output(InstanceId=instance_id)
189 self.assertEqual(instance_id, data['InstanceId'])
190 self.assertIsNotNone(data['Timestamp'])
191 self.assertIn('Output', data)
192
193 self.client.terminate_instances(InstanceIds=[instance_id])
194 self.cancelResourceCleanUp(res_clean)
195 self.get_instance_waiter().wait_delete(instance_id)
196
197 @decorators.idempotent_id('5947ccaa-a519-46f4-9d58-ceb79042266a')
198 @testtools.skipUnless(CONF.aws.ebs_image_id, "EBS image id is not defined")
199 def test_stop_instance(self):
200 instance_type = CONF.aws.instance_type
201 image_id = CONF.aws.ebs_image_id
202 data = self.client.run_instances(
203 ImageId=image_id, InstanceType=instance_type,
204 Placement={'AvailabilityZone': self.zone}, MinCount=1, MaxCount=1)
205 instance_id = data['Instances'][0]['InstanceId']
206 res_clean = self.addResourceCleanUp(self.client.terminate_instances,
207 InstanceIds=[instance_id])
208 self.get_instance_waiter().wait_available(instance_id,
209 final_set=('running'))
210
211 data = self.client.stop_instances(InstanceIds=[instance_id])
212 if CONF.aws.run_incompatible_tests:
213 instances = data['StoppingInstances']
214 self.assertEqual(1, len(instances))
215 instance = instances[0]
216 self.assertEqual(instance_id, instance['InstanceId'])
217 self.assertEqual('running', instance['PreviousState']['Name'])
218 self.assertEqual('stopping', instance['CurrentState']['Name'])
219
220 self.get_instance_waiter().wait_available(instance_id,
221 final_set=('stopped'))
222
223 self.client.terminate_instances(InstanceIds=[instance_id])
224 self.cancelResourceCleanUp(res_clean)
225 self.get_instance_waiter().wait_delete(instance_id)
226
227 @decorators.idempotent_id('0f29affb-eae5-42be-9b52-d28a17ba7107')
228 @testtools.skipUnless(CONF.aws.run_incompatible_tests,
229 "Openstack doesn't assign public ip automatically for new instance")
230 def test_public_ip_is_assigned(self):
231 """Is public IP assigned to launched instnace?"""
232 instance_type = CONF.aws.instance_type
233 image_id = CONF.aws.image_id
234 data = self.client.run_instances(
235 ImageId=image_id, InstanceType=instance_type,
236 Placement={'AvailabilityZone': self.zone}, MinCount=1, MaxCount=1)
237 self.assertEqual(1, len(data['Instances']))
238 instance_id = data['Instances'][0]['InstanceId']
239 res_clean = self.addResourceCleanUp(self.client.terminate_instances,
240 InstanceIds=[instance_id])
241 self.get_instance_waiter().wait_available(instance_id,
242 final_set=('running'))
243
244 instance = self.get_instance(instance_id)
245 self.assertIsNotNone(instance.get('PublicIpAddress'))
246 self.assertIsNotNone(instance.get('PrivateIpAddress'))
247 self.assertNotEqual(instance.get('PublicIpAddress'),
248 instance.get('PrivateIpAddress'))
249
250 self.client.terminate_instances(InstanceIds=[instance_id])
251 self.cancelResourceCleanUp(res_clean)
252 self.get_instance_waiter().wait_delete(instance_id)
diff --git a/ec2api/tests/functional/api/test_instances_ebs.py b/ec2api/tests/functional/api/test_instances_ebs.py
deleted file mode 100644
index 29b9096..0000000
--- a/ec2api/tests/functional/api/test_instances_ebs.py
+++ /dev/null
@@ -1,92 +0,0 @@
1# Copyright 2014 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from oslo_log import log
17from tempest.lib import decorators
18import testtools
19
20from ec2api.tests.functional import base
21from ec2api.tests.functional import config
22
23CONF = config.CONF
24LOG = log.getLogger(__name__)
25
26
27class InstanceWithEBSTest(base.EC2TestCase):
28
29 @decorators.idempotent_id('a5cad848-bed2-4dcb-8ba0-987bb7e9c487')
30 @testtools.skipUnless(CONF.aws.ebs_image_id, "EBS image id is not defined")
31 def test_create_get_delete_ebs_instance(self):
32 """Launch EBS-backed instance, check results, and terminate it."""
33 instance_id = self.run_instance(ImageId=CONF.aws.ebs_image_id)
34 instance = self.get_instance(instance_id)
35
36 self.assertEqual('ebs', instance.get('RootDeviceType'))
37 self.assertIsNotNone(instance.get('RootDeviceName'))
38 bdms = instance.get('BlockDeviceMappings')
39 self.assertIsNotNone(bdms)
40 rdn = instance['RootDeviceName']
41 bdt = [bdt for bdt in bdms if bdt['DeviceName'] == rdn]
42 self.assertEqual(1, len(bdt))
43 ebs = bdt[0]['Ebs']
44 self.assertIsNotNone(ebs)
45 volume_id = ebs.get('VolumeId')
46 self.assertIsNotNone(volume_id)
47 self.assertEqual('attached', ebs.get('Status'))
48 if CONF.aws.run_incompatible_tests:
49 self.assertTrue(ebs.get('AttachTime'))
50 self.assertTrue(ebs.get('DeleteOnTermination'))
51
52 data = self.client.describe_volumes(VolumeIds=[volume_id])
53 self.assertEqual(1, len(data['Volumes']))
54
55 data = self.client.terminate_instances(InstanceIds=[instance_id])
56 self.get_instance_waiter().wait_delete(instance_id)
57
58 @decorators.idempotent_id('b6226b7b-d965-4c3a-b2a8-48add794c194')
59 @testtools.skipUnless(CONF.aws.ebs_image_id, "EBS image id is not defined")
60 def test_create_root_volume_snapshot(self):
61 """Create snapshot of root volume of EBS-backed instance."""
62 instance_id = self.run_instance(ImageId=CONF.aws.ebs_image_id)
63
64 bdt = self.get_instance_bdm(instance_id, None)
65 self.assertIsNotNone(bdt)
66 volume_id = bdt['Ebs'].get('VolumeId')
67 self.assertIsNotNone(volume_id)
68
69 self.client.stop_instances(InstanceIds=[instance_id])
70 self.get_instance_waiter().wait_available(instance_id,
71 final_set=('stopped'))
72
73 data = self.client.describe_volumes(VolumeIds=[volume_id])
74 self.assertEqual(1, len(data['Volumes']))
75
76 kwargs = {
77 'VolumeId': data['Volumes'][0]['VolumeId'],
78 'Description': 'Description'
79 }
80 data = self.client.create_snapshot(*[], **kwargs)
81 snapshot_id = data['SnapshotId']
82 res_clean_s = self.addResourceCleanUp(self.client.delete_snapshot,
83 SnapshotId=snapshot_id)
84 self.get_snapshot_waiter().wait_available(snapshot_id,
85 final_set=('completed'))
86
87 data = self.client.delete_snapshot(SnapshotId=snapshot_id)
88 self.cancelResourceCleanUp(res_clean_s)
89 self.get_snapshot_waiter().wait_delete(snapshot_id)
90
91 data = self.client.terminate_instances(InstanceIds=[instance_id])
92 self.get_instance_waiter().wait_delete(instance_id)
diff --git a/ec2api/tests/functional/api/test_instances_vpc.py b/ec2api/tests/functional/api/test_instances_vpc.py
deleted file mode 100644
index a60bde4..0000000
--- a/ec2api/tests/functional/api/test_instances_vpc.py
+++ /dev/null
@@ -1,282 +0,0 @@
1# Copyright 2014 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from oslo_log import log
17from tempest.lib import decorators
18import testtools
19
20from ec2api.tests.functional import base
21from ec2api.tests.functional import config
22
23CONF = config.CONF
24LOG = log.getLogger(__name__)
25
26
27class InstanceInVPCTest(base.EC2TestCase):
28
29 VPC_CIDR = '10.16.0.0/20'
30 vpc_id = None
31 SUBNET_CIDR = '10.16.0.0/24'
32 subnet_id = None
33
34 @classmethod
35 @base.safe_setup
36 def setUpClass(cls):
37 super(InstanceInVPCTest, cls).setUpClass()
38 if not base.TesterStateHolder().get_vpc_enabled():
39 raise cls.skipException('VPC is disabled')
40
41 data = cls.client.create_vpc(CidrBlock=cls.VPC_CIDR)
42 cls.vpc_id = data['Vpc']['VpcId']
43 cls.addResourceCleanUpStatic(cls.client.delete_vpc, VpcId=cls.vpc_id)
44 cls.get_vpc_waiter().wait_available(cls.vpc_id)
45
46 aws_zone = CONF.aws.aws_zone
47 data = cls.client.create_subnet(VpcId=cls.vpc_id,
48 CidrBlock=cls.SUBNET_CIDR,
49 AvailabilityZone=aws_zone)
50 cls.subnet_id = data['Subnet']['SubnetId']
51 cls.addResourceCleanUpStatic(cls.client.delete_subnet,
52 SubnetId=cls.subnet_id)
53 cls.get_subnet_waiter().wait_available(cls.subnet_id)
54
55 @decorators.idempotent_id('af8bd493-4a68-49e7-a3d1-326251b8d16e')
56 @testtools.skipUnless(CONF.aws.image_id, "image id is not defined")
57 def test_create_delete_instance(self):
58 instance_id = self.run_instance(SubnetId=self.subnet_id)
59
60 data = self.client.describe_instances(InstanceIds=[instance_id])
61 reservations = data.get('Reservations', [])
62 self.assertNotEmpty(reservations)
63 instances = reservations[0].get('Instances', [])
64 self.assertNotEmpty(instances)
65 instance = instances[0]
66 self.assertEqual(self.vpc_id, instance['VpcId'])
67 self.assertEqual(self.subnet_id, instance['SubnetId'])
68 self.assertTrue(instance['SourceDestCheck'])
69 self.assertEqual(1, len(instance['NetworkInterfaces']))
70 ni = instance['NetworkInterfaces'][0]
71 self.assertEqual(1, len(ni['Groups']))
72 self.assertIsNotNone(ni['MacAddress'])
73 self.assertIsNotNone(ni['PrivateIpAddress'])
74 self.assertTrue(ni['SourceDestCheck'])
75 self.assertEqual('in-use', ni['Status'])
76 self.assertEqual(self.vpc_id, ni['VpcId'])
77 self.assertEqual(self.subnet_id, ni['SubnetId'])
78
79 self.client.terminate_instances(InstanceIds=[instance_id])
80 self.get_instance_waiter().wait_delete(instance_id)
81
82 # NOTE(andrey-mp): There is difference between Openstack and Amazon.
83 # Amazon returns instance in 'terminated' state some time after
84 # instance deletion. But Openstack doesn't return such instance.
85
86 @decorators.idempotent_id('17ba6206-3044-4e51-9e9b-f5d5728cc047')
87 @testtools.skipUnless(CONF.aws.image_id, "image id is not defined")
88 def test_describe_instances_filter(self):
89 instance_id = self.run_instance(SubnetId=self.subnet_id)
90
91 data = self.client.describe_instances(InstanceIds=[instance_id])
92 self.assert_instance(data, instance_id)
93 instances = data['Reservations'][0]['Instances']
94 private_dns = instances[0]['PrivateDnsName']
95 private_ip = instances[0]['PrivateIpAddress']
96
97 # NOTE(andrey-mp): by private ip
98 data = self.client.describe_instances(
99 Filters=[{'Name': 'private-ip-address', 'Values': ['1.2.3.4']}])
100 self.assertEqual(0, len(data['Reservations']))
101
102 data = self.client.describe_instances(
103 Filters=[{'Name': 'private-ip-address', 'Values': [private_ip]}])
104 self.assert_instance(data, instance_id)
105
106 # NOTE(andrey-mp): by private dns
107 data = self.client.describe_instances(
108 Filters=[{'Name': 'private-dns-name', 'Values': ['fake.com']}])
109 self.assertEqual(0, len(data['Reservations']))
110
111 data = self.client.describe_instances(
112 Filters=[{'Name': 'private-dns-name', 'Values': [private_dns]}])
113 self.assert_instance(data, instance_id)
114
115 # NOTE(andrey-mp): by subnet id
116 data = self.client.describe_instances(
117 Filters=[{'Name': 'subnet-id', 'Values': ['subnet-0']}])
118 self.assertEqual(0, len(data['Reservations']))
119
120 data = self.client.describe_instances(
121 Filters=[{'Name': 'subnet-id', 'Values': [self.subnet_id]}])
122 self.assert_instance(data, instance_id)
123
124 # NOTE(andrey-mp): by vpc id
125 data = self.client.describe_instances(
126 Filters=[{'Name': 'vpc-id', 'Values': ['vpc-0']}])
127 self.assertEqual(0, len(data['Reservations']))
128
129 data = self.client.describe_instances(
130 Filters=[{'Name': 'vpc-id', 'Values': [self.vpc_id]}])
131 self.assert_instance(data, instance_id)
132
133 self.client.terminate_instances(InstanceIds=[instance_id])
134 self.get_instance_waiter().wait_delete(instance_id)
135
136 def assert_instance(self, data, instance_id):
137 reservations = data.get('Reservations', [])
138 self.assertNotEmpty(reservations)
139 instances = reservations[0].get('Instances', [])
140 self.assertNotEmpty(instances)
141 self.assertEqual(instance_id, instances[0]['InstanceId'])
142
143 @decorators.idempotent_id('60ceda8b-85ae-47a7-807b-c4a4dd05a13b')
144 @testtools.skipUnless(CONF.aws.image_id, "image id is not defined")
145 def test_create_instance_with_two_interfaces(self):
146 kwargs = {
147 'SubnetId': self.subnet_id,
148 }
149 data = self.client.create_network_interface(*[], **kwargs)
150 ni_id1 = data['NetworkInterface']['NetworkInterfaceId']
151 clean_ni1 = self.addResourceCleanUp(
152 self.client.delete_network_interface, NetworkInterfaceId=ni_id1)
153 self.get_network_interface_waiter().wait_available(ni_id1)
154
155 kwargs = {
156 'SubnetId': self.subnet_id,
157 }
158 data = self.client.create_network_interface(*[], **kwargs)
159 ni_id2 = data['NetworkInterface']['NetworkInterfaceId']
160 clean_ni2 = self.addResourceCleanUp(
161 self.client.delete_network_interface, NetworkInterfaceId=ni_id2)
162 self.get_network_interface_waiter().wait_available(ni_id2)
163
164 instance_id = self.run_instance(
165 NetworkInterfaces=[{'NetworkInterfaceId': ni_id1,
166 'DeviceIndex': 0},
167 {'NetworkInterfaceId': ni_id2,
168 'DeviceIndex': 2}])
169
170 instance = self.get_instance(instance_id)
171 nis = instance.get('NetworkInterfaces', [])
172 self.assertEqual(2, len(nis))
173
174 self.client.terminate_instances(InstanceIds=[instance_id])
175 self.get_instance_waiter().wait_delete(instance_id)
176
177 self.get_network_interface_waiter().wait_available(ni_id1)
178 self.get_network_interface_waiter().wait_available(ni_id2)
179
180 self.client.delete_network_interface(
181 NetworkInterfaceId=ni_id2)
182 self.cancelResourceCleanUp(clean_ni2)
183 self.get_network_interface_waiter().wait_delete(ni_id2)
184
185 self.client.delete_network_interface(
186 NetworkInterfaceId=ni_id1)
187 self.cancelResourceCleanUp(clean_ni1)
188 self.get_network_interface_waiter().wait_delete(ni_id1)
189
190 @decorators.idempotent_id('a7dc520a-e828-4347-91e1-385c4e0e6070')
191 @testtools.skipUnless(CONF.aws.image_id, "image id is not defined")
192 def test_create_instance_with_private_ip(self):
193 ip = '10.16.0.12'
194
195 instance_id = self.run_instance(SubnetId=self.subnet_id,
196 PrivateIpAddress=ip)
197
198 instance = self.get_instance(instance_id)
199 self.assertEqual(ip, instance['PrivateIpAddress'])
200
201 self.client.terminate_instances(InstanceIds=[instance_id])
202 self.get_instance_waiter().wait_delete(instance_id)
203
204 @decorators.idempotent_id('582ac8ed-58e7-4f27-bd65-35b999241c63')
205 @testtools.skipUnless(CONF.aws.image_id, "image id is not defined")
206 def test_create_instance_with_invalid_params(self):
207 def _rollback(fn_data):
208 self.client.terminate_instances(
209 InstanceIds=[fn_data['Instances'][0]['InstanceId']])
210
211 kwargs = {
212 'ImageId': CONF.aws.image_id,
213 'InstanceType': CONF.aws.instance_type,
214 'MinCount': 1,
215 'MaxCount': 1,
216 'PrivateIpAddress': '10.16.1.2'
217 }
218 ex_str = ('InvalidParameterCombination'
219 if base.TesterStateHolder().get_ec2_enabled() else
220 'InvalidParameterValue')
221 self.assertRaises(ex_str,
222 self.client.run_instances, rollback_fn=_rollback,
223 **kwargs)
224
225 kwargs = {
226 'ImageId': CONF.aws.image_id,
227 'InstanceType': CONF.aws.instance_type,
228 'MinCount': 1,
229 'MaxCount': 1,
230 'SubnetId': self.subnet_id,
231 'PrivateIpAddress': '10.16.1.12'
232 }
233 self.assertRaises('InvalidParameterValue',
234 self.client.run_instances, rollback_fn=_rollback,
235 **kwargs)
236
237 kwargs = {
238 'SubnetId': self.subnet_id,
239 }
240 data = self.client.create_network_interface(*[], **kwargs)
241 ni_id1 = data['NetworkInterface']['NetworkInterfaceId']
242 self.addResourceCleanUp(self.client.delete_network_interface,
243 NetworkInterfaceId=ni_id1)
244 self.get_network_interface_waiter().wait_available(ni_id1)
245
246 kwargs = {
247 'SubnetId': self.subnet_id,
248 }
249 data = self.client.create_network_interface(*[], **kwargs)
250 ni_id2 = data['NetworkInterface']['NetworkInterfaceId']
251 self.addResourceCleanUp(self.client.delete_network_interface,
252 NetworkInterfaceId=ni_id2)
253 self.get_network_interface_waiter().wait_available(ni_id2)
254
255 # NOTE(andrey-mp): A network interface may not specify a network
256 # interface ID and delete on termination as true
257 kwargs = {
258 'ImageId': CONF.aws.image_id,
259 'InstanceType': CONF.aws.instance_type,
260 'MinCount': 1,
261 'MaxCount': 1,
262 'NetworkInterfaces': [{'NetworkInterfaceId': ni_id1,
263 'DeviceIndex': 0,
264 'DeleteOnTermination': True}]
265 }
266 self.assertRaises('InvalidParameterCombination',
267 self.client.run_instances, rollback_fn=_rollback,
268 **kwargs)
269
270 if CONF.aws.run_incompatible_tests:
271 # NOTE(andrey-mp): Each network interface requires a device index.
272 kwargs = {
273 'ImageId': CONF.aws.image_id,
274 'InstanceType': CONF.aws.instance_type,
275 'MinCount': 1,
276 'MaxCount': 1,
277 'NetworkInterfaces': [{'NetworkInterfaceId': ni_id1},
278 {'NetworkInterfaceId': ni_id2}]
279 }
280 self.assertRaises('InvalidParameterValue',
281 self.client.run_instances, rollback_fn=_rollback,
282 **kwargs)
diff --git a/ec2api/tests/functional/api/test_internet_gateways.py b/ec2api/tests/functional/api/test_internet_gateways.py
deleted file mode 100644
index afdc53e..0000000
--- a/ec2api/tests/functional/api/test_internet_gateways.py
+++ /dev/null
@@ -1,223 +0,0 @@
1# Copyright 2014 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16import time
17
18from oslo_log import log
19from tempest.lib import decorators
20import testtools
21
22from ec2api.tests.functional import base
23from ec2api.tests.functional import config
24
25CONF = config.CONF
26LOG = log.getLogger(__name__)
27
28
29class InternetGatewayTest(base.EC2TestCase):
30
31 VPC_CIDR = '10.4.0.0/20'
32 VPC_CIDR_ALT = '10.5.0.0/20'
33 vpc_id = None
34 vpc_id_alt = None
35
36 @classmethod
37 @base.safe_setup
38 def setUpClass(cls):
39 super(InternetGatewayTest, cls).setUpClass()
40 if not base.TesterStateHolder().get_vpc_enabled():
41 raise cls.skipException('VPC is disabled')
42
43 data = cls.client.create_vpc(CidrBlock=cls.VPC_CIDR)
44 cls.vpc_id = data['Vpc']['VpcId']
45 cls.get_vpc_waiter().wait_available(cls.vpc_id)
46 cls.addResourceCleanUpStatic(cls.client.delete_vpc, VpcId=cls.vpc_id)
47
48 data = cls.client.create_vpc(CidrBlock=cls.VPC_CIDR_ALT)
49 cls.vpc_id_alt = data['Vpc']['VpcId']
50 cls.get_vpc_waiter().wait_available(cls.vpc_id_alt)
51 cls.addResourceCleanUpStatic(cls.client.delete_vpc,
52 VpcId=cls.vpc_id_alt)
53
54 @decorators.idempotent_id('f2d40306-4b18-4e17-90a5-371db0ddc7cb')
55 def test_create_attach_internet_gateway(self):
56 data = self.client.create_internet_gateway()
57 gw_id = data['InternetGateway']['InternetGatewayId']
58 res_clean = self.addResourceCleanUp(
59 self.client.delete_internet_gateway, InternetGatewayId=gw_id)
60 self.assertEmpty(data['InternetGateway'].get('Attachments', []))
61
62 data = self.client.attach_internet_gateway(VpcId=self.vpc_id,
63 InternetGatewayId=gw_id)
64
65 data = self.client.detach_internet_gateway(VpcId=self.vpc_id,
66 InternetGatewayId=gw_id)
67
68 data = self.client.delete_internet_gateway(InternetGatewayId=gw_id)
69 self.cancelResourceCleanUp(res_clean)
70
71 self.assertRaises('InvalidInternetGatewayID.NotFound',
72 self.client.describe_internet_gateways,
73 InternetGatewayIds=[gw_id])
74
75 @decorators.idempotent_id('f092b63d-9460-4d8f-ba8a-bcd380666033')
76 def test_delete_attached_internet_gateway(self):
77 data = self.client.create_internet_gateway()
78 gw_id = data['InternetGateway']['InternetGatewayId']
79 res_clean = self.addResourceCleanUp(
80 self.client.delete_internet_gateway, InternetGatewayId=gw_id)
81 self.assertEmpty(data['InternetGateway'].get('Attachments', []))
82
83 data = self.client.attach_internet_gateway(VpcId=self.vpc_id,
84 InternetGatewayId=gw_id)
85
86 self.assertRaises('DependencyViolation',
87 self.client.delete_internet_gateway,
88 InternetGatewayId=gw_id)
89
90 data = self.client.detach_internet_gateway(VpcId=self.vpc_id,
91 InternetGatewayId=gw_id)
92
93 data = self.client.delete_internet_gateway(InternetGatewayId=gw_id)
94 self.cancelResourceCleanUp(res_clean)
95
96 @decorators.idempotent_id('89700013-5753-4608-8245-4fc99fbb67ea')
97 @testtools.skipUnless(CONF.aws.run_incompatible_tests,
98 "Another error code returned - InvalidParameterValue")
99 def test_attach_detach_invalid_internet_gateway(self):
100 gw_id = "gw-1"
101 self.assertRaises('InvalidInternetGatewayID.NotFound',
102 self.client.attach_internet_gateway,
103 VpcId=self.vpc_id, InternetGatewayId=gw_id)
104
105 self.assertRaises('InvalidInternetGatewayID.NotFound',
106 self.client.detach_internet_gateway,
107 VpcId=self.vpc_id, InternetGatewayId=gw_id)
108
109 @decorators.idempotent_id('e3e4d8c4-8f62-43e8-a24d-bfd292b4144c')
110 def test_double_attach_internet_gateway(self):
111 data = self.client.create_internet_gateway()
112 gw_id = data['InternetGateway']['InternetGatewayId']
113 res_clean = self.addResourceCleanUp(
114 self.client.delete_internet_gateway, InternetGatewayId=gw_id)
115 self.assertEmpty(data['InternetGateway'].get('Attachments', []))
116
117 data = self.client.attach_internet_gateway(VpcId=self.vpc_id,
118 InternetGatewayId=gw_id)
119
120 self.assertRaises('Resource.AlreadyAssociated',
121 self.client.attach_internet_gateway,
122 VpcId=self.vpc_id, InternetGatewayId=gw_id)
123
124 data = self.client.detach_internet_gateway(VpcId=self.vpc_id,
125 InternetGatewayId=gw_id)
126
127 data = self.client.delete_internet_gateway(InternetGatewayId=gw_id)
128 self.cancelResourceCleanUp(res_clean)
129
130 @decorators.idempotent_id('d8f3a488-a4ba-4ed5-998c-3dc6f43d6d9e')
131 def test_attach_one_internet_gateway_to_two_vpcs(self):
132 data = self.client.create_internet_gateway()
133 gw_id = data['InternetGateway']['InternetGatewayId']
134 res_clean = self.addResourceCleanUp(
135 self.client.delete_internet_gateway, InternetGatewayId=gw_id)
136 self.assertEmpty(data['InternetGateway'].get('Attachments', []))
137
138 data = self.client.attach_internet_gateway(VpcId=self.vpc_id,
139 InternetGatewayId=gw_id)
140
141 self.assertRaises('Resource.AlreadyAssociated',
142 self.client.attach_internet_gateway,
143 VpcId=self.vpc_id_alt, InternetGatewayId=gw_id)
144
145 data = self.client.detach_internet_gateway(VpcId=self.vpc_id,
146 InternetGatewayId=gw_id)
147
148 data = self.client.delete_internet_gateway(InternetGatewayId=gw_id)
149 self.cancelResourceCleanUp(res_clean)
150
151 @decorators.idempotent_id('b86f338c-613e-4cd7-9742-07c86864b0da')
152 def test_describe_internet_gateways_base(self):
153 data = self.client.create_internet_gateway()
154 gw_id = data['InternetGateway']['InternetGatewayId']
155 res_clean = self.addResourceCleanUp(
156 self.client.delete_internet_gateway, InternetGatewayId=gw_id)
157 self.assertEmpty(data['InternetGateway'].get('Attachments', []))
158
159 data = self.client.attach_internet_gateway(VpcId=self.vpc_id,
160 InternetGatewayId=gw_id)
161 self.addResourceCleanUp(self.client.detach_internet_gateway,
162 VpcId=self.vpc_id,
163 InternetGatewayId=gw_id)
164
165 time.sleep(2)
166 # NOTE(andrey-mp): by real id
167 data = self.client.describe_internet_gateways(
168 InternetGatewayIds=[gw_id])
169 self.assertEqual(1, len(data['InternetGateways']))
170
171 # NOTE(andrey-mp): by fake id
172 self.assertRaises('InvalidInternetGatewayID.NotFound',
173 self.client.describe_internet_gateways,
174 InternetGatewayIds=['igw-0'])
175
176 data = self.client.detach_internet_gateway(VpcId=self.vpc_id,
177 InternetGatewayId=gw_id)
178
179 data = self.client.delete_internet_gateway(InternetGatewayId=gw_id)
180 self.cancelResourceCleanUp(res_clean)
181
182 @decorators.idempotent_id('3f141c56-9ee6-46bf-9c14-0d922ed8a482')
183 def test_describe_internet_gateways_filters(self):
184 # NOTE(andrey-mp): by filter real vpc-id before creation
185 data = self.client.describe_internet_gateways(
186 Filters=[{'Name': 'attachment.vpc-id', 'Values': [self.vpc_id]}])
187 self.assertEqual(0, len(data['InternetGateways']))
188
189 data = self.client.create_internet_gateway()
190 gw_id = data['InternetGateway']['InternetGatewayId']
191 res_clean = self.addResourceCleanUp(
192 self.client.delete_internet_gateway, InternetGatewayId=gw_id)
193 self.assertEmpty(data['InternetGateway'].get('Attachments', []))
194
195 data = self.client.attach_internet_gateway(VpcId=self.vpc_id,
196 InternetGatewayId=gw_id)
197 self.addResourceCleanUp(self.client.detach_internet_gateway,
198 VpcId=self.vpc_id,
199 InternetGatewayId=gw_id)
200
201 time.sleep(2)
202 # NOTE(andrey-mp): by filter real vpc-id
203 data = self.client.describe_internet_gateways(
204 Filters=[{'Name': 'attachment.vpc-id', 'Values': [self.vpc_id]}])
205 self.assertEqual(1, len(data['InternetGateways']))
206 self.assertEqual(gw_id,
207 data['InternetGateways'][0]['InternetGatewayId'])
208
209 # NOTE(andrey-mp): by filter fake vpc-id
210 data = self.client.describe_internet_gateways(
211 Filters=[{'Name': 'attachment.vpc-id', 'Values': ['vpc-0']}])
212 self.assertEqual(0, len(data['InternetGateways']))
213
214 # NOTE(andrey-mp): by fake filter
215 self.assertRaises('InvalidParameterValue',
216 self.client.describe_internet_gateways,
217 Filters=[{'Name': 'fake', 'Values': ['fake']}])
218
219 data = self.client.detach_internet_gateway(VpcId=self.vpc_id,
220 InternetGatewayId=gw_id)
221
222 data = self.client.delete_internet_gateway(InternetGatewayId=gw_id)
223 self.cancelResourceCleanUp(res_clean)
diff --git a/ec2api/tests/functional/api/test_key_pairs.py b/ec2api/tests/functional/api/test_key_pairs.py
deleted file mode 100644
index 21687e9..0000000
--- a/ec2api/tests/functional/api/test_key_pairs.py
+++ /dev/null
@@ -1,149 +0,0 @@
1# Copyright 2014 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from tempest.lib import decorators
17import testtools
18
19from ec2api.tests.functional import base
20from ec2api.tests.functional import config
21
22CONF = config.CONF
23
24
25class KeyPairTest(base.EC2TestCase):
26
27 @decorators.idempotent_id('15cfd866-d6bb-473a-9b8a-6420900a5ca3')
28 def test_create_delete_key_pair(self):
29 keyName = 'Test key'
30 data = self.client.create_key_pair(KeyName=keyName)
31 res_clean = self.addResourceCleanUp(self.client.delete_key_pair,
32 KeyName=keyName)
33
34 self.assertEqual(keyName, data['KeyName'])
35 self.assertIsNotNone(data.get('KeyFingerprint'))
36 self.assertGreater(len(data['KeyFingerprint']), 0)
37 self.assertGreater(len(data.get('KeyMaterial')), 0)
38
39 data = self.client.delete_key_pair(KeyName=keyName)
40 self.cancelResourceCleanUp(res_clean)
41
42 @decorators.idempotent_id('05478a51-1505-42a8-8c7d-4fd7e32c467e')
43 def test_create_duplicate_key_pair(self):
44 keyName = 'Test key'
45 self.client.create_key_pair(KeyName=keyName)
46 res_clean = self.addResourceCleanUp(self.client.delete_key_pair,
47 KeyName=keyName)
48
49 self.assertRaises('InvalidKeyPair.Duplicate',
50 self.client.create_key_pair,
51 KeyName=keyName)
52
53 self.client.delete_key_pair(KeyName=keyName)
54 self.cancelResourceCleanUp(res_clean)
55
56 @decorators.idempotent_id('43d87b6e-6667-4d19-8c0b-e73901105bb7')
57 def test_describe_key_pairs(self):
58 keyName = 'Test key'
59 data = self.client.create_key_pair(KeyName=keyName)
60 res_clean = self.addResourceCleanUp(self.client.delete_key_pair,
61 KeyName=keyName)
62 self.assertIsNotNone(data.get('KeyFingerprint'))
63 self.assertGreater(len(data['KeyFingerprint']), 0)
64 fingerprint = data.get('KeyFingerprint')
65
66 data = self.client.describe_key_pairs(KeyNames=[keyName])
67 self.assertEqual(1, len(data.get('KeyPairs')))
68 data = data['KeyPairs'][0]
69 self.assertEqual(keyName, data['KeyName'])
70 self.assertIsNotNone(data.get('KeyFingerprint'))
71 self.assertGreater(len(data['KeyFingerprint']), 0)
72 self.assertIsNone(data.get('KeyMaterial'))
73
74 data = self.client.describe_key_pairs(
75 Filters=[{'Name': 'key-name', 'Values': [keyName]}])
76 self.assertEqual(1, len(data.get('KeyPairs')))
77 self.assertEqual(keyName, data['KeyPairs'][0]['KeyName'])
78
79 data = self.client.describe_key_pairs(
80 Filters=[{'Name': 'fingerprint', 'Values': [fingerprint]}])
81 self.assertEqual(1, len(data.get('KeyPairs')))
82 self.assertEqual(keyName, data['KeyPairs'][0]['KeyName'])
83
84 self.assertRaises('InvalidKeyPair.NotFound',
85 self.client.describe_key_pairs,
86 KeyNames=['fake key'])
87
88 data = self.client.delete_key_pair(KeyName=keyName)
89 self.cancelResourceCleanUp(res_clean)
90
91 self.assertRaises('InvalidKeyPair.NotFound',
92 self.client.describe_key_pairs,
93 KeyNames=[keyName])
94
95 # NOTE(andrey-mp): Amazon allows to delete absent key and returns 200
96 self.client.delete_key_pair(KeyName=keyName)
97
98 @decorators.idempotent_id('0e51eec5-3f61-4d8a-89c9-8d098f381682')
99 def test_import_empty_key_pair(self):
100 keyName = 'Test key'
101 publicKey = ''
102
103 def _rollback(fn_data):
104 self.client.delete_key_pair(KeyName=keyName)
105
106 self.assertRaises('MissingParameter',
107 self.client.import_key_pair,
108 rollback_fn=_rollback,
109 KeyName=keyName, PublicKeyMaterial=publicKey)
110
111 @decorators.idempotent_id('478c17e6-b7ca-4115-bee2-be279bdd0f65')
112 @testtools.skipUnless(CONF.aws.run_incompatible_tests,
113 "Different error code")
114 def test_import_invalid_key_pair(self):
115 keyName = 'Test key'
116 publicKey = 'ssh-rsa JUNK test@ubuntu'
117
118 def _rollback():
119 self.client.delete_key_pair(KeyName=keyName)
120
121 self.assertRaises('InvalidKey.Format',
122 self.client.import_key_pair,
123 rollback_fn=_rollback,
124 KeyName=keyName, PublicKeyMaterial=publicKey)
125
126 @decorators.idempotent_id('eda525d6-144b-4840-b6ba-e18d93e3589f')
127 def test_import_key_pair(self):
128 keyName = 'Test key'
129 publicKey = ("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCs"
130 "Ne3/1ILNCqFyfYWDeTKLD6jEXC2OQHLmietMWW+/vd"
131 "aZq7KZEwO0jhglaFjU1mpqq4Gz5RX156sCTNM9vRbw"
132 "KAxfsdF9laBYVsex3m3Wmui3uYrKyumsoJn2g9GNnG1P"
133 "I1mrVjZ61i0GY3khna+wzlTpCCmy5HNlrmbj3XLqBUpip"
134 "TOXmsnr4sChzC53KCd8LXuwc1i/CZPvF+3XipvAgFSE53pCt"
135 "LOeB1kYMOBaiUPLQTWXR3JpckqFIQwhIH0zoHlJvZE8hh90"
136 "XcPojYN56tI0OlrGqojbediJYD0rUsJu4weZpbn8vilb3JuDY+jws"
137 "snSA8wzBx3A/8y9Pp1B test@ubuntu")
138 data = self.client.import_key_pair(KeyName=keyName,
139 PublicKeyMaterial=publicKey)
140 res_clean = self.addResourceCleanUp(self.client.delete_key_pair,
141 KeyName=keyName)
142
143 self.assertEqual(keyName, data['KeyName'])
144 self.assertIsNotNone(data.get('KeyFingerprint'))
145 self.assertGreater(len(data['KeyFingerprint']), 0)
146 self.assertIsNone(data.get('KeyMaterial'))
147
148 self.client.delete_key_pair(KeyName=keyName)
149 self.cancelResourceCleanUp(res_clean)
diff --git a/ec2api/tests/functional/api/test_network_interfaces.py b/ec2api/tests/functional/api/test_network_interfaces.py
deleted file mode 100644
index 75bcdcf..0000000
--- a/ec2api/tests/functional/api/test_network_interfaces.py
+++ /dev/null
@@ -1,582 +0,0 @@
1# Copyright 2014 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16import time
17
18import botocore.exceptions
19from oslo_log import log
20from tempest.lib.common.utils import data_utils
21from tempest.lib import decorators
22import testtools
23
24from ec2api.tests.functional import base
25from ec2api.tests.functional import config
26
27CONF = config.CONF
28
29LOG = log.getLogger(__name__)
30
31
32class NetworkInterfaceTest(base.EC2TestCase):
33
34 VPC_CIDR = '10.7.0.0/20'
35 vpc_id = None
36 SUBNET_CIDR = '10.7.0.0/28'
37 subnet_id = None
38
39 @classmethod
40 @base.safe_setup
41 def setUpClass(cls):
42 super(NetworkInterfaceTest, cls).setUpClass()
43 if not base.TesterStateHolder().get_vpc_enabled():
44 raise cls.skipException('VPC is disabled')
45
46 data = cls.client.create_vpc(CidrBlock=cls.VPC_CIDR)
47 cls.vpc_id = data['Vpc']['VpcId']
48 cls.addResourceCleanUpStatic(cls.client.delete_vpc, VpcId=cls.vpc_id)
49 cls.get_vpc_waiter().wait_available(cls.vpc_id)
50
51 aws_zone = CONF.aws.aws_zone
52 data = cls.client.create_subnet(VpcId=cls.vpc_id,
53 CidrBlock=cls.SUBNET_CIDR,
54 AvailabilityZone=aws_zone)
55 cls.subnet_id = data['Subnet']['SubnetId']
56 cls.addResourceCleanUpStatic(cls.client.delete_subnet,
57 SubnetId=cls.subnet_id)
58 cls.get_subnet_waiter().wait_available(cls.subnet_id)
59
60 def _wait_assignment(self, ni_id, data):
61 # NOTE(andrey-mp): Amazon don't do it quickly and there is no way
62 # to wait this request
63 time.sleep(5)
64
65 @decorators.idempotent_id('d03f49b1-a77e-439b-96e2-5e152b968863')
66 def test_delete_subnet_with_network_interface(self):
67 data = self.client.create_subnet(VpcId=self.vpc_id,
68 CidrBlock='10.7.1.0/28')
69 subnet_id = data['Subnet']['SubnetId']
70 res_clean_subnet = self.addResourceCleanUp(self.client.delete_subnet,
71 SubnetId=subnet_id)
72 self.get_subnet_waiter().wait_available(subnet_id)
73
74 data = self.client.create_network_interface(SubnetId=subnet_id)
75 ni_id = data['NetworkInterface']['NetworkInterfaceId']
76 res_clean_ni = self.addResourceCleanUp(
77 self.client.delete_network_interface, NetworkInterfaceId=ni_id)
78 self.get_network_interface_waiter().wait_available(ni_id)
79 time.sleep(2)
80
81 self.assertRaises('DependencyViolation',
82 self.client.delete_subnet,
83 SubnetId=subnet_id)
84
85 self.client.delete_network_interface(NetworkInterfaceId=ni_id)
86 self.cancelResourceCleanUp(res_clean_ni)
87 self.get_network_interface_waiter().wait_delete(ni_id)
88
89 self.client.delete_subnet(SubnetId=subnet_id)
90 self.cancelResourceCleanUp(res_clean_subnet)
91 self.get_subnet_waiter().wait_delete(subnet_id)
92
93 @decorators.idempotent_id('e19e450d-5c24-47b1-9814-4a65a78e5a31')
94 def test_create_network_interface(self):
95 desc = data_utils.rand_name('ni')
96 data = self.client.create_network_interface(SubnetId=self.subnet_id,
97 Description=desc)
98 ni_id = data['NetworkInterface']['NetworkInterfaceId']
99 res_clean = self.addResourceCleanUp(
100 self.client.delete_network_interface, NetworkInterfaceId=ni_id)
101 ni = data['NetworkInterface']
102 self.assertEqual(self.vpc_id, ni['VpcId'])
103 self.assertEqual(self.subnet_id, ni['SubnetId'])
104 self.assertEqual(desc, ni['Description'])
105
106 self.assertNotEmpty(ni.get('Groups'))
107 self.assertEqual('default', ni['Groups'][0]['GroupName'])
108
109 address = ni.get('PrivateIpAddress')
110 self.assertIsNotNone(address)
111 addresses = ni.get('PrivateIpAddresses')
112 self.assertIsNotNone(addresses)
113 self.assertEqual(1, len(addresses))
114 self.assertTrue(addresses[0]['Primary'])
115 self.assertEqual(address, addresses[0]['PrivateIpAddress'])
116
117 self.assertIsNotNone(ni.get('MacAddress'))
118 self.assertIsNotNone(ni.get('OwnerId'))
119 self.assertIsNotNone(ni.get('RequesterManaged'))
120 self.assertIsNotNone(ni.get('SourceDestCheck'))
121
122 self.get_network_interface_waiter().wait_available(ni_id)
123
124 self.client.delete_network_interface(NetworkInterfaceId=ni_id)
125 self.cancelResourceCleanUp(res_clean)
126 self.get_network_interface_waiter().wait_delete(ni_id)
127
128 self.assertRaises('InvalidNetworkInterfaceID.NotFound',
129 self.client.describe_network_interfaces,
130 NetworkInterfaceIds=[ni_id])
131
132 # TODO(andrey-mp): add creation with addresses
133
134 @decorators.idempotent_id('61e16648-7736-4647-b618-27d3f4f0c9c6')
135 def test_create_max_network_interface(self):
136 # NOTE(andrey-mp): wait some time while all ports will be deleted
137 # for this subnet(that are deleting after previous test)
138 time.sleep(5)
139
140 data = self.client.describe_subnets(SubnetIds=[self.subnet_id])
141 count_before = data['Subnets'][0]['AvailableIpAddressCount']
142 addresses = []
143 while True:
144 try:
145 data = self.client.create_network_interface(
146 SubnetId=self.subnet_id)
147 except botocore.exceptions.ClientError as e:
148 error_code = e.response['Error']['Code']
149 self.assertEqual('InsufficientFreeAddressesInSubnet',
150 error_code, e.message)
151 break
152 ni_id = data['NetworkInterface']['NetworkInterfaceId']
153 res_clean = self.addResourceCleanUp(
154 self.client.delete_network_interface,
155 NetworkInterfaceId=ni_id)
156 addresses.append((ni_id, res_clean))
157
158 data = self.client.describe_subnets(SubnetIds=[self.subnet_id])
159 count_after = data['Subnets'][0]['AvailableIpAddressCount']
160 # NOTE(andrey-mp): This is strange but Amazon can't create last NI
161 # and Openstack can
162 self.assertIn(count_after, [0, 1])
163 self.assertEqual(len(addresses), count_before - count_after)
164
165 for addr in addresses:
166 self.client.delete_network_interface(NetworkInterfaceId=addr[0])
167 self.cancelResourceCleanUp(addr[1])
168 self.get_network_interface_waiter().wait_delete(addr[0])
169
170 @decorators.idempotent_id('8c174e5f-e377-4bf2-9315-b868a8199c17')
171 def test_unassign_primary_addresses(self):
172 data = self.client.create_network_interface(SubnetId=self.subnet_id)
173 ni_id = data['NetworkInterface']['NetworkInterfaceId']
174 res_clean = self.addResourceCleanUp(
175 self.client.delete_network_interface, NetworkInterfaceId=ni_id)
176 primary_address = data['NetworkInterface'].get('PrivateIpAddress')
177 self.get_network_interface_waiter().wait_available(ni_id)
178
179 self.assertRaises('InvalidParameterValue',
180 self.client.unassign_private_ip_addresses,
181 NetworkInterfaceId=ni_id,
182 PrivateIpAddresses=[primary_address])
183
184 self.client.delete_network_interface(NetworkInterfaceId=ni_id)
185 self.cancelResourceCleanUp(res_clean)
186 self.get_network_interface_waiter().wait_delete(ni_id)
187
188 @decorators.idempotent_id('de0d0375-d99a-476c-939a-0e15c4e431a8')
189 def test_assign_unassign_private_addresses_by_count(self):
190 data = self.client.describe_subnets(SubnetIds=[self.subnet_id])
191 count = data['Subnets'][0]['AvailableIpAddressCount']
192 data = self.client.create_network_interface(SubnetId=self.subnet_id)
193 ni_id = data['NetworkInterface']['NetworkInterfaceId']
194 res_clean = self.addResourceCleanUp(
195 self.client.delete_network_interface, NetworkInterfaceId=ni_id)
196 self.get_network_interface_waiter().wait_available(ni_id)
197
198 data = self.client.assign_private_ip_addresses(
199 NetworkInterfaceId=ni_id,
200 SecondaryPrivateIpAddressCount=2)
201 self._wait_assignment(ni_id, data)
202
203 data = self.client.describe_subnets(SubnetIds=[self.subnet_id])
204 count_after = data['Subnets'][0]['AvailableIpAddressCount']
205 self.assertEqual(count - 3, count_after)
206
207 data = self.client.describe_network_interfaces(
208 NetworkInterfaceIds=[ni_id])
209
210 addresses = []
211 for addr in data['NetworkInterfaces'][0]['PrivateIpAddresses']:
212 if not addr['Primary']:
213 addresses.append(addr['PrivateIpAddress'])
214 self.assertEqual(2, len(addresses))
215
216 data = self.client.unassign_private_ip_addresses(
217 NetworkInterfaceId=ni_id,
218 PrivateIpAddresses=addresses)
219 self._wait_assignment(ni_id, data)
220
221 data = self.client.describe_subnets(SubnetIds=[self.subnet_id])
222 count_after = data['Subnets'][0]['AvailableIpAddressCount']
223 self.assertEqual(count - 1, count_after)
224
225 self.client.delete_network_interface(NetworkInterfaceId=ni_id)
226 self.cancelResourceCleanUp(res_clean)
227 self.get_network_interface_waiter().wait_delete(ni_id)
228
229 @decorators.idempotent_id('5d7bda42-d23e-4cbf-9e66-8ca052ac28ff')
230 def test_assign_unassign_private_addresses_by_addresses(self):
231 data = self.client.describe_subnets(SubnetIds=[self.subnet_id])
232 count = data['Subnets'][0]['AvailableIpAddressCount']
233 data = self.client.create_network_interface(SubnetId=self.subnet_id)
234 ni_id = data['NetworkInterface']['NetworkInterfaceId']
235 res_clean = self.addResourceCleanUp(
236 self.client.delete_network_interface, NetworkInterfaceId=ni_id)
237 self.get_network_interface_waiter().wait_available(ni_id)
238
239 ni = self.client.describe_network_interfaces(
240 NetworkInterfaceIds=[ni_id])['NetworkInterfaces']
241 ni_addr = ni[0]['PrivateIpAddresses'][0]['PrivateIpAddress']
242
243 # add two more addresses to interface.
244 # check that they does not equal to current.
245 addresses = []
246 for i in range(10, 13):
247 addr = '10.7.0.%d' % i
248 if addr != ni_addr:
249 addresses.append(addr)
250 if len(addresses) >= 2:
251 break
252 data = self.client.assign_private_ip_addresses(
253 NetworkInterfaceId=ni_id,
254 PrivateIpAddresses=addresses)
255 self._wait_assignment(ni_id, data)
256
257 data = self.client.describe_subnets(SubnetIds=[self.subnet_id])
258 count_after = data['Subnets'][0]['AvailableIpAddressCount']
259 # NOTE(Alex): Amazon misses 1 IP address by some reason.
260 self.assertIn(count_after, [count - 3, count - 4])
261
262 data = self.client.describe_network_interfaces(
263 NetworkInterfaceIds=[ni_id])
264
265 assigned_addresses = []
266 for addr in data['NetworkInterfaces'][0]['PrivateIpAddresses']:
267 if not addr['Primary']:
268 self.assertIn(addr['PrivateIpAddress'], addresses)
269 assigned_addresses.append(addr['PrivateIpAddress'])
270 self.assertEqual(2, len(assigned_addresses))
271
272 data = self.client.unassign_private_ip_addresses(
273 NetworkInterfaceId=ni_id,
274 PrivateIpAddresses=addresses)
275 self._wait_assignment(ni_id, data)
276
277 data = self.client.describe_subnets(SubnetIds=[self.subnet_id])
278 count_after = data['Subnets'][0]['AvailableIpAddressCount']
279 self.assertIn(count_after, [count - 1, count - 2])
280
281 self.client.delete_network_interface(NetworkInterfaceId=ni_id)
282 self.cancelResourceCleanUp(res_clean)
283 self.get_network_interface_waiter().wait_delete(ni_id)
284
285 @decorators.idempotent_id('0c514bb4-5800-4db0-9032-0aa3ab998612')
286 @testtools.skipUnless(CONF.aws.image_id, "image id is not defined")
287 def test_attach_network_interface(self):
288 data = self.client.create_network_interface(SubnetId=self.subnet_id)
289 ni_id = data['NetworkInterface']['NetworkInterfaceId']
290 self.addResourceCleanUp(self.client.delete_network_interface,
291 NetworkInterfaceId=ni_id)
292 ni = data['NetworkInterface']
293 address = ni.get('PrivateIpAddress')
294 self.assertIsNotNone(address)
295 self.get_network_interface_waiter().wait_available(ni_id)
296
297 instance_id = self.run_instance(SubnetId=self.subnet_id)
298
299 # NOTE(andrey-mp): Amazon can't attach to device index = 0
300 kwargs = {
301 'DeviceIndex': 0,
302 'InstanceId': instance_id,
303 'NetworkInterfaceId': ni_id
304 }
305 self.assertRaises('InvalidParameterValue',
306 self.client.attach_network_interface,
307 **kwargs)
308
309 kwargs = {
310 'DeviceIndex': 2,
311 'InstanceId': instance_id,
312 'NetworkInterfaceId': ni_id
313 }
314 data = self.client.attach_network_interface(*[], **kwargs)
315 attachment_id = data['AttachmentId']
316
317 instance = self.get_instance(instance_id)
318 nis = instance.get('NetworkInterfaces', [])
319 self.assertEqual(2, len(nis))
320 ids = [nis[0]['Attachment']['AttachmentId'],
321 nis[1]['Attachment']['AttachmentId']]
322 self.assertIn(attachment_id, ids)
323
324 self.assertRaises('InvalidParameterValue',
325 self.client.delete_network_interface,
326 NetworkInterfaceId=ni_id)
327
328 self.client.detach_network_interface(AttachmentId=attachment_id)
329
330 self.client.terminate_instances(InstanceIds=[instance_id])
331 self.get_instance_waiter().wait_delete(instance_id)
332
333 @decorators.idempotent_id('381c9995-bc83-4e7e-b716-25a451660ace')
334 @testtools.skipUnless(CONF.aws.image_id, "image id is not defined")
335 def test_network_interfaces_are_not_deleted_on_termination(self):
336 instance_id = self.run_instance(SubnetId=self.subnet_id)
337
338 instance = self.get_instance(instance_id)
339 nis = instance.get('NetworkInterfaces', [])
340 self.assertEqual(1, len(nis))
341 self.assertTrue(nis[0]['Attachment']['DeleteOnTermination'])
342 ni_id = nis[0]['NetworkInterfaceId']
343 attachment_id = nis[0]['Attachment']['AttachmentId']
344
345 kwargs = {
346 'NetworkInterfaceId': ni_id,
347 'Attachment': {
348 'AttachmentId': attachment_id,
349 'DeleteOnTermination': False,
350 }
351 }
352 self.client.modify_network_interface_attribute(*[], **kwargs)
353 clean_ni = self.addResourceCleanUp(
354 self.client.delete_network_interface, NetworkInterfaceId=ni_id)
355
356 data = self.client.create_network_interface(SubnetId=self.subnet_id)
357 ni_id2 = data['NetworkInterface']['NetworkInterfaceId']
358 clean_ni2 = self.addResourceCleanUp(
359 self.client.delete_network_interface, NetworkInterfaceId=ni_id2)
360 self.get_network_interface_waiter().wait_available(ni_id2)
361 kwargs = {
362 'DeviceIndex': 2,
363 'InstanceId': instance_id,
364 'NetworkInterfaceId': ni_id2
365 }
366 data = self.client.attach_network_interface(*[], **kwargs)
367 attachment_id = data['AttachmentId']
368
369 instance = self.get_instance(instance_id)
370 nis = instance.get('NetworkInterfaces', [])
371 self.assertEqual(2, len(nis))
372 ni = nis[0]
373 if ni['Attachment']['AttachmentId'] != attachment_id:
374 ni = nis[1]
375 self.assertEqual(attachment_id, ni['Attachment']['AttachmentId'])
376 self.assertFalse(ni['Attachment']['DeleteOnTermination'])
377
378 self.client.terminate_instances(InstanceIds=[instance_id])
379 self.get_instance_waiter().wait_delete(instance_id)
380
381 self.get_network_interface_waiter().wait_available(ni_id)
382 self.get_network_interface_waiter().wait_available(ni_id2)
383
384 self.client.delete_network_interface(NetworkInterfaceId=ni_id)
385 self.cancelResourceCleanUp(clean_ni)
386 self.get_network_interface_waiter().wait_delete(ni_id)
387
388 self.client.delete_network_interface(NetworkInterfaceId=ni_id2)
389 self.cancelResourceCleanUp(clean_ni2)
390 self.get_network_interface_waiter().wait_delete(ni_id2)
391
392 @decorators.idempotent_id('de910bc7-008a-40c2-b4b2-4587a489fc1c')
393 @testtools.skipUnless(CONF.aws.image_id, "image id is not defined")
394 def test_network_interfaces_are_deleted_on_termination(self):
395 instance_id = self.run_instance(SubnetId=self.subnet_id)
396
397 instance = self.get_instance(instance_id)
398 nis = instance.get('NetworkInterfaces', [])
399 self.assertEqual(1, len(nis))
400 self.assertTrue(nis[0]['Attachment']['DeleteOnTermination'])
401 ni_id = nis[0]['NetworkInterfaceId']
402
403 data = self.client.create_network_interface(SubnetId=self.subnet_id)
404 ni_id2 = data['NetworkInterface']['NetworkInterfaceId']
405 self.addResourceCleanUp(self.client.delete_network_interface,
406 NetworkInterfaceId=ni_id2)
407 self.get_network_interface_waiter().wait_available(ni_id2)
408 kwargs = {
409 'DeviceIndex': 2,
410 'InstanceId': instance_id,
411 'NetworkInterfaceId': ni_id2
412 }
413 data = self.client.attach_network_interface(*[], **kwargs)
414 attachment_id = data['AttachmentId']
415
416 kwargs = {
417 'NetworkInterfaceId': ni_id2,
418 'Attachment': {
419 'AttachmentId': attachment_id,
420 'DeleteOnTermination': True,
421 }
422 }
423 self.client.modify_network_interface_attribute(*[], **kwargs)
424
425 self.client.terminate_instances(InstanceIds=[instance_id])
426 self.get_instance_waiter().wait_delete(instance_id)
427
428 self.get_network_interface_waiter().wait_delete(ni_id)
429 self.get_network_interface_waiter().wait_delete(ni_id2)
430
431 @decorators.idempotent_id('028eb864-59e9-4ed6-a062-9d5de9eba652')
432 def test_network_interface_attribute_description(self):
433 desc = data_utils.rand_name('ni')
434 data = self.client.create_network_interface(
435 SubnetId=self.subnet_id, Description=desc)
436 ni_id = data['NetworkInterface']['NetworkInterfaceId']
437 res_clean = self.addResourceCleanUp(
438 self.client.delete_network_interface, NetworkInterfaceId=ni_id)
439 self.get_network_interface_waiter().wait_available(ni_id)
440
441 data = self.client.describe_network_interface_attribute(
442 NetworkInterfaceId=ni_id, Attribute='description')
443 self.assertEqual(desc, data['Description']['Value'])
444
445 new_desc = data_utils.rand_name('new-ni')
446 self.client.modify_network_interface_attribute(
447 NetworkInterfaceId=ni_id, Description={'Value': new_desc})
448
449 data = self.client.describe_network_interface_attribute(
450 NetworkInterfaceId=ni_id, Attribute='description')
451 self.assertEqual(new_desc, data['Description']['Value'])
452
453 self.client.delete_network_interface(NetworkInterfaceId=ni_id)
454 self.cancelResourceCleanUp(res_clean)
455 self.get_network_interface_waiter().wait_delete(ni_id)
456
457 @decorators.idempotent_id('9428b5e6-42f2-495f-a535-df53d1fcf4af')
458 def test_network_interface_attribute_source_dest_check(self):
459 data = self.client.create_network_interface(SubnetId=self.subnet_id)
460 ni_id = data['NetworkInterface']['NetworkInterfaceId']
461 res_clean = self.addResourceCleanUp(
462 self.client.delete_network_interface, NetworkInterfaceId=ni_id)
463 self.get_network_interface_waiter().wait_available(ni_id)
464
465 self.client.modify_network_interface_attribute(
466 NetworkInterfaceId=ni_id, SourceDestCheck={'Value': False})
467
468 data = self.client.describe_network_interface_attribute(
469 NetworkInterfaceId=ni_id, Attribute='sourceDestCheck')
470 self.assertFalse(data['SourceDestCheck']['Value'])
471
472 # NOTE(andrey-mp): ResetNetworkInterfaceAttribute had inadequate json
473 # scheme in botocore and doesn't work against Amazon.
474
475 self.client.modify_network_interface_attribute(
476 NetworkInterfaceId=ni_id, SourceDestCheck={'Value': True})
477
478 data = self.client.describe_network_interface_attribute(
479 NetworkInterfaceId=ni_id, Attribute='sourceDestCheck')
480 self.assertEqual(True, data['SourceDestCheck']['Value'])
481
482 self.client.delete_network_interface(NetworkInterfaceId=ni_id)
483 self.cancelResourceCleanUp(res_clean)
484 self.get_network_interface_waiter().wait_delete(ni_id)
485
486 @decorators.idempotent_id('19d25f59-5b32-4314-b4da-7c8f679b7a96')
487 @testtools.skipUnless(CONF.aws.image_id, "image id is not defined")
488 def test_network_interface_attribute_attachment(self):
489 instance_id = self.run_instance(SubnetId=self.subnet_id)
490
491 instance = self.get_instance(instance_id)
492 nis = instance.get('NetworkInterfaces', [])
493 self.assertEqual(1, len(nis))
494 self.assertTrue(nis[0]['Attachment']['DeleteOnTermination'])
495 ni_id = nis[0]['NetworkInterfaceId']
496
497 data = self.client.describe_network_interface_attribute(
498 NetworkInterfaceId=ni_id, Attribute='attachment')
499 self.assertIn('Attachment', data)
500 self.assertTrue(data['Attachment'].get('AttachmentId'))
501 self.assertTrue(data['Attachment'].get('DeleteOnTermination'))
502 self.assertEqual(0, data['Attachment'].get('DeviceIndex'))
503 self.assertEqual(instance_id, data['Attachment'].get('InstanceId'))
504 self.assertEqual('attached', data['Attachment'].get('Status'))
505
506 self.client.terminate_instances(InstanceIds=[instance_id])
507 self.get_instance_waiter().wait_delete(instance_id)
508
509 @decorators.idempotent_id('74967cd0-155f-4cfe-994e-2c6803dad04c')
510 def test_network_interface_attribute_empty_attachment(self):
511 data = self.client.create_network_interface(SubnetId=self.subnet_id)
512 ni_id = data['NetworkInterface']['NetworkInterfaceId']
513 res_clean = self.addResourceCleanUp(
514 self.client.delete_network_interface, NetworkInterfaceId=ni_id)
515 self.get_network_interface_waiter().wait_available(ni_id)
516
517 data = self.client.describe_network_interface_attribute(
518 NetworkInterfaceId=ni_id, Attribute='attachment')
519 self.assertNotIn('Attachment', data)
520
521 self.client.delete_network_interface(NetworkInterfaceId=ni_id)
522 self.cancelResourceCleanUp(res_clean)
523 self.get_network_interface_waiter().wait_delete(ni_id)
524
525 @decorators.idempotent_id('a55f1169-d302-4166-b74e-e84a0d79129c')
526 def test_network_interface_attribute_group_set(self):
527 data = self.client.create_network_interface(SubnetId=self.subnet_id)
528 ni_id = data['NetworkInterface']['NetworkInterfaceId']
529 res_clean = self.addResourceCleanUp(
530 self.client.delete_network_interface, NetworkInterfaceId=ni_id)
531 self.get_network_interface_waiter().wait_available(ni_id)
532
533 data = self.client.describe_network_interface_attribute(
534 NetworkInterfaceId=ni_id, Attribute='groupSet')
535 self.assertIn('Groups', data)
536 self.assertEqual(1, len(data['Groups']))
537 self.assertEqual('default', data['Groups'][0]['GroupName'])
538
539 self.client.delete_network_interface(NetworkInterfaceId=ni_id)
540 self.cancelResourceCleanUp(res_clean)
541 self.get_network_interface_waiter().wait_delete(ni_id)
542
543 @decorators.idempotent_id('7832976f-27cb-405e-ab05-466b102d86f8')
544 def test_instance_attributes_negative(self):
545 data = self.client.create_network_interface(SubnetId=self.subnet_id)
546 ni_id = data['NetworkInterface']['NetworkInterfaceId']
547 res_clean = self.addResourceCleanUp(
548 self.client.delete_network_interface, NetworkInterfaceId=ni_id)
549 self.get_network_interface_waiter().wait_available(ni_id)
550
551 self.assertRaises('InvalidParameterCombination',
552 self.client.describe_network_interface_attribute,
553 NetworkInterfaceId=ni_id)
554 self.assertRaises('InvalidParameterValue',
555 self.client.describe_network_interface_attribute,
556 NetworkInterfaceId=ni_id, Attribute='fake')
557 self.assertRaises('InvalidNetworkInterfaceID.NotFound',
558 self.client.describe_network_interface_attribute,
559 NetworkInterfaceId='eni-0', Attribute='description')
560
561 self.assertRaises('InvalidParameterCombination',
562 self.client.modify_network_interface_attribute,
563 NetworkInterfaceId=ni_id)
564 self.assertRaises('MissingParameter',
565 self.client.modify_network_interface_attribute,
566 NetworkInterfaceId=ni_id,
567 Attachment={'AttachmentId': 'fake'})
568 self.assertRaises('InvalidAttachmentID.NotFound',
569 self.client.modify_network_interface_attribute,
570 NetworkInterfaceId=ni_id,
571 Attachment={'AttachmentId': 'eni-attach-0',
572 'DeleteOnTermination': True})
573 self.assertRaises('InvalidGroup.NotFound',
574 self.client.modify_network_interface_attribute,
575 NetworkInterfaceId=ni_id, Groups=['sg-0'])
576 self.assertRaises('InvalidParameterCombination',
577 self.client.modify_network_interface_attribute,
578 NetworkInterfaceId=ni_id, Description={})
579
580 self.client.delete_network_interface(NetworkInterfaceId=ni_id)
581 self.cancelResourceCleanUp(res_clean)
582 self.get_network_interface_waiter().wait_delete(ni_id)
diff --git a/ec2api/tests/functional/api/test_regions.py b/ec2api/tests/functional/api/test_regions.py
deleted file mode 100644
index 7d68271..0000000
--- a/ec2api/tests/functional/api/test_regions.py
+++ /dev/null
@@ -1,47 +0,0 @@
1# Copyright 2014 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from tempest.lib import decorators
17
18from ec2api.tests.functional import base
19from ec2api.tests.functional import config
20
21CONF = config.CONF
22
23
24class RegionTest(base.EC2TestCase):
25
26 @decorators.idempotent_id('f303e87e-4e5f-4110-a5da-5f690acb44ba')
27 def test_describe_regions(self):
28 data = self.client.describe_regions()
29 self.assertNotEmpty(data['Regions'])
30
31 region = CONF.aws.aws_region
32 if not region:
33 return
34
35 regions = [r['RegionName'] for r in data['Regions']]
36 self.assertIn(region, regions)
37
38 @decorators.idempotent_id('be38f383-4637-4581-bb62-b47c1463f0a1')
39 def test_describe_zones(self):
40 data = self.client.describe_availability_zones()
41 self.assertNotEmpty(data['AvailabilityZones'])
42
43 region = CONF.aws.aws_region
44 if not region:
45 return
46
47 # TODO(andrey-mp): add checking of other fields of returned data
diff --git a/ec2api/tests/functional/api/test_routes.py b/ec2api/tests/functional/api/test_routes.py
deleted file mode 100644
index d610b71..0000000
--- a/ec2api/tests/functional/api/test_routes.py
+++ /dev/null
@@ -1,338 +0,0 @@
1# Copyright 2014 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from oslo_log import log
17from tempest.lib import decorators
18
19from ec2api.tests.functional import base
20from ec2api.tests.functional import config
21
22CONF = config.CONF
23LOG = log.getLogger(__name__)
24
25
26class RouteTest(base.EC2TestCase):
27
28 VPC_CIDR = '10.14.0.0/20'
29 SUBNET_CIDR = '10.14.0.0/24'
30 vpc_id = None
31
32 @classmethod
33 @base.safe_setup
34 def setUpClass(cls):
35 super(RouteTest, cls).setUpClass()
36 if not base.TesterStateHolder().get_vpc_enabled():
37 raise cls.skipException('VPC is disabled')
38
39 data = cls.client.create_vpc(CidrBlock=cls.VPC_CIDR)
40 cls.vpc_id = data['Vpc']['VpcId']
41 cls.addResourceCleanUpStatic(cls.client.delete_vpc, VpcId=cls.vpc_id)
42 cls.get_vpc_waiter().wait_available(cls.vpc_id)
43
44 @decorators.idempotent_id('69c04d14-5603-4a98-9331-739821b98b10')
45 def test_create_delete_route_table(self):
46 data = self.client.create_route_table(VpcId=self.vpc_id)
47 rt_id = data['RouteTable']['RouteTableId']
48 res_clean = self.addResourceCleanUp(self.client.delete_route_table,
49 RouteTableId=rt_id)
50 rt = data['RouteTable']
51 self.assertEqual(self.vpc_id, rt['VpcId'])
52 self.assertEqual(1, len(rt['Routes']))
53 route = rt['Routes'][0]
54 self.assertEqual(self.VPC_CIDR, route['DestinationCidrBlock'])
55 self.assertEqual('active', route['State'])
56
57 data = self.client.delete_route_table(RouteTableId=rt_id)
58 self.cancelResourceCleanUp(res_clean)
59
60 self.assertRaises('InvalidRouteTableID.NotFound',
61 self.client.describe_route_tables,
62 RouteTableIds=[rt_id])
63
64 self.assertRaises('InvalidRouteTableID.NotFound',
65 self.client.delete_route_table,
66 RouteTableId=rt_id)
67
68 @decorators.idempotent_id('d8051b30-eb70-4c4b-988b-56078a125af3')
69 def test_describe_route_tables_base(self):
70 data = self.client.create_route_table(VpcId=self.vpc_id)
71 rt_id = data['RouteTable']['RouteTableId']
72 res_clean = self.addResourceCleanUp(self.client.delete_route_table,
73 RouteTableId=rt_id)
74
75 # NOTE(andrey-mp): by real id
76 data = self.client.describe_route_tables(RouteTableIds=[rt_id])
77 self.assertEqual(1, len(data['RouteTables']))
78
79 # NOTE(andrey-mp): by fake id
80 self.assertRaises('InvalidRouteTableID.NotFound',
81 self.client.describe_route_tables,
82 RouteTableIds=['rtb-0'])
83
84 data = self.client.delete_route_table(RouteTableId=rt_id)
85 self.cancelResourceCleanUp(res_clean)
86
87 @decorators.idempotent_id('77a53f3e-437a-45ed-b3b5-e6b7ab2c9407')
88 def test_describe_route_tables_filters(self):
89 data = self.client.create_route_table(VpcId=self.vpc_id)
90 rt_id = data['RouteTable']['RouteTableId']
91 self.addResourceCleanUp(self.client.delete_route_table,
92 RouteTableId=rt_id)
93
94 data = self.client.create_subnet(VpcId=self.vpc_id,
95 CidrBlock=self.SUBNET_CIDR)
96 subnet_id = data['Subnet']['SubnetId']
97 self.addResourceCleanUp(self.client.delete_subnet,
98 SubnetId=subnet_id)
99 self.get_subnet_waiter().wait_available(subnet_id)
100
101 data = self.client.associate_route_table(RouteTableId=rt_id,
102 SubnetId=subnet_id)
103 assoc_id = data['AssociationId']
104 self.addResourceCleanUp(self.client.disassociate_route_table,
105 AssociationId=assoc_id)
106
107 # NOTE(andrey-mp): by association_id
108 data = self.client.describe_route_tables(
109 Filters=[{'Name': 'association.route-table-association-id',
110 'Values': [assoc_id]}])
111 self.assertEqual(1, len(data['RouteTables']))
112
113 # NOTE(andrey-mp): by route table id
114 data = self.client.describe_route_tables(
115 Filters=[{'Name': 'association.route-table-id',
116 'Values': [rt_id]}])
117 self.assertEqual(1, len(data['RouteTables']))
118
119 # NOTE(andrey-mp): by subnet id
120 data = self.client.describe_route_tables(
121 Filters=[{'Name': 'association.subnet-id',
122 'Values': [subnet_id]}])
123 self.assertEqual(1, len(data['RouteTables']))
124
125 # NOTE(andrey-mp): by filter real vpc
126 data = self.client.describe_route_tables(
127 Filters=[{'Name': 'vpc-id', 'Values': [self.vpc_id]}])
128 self.assertLess(0, len(data['RouteTables']))
129
130 # NOTE(andrey-mp): by filter fake vpc
131 data = self.client.describe_route_tables(
132 Filters=[{'Name': 'vpc-id', 'Values': ['vpc-0']}])
133 self.assertEqual(0, len(data['RouteTables']))
134
135 # NOTE(andrey-mp): by fake filter
136 self.assertRaises('InvalidParameterValue',
137 self.client.describe_route_tables,
138 Filters=[{'Name': 'fake', 'Values': ['fake']}])
139
140 @decorators.idempotent_id('55361f57-331a-43b8-8729-efee2d1c0dc9')
141 def test_associate_disassociate_route_table(self):
142 data = self.client.create_route_table(VpcId=self.vpc_id)
143 rt_id = data['RouteTable']['RouteTableId']
144 res_clean_rt = self.addResourceCleanUp(self.client.delete_route_table,
145 RouteTableId=rt_id)
146
147 data = self.client.create_subnet(VpcId=self.vpc_id,
148 CidrBlock=self.SUBNET_CIDR)
149 subnet_id = data['Subnet']['SubnetId']
150 res_clean_subnet = self.addResourceCleanUp(self.client.delete_subnet,
151 SubnetId=subnet_id)
152 self.get_subnet_waiter().wait_available(subnet_id)
153
154 data = self.client.associate_route_table(RouteTableId=rt_id,
155 SubnetId=subnet_id)
156 assoc_id = data['AssociationId']
157 res_clean = self.addResourceCleanUp(
158 self.client.disassociate_route_table, AssociationId=assoc_id)
159
160 data = self.client.disassociate_route_table(AssociationId=assoc_id)
161 self.cancelResourceCleanUp(res_clean)
162
163 data = self.client.delete_subnet(SubnetId=subnet_id)
164 self.cancelResourceCleanUp(res_clean_subnet)
165 self.get_subnet_waiter().wait_delete(subnet_id)
166
167 data = self.client.delete_route_table(RouteTableId=rt_id)
168 self.cancelResourceCleanUp(res_clean_rt)
169
170 @decorators.idempotent_id('b1a07211-6e9a-41db-8017-47e7c4b9c043')
171 def test_replace_route_table(self):
172 data = self.client.create_subnet(VpcId=self.vpc_id,
173 CidrBlock=self.SUBNET_CIDR)
174 subnet_id = data['Subnet']['SubnetId']
175 res_clean_subnet = self.addResourceCleanUp(self.client.delete_subnet,
176 SubnetId=subnet_id)
177 self.get_subnet_waiter().wait_available(subnet_id)
178
179 # NOTE(andrey-mp): by vpc id
180 data = self.client.describe_route_tables(
181 Filters=[{'Name': 'vpc-id', 'Values': [self.vpc_id]}])
182 self.assertEqual(1, len(data['RouteTables']))
183 self.assertEqual(1, len(data['RouteTables'][0]['Associations']))
184 default_rt_id = data['RouteTables'][0]['RouteTableId']
185 main_assoc = data['RouteTables'][0]['Associations'][0]
186 self.assertTrue(main_assoc['Main'])
187 main_assoc_id = main_assoc['RouteTableAssociationId']
188
189 data = self.client.create_route_table(VpcId=self.vpc_id)
190 rt_id = data['RouteTable']['RouteTableId']
191 res_clean_rt = self.addResourceCleanUp(self.client.delete_route_table,
192 RouteTableId=rt_id)
193
194 data = self.client.replace_route_table_association(
195 RouteTableId=rt_id, AssociationId=main_assoc_id)
196 assoc_id = data['NewAssociationId']
197 res_clean = self.addResourceCleanUp(
198 self.client.replace_route_table_association,
199 RouteTableId=default_rt_id,
200 AssociationId=assoc_id)
201
202 # NOTE(andrey-mp): by vpc id
203 data = self.client.describe_route_tables(
204 Filters=[{'Name': 'vpc-id', 'Values': [self.vpc_id]}])
205 self.assertEqual(2, len(data['RouteTables']))
206 for rt in data['RouteTables']:
207 if rt['RouteTableId'] == rt_id:
208 self.assertEqual(1, len(rt['Associations']))
209 self.assertTrue(rt['Associations'][0]['Main'])
210 else:
211 self.assertEmpty(rt.get('Associations', []))
212
213 self.assertRaises('DependencyViolation',
214 self.client.delete_route_table,
215 RouteTableId=rt_id)
216
217 self.assertRaises('InvalidParameterValue',
218 self.client.disassociate_route_table,
219 AssociationId=assoc_id)
220
221 data = self.client.replace_route_table_association(
222 RouteTableId=default_rt_id,
223 AssociationId=assoc_id)
224 self.cancelResourceCleanUp(res_clean)
225
226 data = self.client.delete_route_table(RouteTableId=rt_id)
227 self.cancelResourceCleanUp(res_clean_rt)
228
229 data = self.client.delete_subnet(SubnetId=subnet_id)
230 self.cancelResourceCleanUp(res_clean_subnet)
231 self.get_subnet_waiter().wait_delete(subnet_id)
232
233 @decorators.idempotent_id('c112ecdb-dce3-4497-b11b-5349a2d89336')
234 def test_create_delete_route(self):
235 data = self.client.create_subnet(VpcId=self.vpc_id,
236 CidrBlock=self.SUBNET_CIDR)
237 subnet_id = data['Subnet']['SubnetId']
238 res_clean_subnet = self.addResourceCleanUp(self.client.delete_subnet,
239 SubnetId=subnet_id)
240 self.get_subnet_waiter().wait_available(subnet_id)
241
242 kwargs = {
243 'SubnetId': subnet_id,
244 }
245 data = self.client.create_network_interface(*[], **kwargs)
246 ni_id = data['NetworkInterface']['NetworkInterfaceId']
247 res_clean_ni = self.addResourceCleanUp(
248 self.client.delete_network_interface,
249 NetworkInterfaceId=ni_id)
250
251 data = self.client.create_route_table(VpcId=self.vpc_id)
252 rt_id = data['RouteTable']['RouteTableId']
253 res_clean_rt = self.addResourceCleanUp(self.client.delete_route_table,
254 RouteTableId=rt_id)
255
256 kwargs = {
257 'DestinationCidrBlock': self.VPC_CIDR,
258 'RouteTableId': rt_id,
259 'NetworkInterfaceId': ni_id
260 }
261 self.assertRaises('InvalidParameterValue',
262 self.client.create_route,
263 **kwargs)
264
265 # can create wider route
266 kwargs = {
267 'DestinationCidrBlock': '10.14.0.0/19',
268 'RouteTableId': rt_id,
269 'NetworkInterfaceId': ni_id
270 }
271 data = self.client.create_route(*[], **kwargs)
272 # can create to another vpc
273 kwargs = {
274 'DestinationCidrBlock': '10.15.0.0/20',
275 'RouteTableId': rt_id,
276 'NetworkInterfaceId': ni_id
277 }
278 data = self.client.create_route(*[], **kwargs)
279
280 data = self.client.describe_route_tables(RouteTableIds=[rt_id])
281 self.assertEqual(1, len(data['RouteTables']))
282 self.assertEqual(3, len(data['RouteTables'][0]['Routes']))
283
284 kwargs = {
285 'DestinationCidrBlock': '10.15.0.0/24',
286 'RouteTableId': rt_id,
287 }
288 self.assertRaises('InvalidRoute.NotFound',
289 self.client.delete_route,
290 **kwargs)
291
292 kwargs = {
293 'DestinationCidrBlock': self.VPC_CIDR,
294 'RouteTableId': rt_id,
295 }
296 self.assertRaises('InvalidParameterValue',
297 self.client.delete_route,
298 **kwargs)
299
300 kwargs = {
301 'DestinationCidrBlock': self.SUBNET_CIDR,
302 'RouteTableId': rt_id,
303 }
304 self.assertRaises('InvalidRoute.NotFound',
305 self.client.delete_route,
306 **kwargs)
307
308 kwargs = {
309 'DestinationCidrBlock': '10.16.0.0/24',
310 'RouteTableId': rt_id,
311 }
312 self.assertRaises('InvalidRoute.NotFound',
313 self.client.delete_route,
314 **kwargs)
315
316 kwargs = {
317 'DestinationCidrBlock': '10.15.0.0/20',
318 'RouteTableId': rt_id,
319 }
320 data = self