blob: 94db116e8e1b974f7f21800ae6c589a531ff66ac [file] [log] [blame]
Daniel Mellado3c0aeab2016-01-29 11:30:25 +00001# Copyright 2013 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
Jakub Libosvar83704832017-12-06 16:02:28 +000016from tempest.lib import exceptions
17
Chandan Kumar667d3d32017-09-22 12:24:06 +053018from neutron_tempest_plugin.api import base
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000019
20
21class BaseRouterTest(base.BaseAdminNetworkTest):
22 # NOTE(salv-orlando): This class inherits from BaseAdminNetworkTest
23 # as some router operations, such as enabling or disabling SNAT
24 # require admin credentials by default
25
Jakub Libosvar83704832017-12-06 16:02:28 +000026 def _cleanup_router(self, router, client=None):
27 try:
28 self.delete_router(router, client)
29 self.routers.remove(router)
30 except exceptions.NotFound:
31 pass
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000032
33 def _create_router(self, name, admin_state_up=False,
Frode Nordahl395e6fa2023-10-09 17:54:13 +020034 external_network_id=None, enable_snat=None, **kwargs):
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000035 # associate a cleanup with created routers to avoid quota limits
36 router = self.create_router(name, admin_state_up,
Frode Nordahl395e6fa2023-10-09 17:54:13 +020037 external_network_id, enable_snat, **kwargs)
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000038 self.addCleanup(self._cleanup_router, router)
39 return router
40
Jakub Libosvar83704832017-12-06 16:02:28 +000041 def _create_admin_router(self, *args, **kwargs):
42 router = self.create_admin_router(*args, **kwargs)
43 self.addCleanup(
44 self._cleanup_router, router, self.os_admin.network_client)
45 return router
46
Daniel Mellado3c0aeab2016-01-29 11:30:25 +000047 def _delete_router(self, router_id, network_client=None):
48 client = network_client or self.client
49 client.delete_router(router_id)
50 # Asserting that the router is not found in the list
51 # after deletion
52 list_body = self.client.list_routers()
53 routers_list = list()
54 for router in list_body['routers']:
55 routers_list.append(router['id'])
56 self.assertNotIn(router_id, routers_list)