1
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2
# not use this file except in compliance with the License. You may obtain
3
# a copy of the License at
5
# http://www.apache.org/licenses/LICENSE-2.0
7
# Unless required by applicable law or agreed to in writing, software
8
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10
# License for the specific language governing permissions and limitations
13
from tempest_lib.common.utils import data_utils
15
from neutron.tests.tempest.api.network import base
16
from neutron.tests.tempest import test
19
class ExternalNetworksTestJSON(base.BaseAdminNetworkTest):
22
def resource_setup(cls):
23
super(ExternalNetworksTestJSON, cls).resource_setup()
24
cls.network = cls.create_network()
26
def _create_network(self, external=True):
27
post_body = {'name': data_utils.rand_name('network-')}
29
post_body['router:external'] = external
30
body = self.admin_client.create_network(**post_body)
31
network = body['network']
32
self.addCleanup(self.admin_client.delete_network, network['id'])
35
@test.idempotent_id('462be770-b310-4df9-9c42-773217e4c8b1')
36
def test_create_external_network(self):
37
# Create a network as an admin user specifying the
38
# external network extension attribute
39
ext_network = self._create_network()
40
# Verifies router:external parameter
41
self.assertIsNotNone(ext_network['id'])
42
self.assertTrue(ext_network['router:external'])
44
@test.idempotent_id('4db5417a-e11c-474d-a361-af00ebef57c5')
45
def test_update_external_network(self):
46
# Update a network as an admin user specifying the
47
# external network extension attribute
48
network = self._create_network(external=False)
49
self.assertFalse(network.get('router:external', False))
50
update_body = {'router:external': True}
51
body = self.admin_client.update_network(network['id'],
53
updated_network = body['network']
54
# Verify that router:external parameter was updated
55
self.assertTrue(updated_network['router:external'])
57
@test.idempotent_id('39be4c9b-a57e-4ff9-b7c7-b218e209dfcc')
58
def test_list_external_networks(self):
60
external_network = self._create_network()
61
# List networks as a normal user and confirm the external
62
# network extension attribute is returned for those networks
63
# that were created as external
64
body = self.client.list_networks()
65
networks_list = [net['id'] for net in body['networks']]
66
self.assertIn(external_network['id'], networks_list)
67
self.assertIn(self.network['id'], networks_list)
68
for net in body['networks']:
69
if net['id'] == self.network['id']:
70
self.assertFalse(net['router:external'])
71
elif net['id'] == external_network['id']:
72
self.assertTrue(net['router:external'])
74
@test.idempotent_id('2ac50ab2-7ebd-4e27-b3ce-a9e399faaea2')
75
def test_show_external_networks_attribute(self):
77
external_network = self._create_network()
78
# Show an external network as a normal user and confirm the
79
# external network extension attribute is returned.
80
body = self.client.show_network(external_network['id'])
81
show_ext_net = body['network']
82
self.assertEqual(external_network['name'], show_ext_net['name'])
83
self.assertEqual(external_network['id'], show_ext_net['id'])
84
self.assertTrue(show_ext_net['router:external'])
85
body = self.client.show_network(self.network['id'])
86
show_net = body['network']
87
# Verify with show that router:external is False for network
88
self.assertEqual(self.network['name'], show_net['name'])
89
self.assertEqual(self.network['id'], show_net['id'])
90
self.assertFalse(show_net['router:external'])
92
@test.idempotent_id('82068503-2cf2-4ed4-b3be-ecb89432e4bb')
93
def test_delete_external_networks_with_floating_ip(self):
94
"""Verifies external network can be deleted while still holding
95
(unassociated) floating IPs
98
# Set cls.client to admin to use base.create_subnet()
99
client = self.admin_client
100
body = client.create_network(**{'router:external': True})
101
external_network = body['network']
102
self.addCleanup(self._try_delete_resource,
103
client.delete_network,
104
external_network['id'])
105
subnet = self.create_subnet(external_network, client=client,
107
body = client.create_floatingip(
108
floating_network_id=external_network['id'])
109
created_floating_ip = body['floatingip']
110
self.addCleanup(self._try_delete_resource,
111
client.delete_floatingip,
112
created_floating_ip['id'])
113
floatingip_list = client.list_floatingips(
114
network=external_network['id'])
115
self.assertIn(created_floating_ip['id'],
116
(f['id'] for f in floatingip_list['floatingips']))
117
client.delete_network(external_network['id'])
118
# Verifies floating ip is deleted
119
floatingip_list = client.list_floatingips()
120
self.assertNotIn(created_floating_ip['id'],
121
(f['id'] for f in floatingip_list['floatingips']))
122
# Verifies subnet is deleted
123
subnet_list = client.list_subnets()
124
self.assertNotIn(subnet['id'],
125
(s['id'] for s in subnet_list))
126
# Removes subnet from the cleanup list
127
self.subnets.remove(subnet)