Lance Bragstad | d3fddec | 2021-02-16 16:27:13 +0000 | [diff] [blame] | 1 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | # not use this file except in compliance with the License. You may obtain |
| 3 | # a copy of the License at |
| 4 | # |
| 5 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | # |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | # License for the specific language governing permissions and limitations |
| 11 | # under the License. |
| 12 | |
| 13 | from tempest import config |
Yosi Ben Shimon | 490c825 | 2023-04-24 17:16:51 +0300 | [diff] [blame^] | 14 | from tempest.lib.common import api_microversion_fixture |
| 15 | from tempest.lib.common import api_version_utils |
| 16 | from tempest import test |
Lance Bragstad | d3fddec | 2021-02-16 16:27:13 +0000 | [diff] [blame] | 17 | |
| 18 | CONF = config.CONF |
| 19 | |
| 20 | |
Yosi Ben Shimon | 490c825 | 2023-04-24 17:16:51 +0300 | [diff] [blame^] | 21 | class VolumeV3RbacBaseTests( |
| 22 | api_version_utils.BaseMicroversionTest, test.BaseTestCase |
| 23 | ): |
Lance Bragstad | d3fddec | 2021-02-16 16:27:13 +0000 | [diff] [blame] | 24 | |
| 25 | identity_version = 'v3' |
| 26 | |
| 27 | @classmethod |
| 28 | def skip_checks(cls): |
| 29 | super(VolumeV3RbacBaseTests, cls).skip_checks() |
| 30 | if not CONF.enforce_scope.cinder: |
| 31 | raise cls.skipException( |
| 32 | "Tempest is not configured to enforce_scope for cinder, " |
| 33 | "skipping RBAC tests. To enable these tests set " |
| 34 | "`tempest.conf [enforce_scope] cinder=True`." |
| 35 | ) |
Yosi Ben Shimon | 490c825 | 2023-04-24 17:16:51 +0300 | [diff] [blame^] | 36 | if not CONF.service_available.cinder: |
| 37 | skip_msg = ("%s skipped as Cinder is not available" % cls.__name__) |
| 38 | raise cls.skipException(skip_msg) |
| 39 | |
| 40 | api_version_utils.check_skip_with_microversion( |
| 41 | cls.min_microversion, cls.max_microversion, |
| 42 | CONF.volume.min_microversion, CONF.volume.max_microversion) |
| 43 | |
| 44 | @classmethod |
| 45 | def setup_credentials(cls): |
| 46 | cls.set_network_resources() |
| 47 | super(VolumeV3RbacBaseTests, cls).setup_credentials() |
| 48 | |
| 49 | def setUp(self): |
| 50 | super(VolumeV3RbacBaseTests, self).setUp() |
| 51 | self.useFixture(api_microversion_fixture.APIMicroversionFixture( |
| 52 | volume_microversion=self.request_microversion)) |
| 53 | |
| 54 | @classmethod |
| 55 | def resource_setup(cls): |
| 56 | super(VolumeV3RbacBaseTests, cls).resource_setup() |
| 57 | cls.request_microversion = ( |
| 58 | api_version_utils.select_request_microversion( |
| 59 | cls.min_microversion, |
| 60 | CONF.volume.min_microversion)) |
Lance Bragstad | d3fddec | 2021-02-16 16:27:13 +0000 | [diff] [blame] | 61 | |
| 62 | def do_request(self, method, expected_status=200, client=None, **payload): |
| 63 | if not client: |
| 64 | client = self.client |
| 65 | if isinstance(expected_status, type(Exception)): |
| 66 | self.assertRaises(expected_status, |
| 67 | getattr(client, method), |
| 68 | **payload) |
| 69 | else: |
| 70 | response = getattr(client, method)(**payload) |
| 71 | self.assertEqual(response.response.status, expected_status) |
| 72 | return response |