1 # Copyright 2013 OpenStack Foundation
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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
16 from neutron.tests.api import base
19 class BaseRouterTest(base.BaseAdminNetworkTest):
20 # NOTE(salv-orlando): This class inherits from BaseAdminNetworkTest
21 # as some router operations, such as enabling or disabling SNAT
22 # require admin credentials by default
25 def resource_setup(cls):
26 super(BaseRouterTest, cls).resource_setup()
28 def _cleanup_router(self, router):
29 self.delete_router(router)
30 self.routers.remove(router)
32 def _create_router(self, name, admin_state_up=False,
33 external_network_id=None, enable_snat=None):
34 # associate a cleanup with created routers to avoid quota limits
35 router = self.create_router(name, admin_state_up,
36 external_network_id, enable_snat)
37 self.addCleanup(self._cleanup_router, router)
40 def _delete_router(self, router_id, network_client=None):
41 client = network_client or self.client
42 client.delete_router(router_id)
43 # Asserting that the router is not found in the list
45 list_body = self.client.list_routers()
47 for router in list_body['routers']:
48 routers_list.append(router['id'])
49 self.assertNotIn(router_id, routers_list)
51 def _add_router_interface_with_subnet_id(self, router_id, subnet_id):
52 interface = self.client.add_router_interface_with_subnet_id(
54 self.addCleanup(self._remove_router_interface_with_subnet_id,
56 self.assertEqual(subnet_id, interface['subnet_id'])
59 def _remove_router_interface_with_subnet_id(self, router_id, subnet_id):
60 body = self.client.remove_router_interface_with_subnet_id(
62 self.assertEqual(subnet_id, body['subnet_id'])
64 def _remove_router_interface_with_port_id(self, router_id, port_id):
65 body = self.client.remove_router_interface_with_port_id(router_id,
67 self.assertEqual(port_id, body['port_id'])