rossella | e02431e | 2013-11-15 17:58:29 +0100 | [diff] [blame] | 1 | # 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 | |
| 16 | from tempest.api.network import base |
| 17 | |
| 18 | |
| 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 |
| 23 | |
armando-migliaccio | 88f7b70 | 2014-06-05 12:59:09 -0700 | [diff] [blame] | 24 | def _cleanup_router(self, router): |
| 25 | self.delete_router(router) |
| 26 | self.routers.remove(router) |
| 27 | |
zhufl | d2c40ca | 2016-10-18 17:03:07 +0800 | [diff] [blame] | 28 | def _create_router(self, name=None, admin_state_up=False, |
armando-migliaccio | 88f7b70 | 2014-06-05 12:59:09 -0700 | [diff] [blame] | 29 | external_network_id=None, enable_snat=None): |
| 30 | # associate a cleanup with created routers to avoid quota limits |
| 31 | router = self.create_router(name, admin_state_up, |
| 32 | external_network_id, enable_snat) |
| 33 | self.addCleanup(self._cleanup_router, router) |
| 34 | return router |
| 35 | |
Ken'ichi Ohmichi | e35f472 | 2015-12-22 04:57:11 +0000 | [diff] [blame] | 36 | def _delete_router(self, router_id, routers_client=None): |
| 37 | client = routers_client or self.routers_client |
armando-migliaccio | 88f7b70 | 2014-06-05 12:59:09 -0700 | [diff] [blame] | 38 | client.delete_router(router_id) |
rossella | e02431e | 2013-11-15 17:58:29 +0100 | [diff] [blame] | 39 | # Asserting that the router is not found in the list |
| 40 | # after deletion |
Ken'ichi Ohmichi | e35f472 | 2015-12-22 04:57:11 +0000 | [diff] [blame] | 41 | list_body = self.routers_client.list_routers() |
rossella | e02431e | 2013-11-15 17:58:29 +0100 | [diff] [blame] | 42 | routers_list = list() |
| 43 | for router in list_body['routers']: |
| 44 | routers_list.append(router['id']) |
| 45 | self.assertNotIn(router_id, routers_list) |
| 46 | |
armando-migliaccio | ee90a4d | 2014-05-06 11:54:07 -0700 | [diff] [blame] | 47 | def _add_router_interface_with_subnet_id(self, router_id, subnet_id): |
Ken'ichi Ohmichi | e35f472 | 2015-12-22 04:57:11 +0000 | [diff] [blame] | 48 | interface = self.routers_client.add_router_interface( |
| 49 | router_id, subnet_id=subnet_id) |
armando-migliaccio | ee90a4d | 2014-05-06 11:54:07 -0700 | [diff] [blame] | 50 | self.addCleanup(self._remove_router_interface_with_subnet_id, |
| 51 | router_id, subnet_id) |
| 52 | self.assertEqual(subnet_id, interface['subnet_id']) |
| 53 | return interface |
| 54 | |
rossella | e02431e | 2013-11-15 17:58:29 +0100 | [diff] [blame] | 55 | def _remove_router_interface_with_subnet_id(self, router_id, subnet_id): |
Ken'ichi Ohmichi | e35f472 | 2015-12-22 04:57:11 +0000 | [diff] [blame] | 56 | body = self.routers_client.remove_router_interface(router_id, |
| 57 | subnet_id=subnet_id) |
liudong | fbdfc7e | 2014-02-15 10:52:17 +0800 | [diff] [blame] | 58 | self.assertEqual(subnet_id, body['subnet_id']) |
rossella | e02431e | 2013-11-15 17:58:29 +0100 | [diff] [blame] | 59 | |
| 60 | def _remove_router_interface_with_port_id(self, router_id, port_id): |
Ken'ichi Ohmichi | e35f472 | 2015-12-22 04:57:11 +0000 | [diff] [blame] | 61 | body = self.routers_client.remove_router_interface(router_id, |
| 62 | port_id=port_id) |
liudong | fbdfc7e | 2014-02-15 10:52:17 +0800 | [diff] [blame] | 63 | self.assertEqual(port_id, body['port_id']) |