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