Slawek Kaplonski | 8dd49aa | 2019-04-16 14:47:07 +0200 | [diff] [blame] | 1 | # Copyright (c) 2015 Ericsson. |
| 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 | import tempest.api.network.base as test |
| 17 | from tempest.common import utils |
| 18 | from tempest import config |
| 19 | from tempest.lib.common.utils import data_utils |
| 20 | |
| 21 | from neutron_tempest_plugin.bgpvpn.services import bgpvpn_client |
| 22 | |
| 23 | CONF = config.CONF |
| 24 | |
| 25 | |
| 26 | class BaseBgpvpnTest(test.BaseNetworkTest): |
| 27 | """Base class for the Bgpvpn tests that use the Tempest Neutron REST client |
| 28 | |
| 29 | """ |
| 30 | |
| 31 | credentials = ['primary', 'admin', 'alt'] |
| 32 | bgpvpn_client = None |
| 33 | bgpvpn_admin_client = None |
| 34 | bgpvpn_alt_client = None |
| 35 | |
| 36 | @classmethod |
| 37 | def resource_cleanup(cls): |
| 38 | for bgpvpn in cls.bgpvpns: |
| 39 | cls.bgpvpn_admin_client.delete_bgpvpn(bgpvpn['id']) |
| 40 | super(BaseBgpvpnTest, cls).resource_cleanup() |
| 41 | |
| 42 | @classmethod |
| 43 | def resource_setup(cls): |
| 44 | cls.route_distinguishers = [] |
| 45 | cls.bgpvpns = [] |
| 46 | cls.bgpvpn_client = bgpvpn_client.BgpvpnClient( |
| 47 | cls.os_primary.auth_provider, |
| 48 | CONF.network.catalog_type, |
| 49 | CONF.network.region or CONF.identity.region, |
| 50 | endpoint_type=CONF.network.endpoint_type, |
| 51 | build_interval=CONF.network.build_interval, |
| 52 | build_timeout=CONF.network.build_timeout, |
| 53 | **cls.os_primary.default_params) |
| 54 | cls.bgpvpn_admin_client = bgpvpn_client.BgpvpnClient( |
| 55 | cls.os_admin.auth_provider, |
| 56 | CONF.network.catalog_type, |
| 57 | CONF.network.region or CONF.identity.region, |
| 58 | endpoint_type=CONF.network.endpoint_type, |
| 59 | build_interval=CONF.network.build_interval, |
| 60 | build_timeout=CONF.network.build_timeout, |
| 61 | **cls.os_admin.default_params) |
| 62 | cls.bgpvpn_alt_client = bgpvpn_client.BgpvpnClient( |
| 63 | cls.os_alt.auth_provider, |
| 64 | CONF.network.catalog_type, |
| 65 | CONF.network.region or CONF.identity.region, |
| 66 | endpoint_type=CONF.network.endpoint_type, |
| 67 | build_interval=CONF.network.build_interval, |
| 68 | build_timeout=CONF.network.build_timeout, |
| 69 | **cls.os_alt.default_params) |
| 70 | super(BaseBgpvpnTest, cls).resource_setup() |
| 71 | |
| 72 | @classmethod |
| 73 | def skip_checks(cls): |
| 74 | super(BaseBgpvpnTest, cls).skip_checks() |
Slawek Kaplonski | a7bb161 | 2019-07-17 15:34:46 +0200 | [diff] [blame] | 75 | msg = None |
Slawek Kaplonski | 8dd49aa | 2019-04-16 14:47:07 +0200 | [diff] [blame] | 76 | if not utils.is_extension_enabled('bgpvpn', 'network'): |
| 77 | msg = "Bgpvpn extension not enabled." |
Slawek Kaplonski | a7bb161 | 2019-07-17 15:34:46 +0200 | [diff] [blame] | 78 | elif not CONF.bgpvpn.run_bgpvpn_tests: |
| 79 | msg = ("Running of bgpvpn related tests is disabled in " |
| 80 | "plugin configuration.") |
| 81 | if msg: |
Slawek Kaplonski | 8dd49aa | 2019-04-16 14:47:07 +0200 | [diff] [blame] | 82 | raise cls.skipException(msg) |
| 83 | |
| 84 | def create_bgpvpn(self, client, **kwargs): |
| 85 | if 'name' not in kwargs: |
| 86 | kwargs['name'] = data_utils.rand_name('test-bgpvpn-') |
| 87 | |
| 88 | body = client.create_bgpvpn(**kwargs) |
| 89 | bgpvpn = body['bgpvpn'] |
| 90 | self.bgpvpns.append(bgpvpn) |
| 91 | return bgpvpn |
| 92 | |
| 93 | def delete_bgpvpn(self, client, bgpvpn): |
| 94 | client.delete_bgpvpn(bgpvpn['id']) |
| 95 | self.bgpvpns.remove(bgpvpn) |