|
0 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
1 |
# not use this file except in compliance with the License. You may obtain
|
|
2 |
# a copy of the License at
|
|
3 |
#
|
|
4 |
# http://www.apache.org/licenses/LICENSE-2.0
|
|
5 |
#
|
|
6 |
# Unless required by applicable law or agreed to in writing, software
|
|
7 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
8 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
9 |
# License for the specific language governing permissions and limitations
|
|
10 |
# under the License.
|
|
11 |
|
|
12 |
import abc
|
|
13 |
|
|
14 |
from tempest.lib import exceptions
|
|
15 |
|
|
16 |
from cinder_tempest_plugin.api.volume import base
|
|
17 |
from cinder_tempest_plugin.rbac.v3 import base as rbac_base
|
|
18 |
|
|
19 |
|
|
20 |
class VolumeV3RbacCapabilityTests(rbac_base.VolumeV3RbacBaseTests,
|
|
21 |
metaclass=abc.ABCMeta):
|
|
22 |
|
|
23 |
@classmethod
|
|
24 |
def setup_clients(cls):
|
|
25 |
super().setup_clients()
|
|
26 |
cls.persona = getattr(cls, 'os_%s' % cls.credentials[0])
|
|
27 |
cls.client = cls.persona.volume_capabilities_client_latest
|
|
28 |
# NOTE(lbragstad): This admin_client will be more useful later when
|
|
29 |
# cinder supports system-scope and we need it for administrative
|
|
30 |
# operations. For now, keep os_project_admin as the admin client until
|
|
31 |
# we have system-scope.
|
|
32 |
admin_client = cls.os_project_admin
|
|
33 |
cls.admin_capabilities_client = (
|
|
34 |
admin_client.volume_capabilities_client_latest)
|
|
35 |
cls.admin_stats_client = (
|
|
36 |
admin_client.volume_scheduler_stats_client_latest)
|
|
37 |
|
|
38 |
@classmethod
|
|
39 |
def setup_credentials(cls):
|
|
40 |
super().setup_credentials()
|
|
41 |
cls.os_primary = getattr(cls, 'os_%s' % cls.credentials[0])
|
|
42 |
|
|
43 |
@abc.abstractmethod
|
|
44 |
def test_get_capabilities(self):
|
|
45 |
"""Test volume_extension:capabilities policy.
|
|
46 |
|
|
47 |
This test must check:
|
|
48 |
* whether the persona can fetch capabilities for a host.
|
|
49 |
|
|
50 |
"""
|
|
51 |
pass
|
|
52 |
|
|
53 |
|
|
54 |
class ProjectAdminTests(VolumeV3RbacCapabilityTests, base.BaseVolumeTest):
|
|
55 |
|
|
56 |
credentials = ['project_admin', 'system_admin']
|
|
57 |
|
|
58 |
def test_get_capabilities(self):
|
|
59 |
pools = self.admin_stats_client.list_pools()['pools']
|
|
60 |
host_name = pools[0]['name']
|
|
61 |
self.do_request('show_backend_capabilities', expected_status=200,
|
|
62 |
host=host_name)
|
|
63 |
|
|
64 |
|
|
65 |
class ProjectMemberTests(ProjectAdminTests, base.BaseVolumeTest):
|
|
66 |
|
|
67 |
credentials = ['project_member', 'project_admin', 'system_admin']
|
|
68 |
|
|
69 |
def test_get_capabilities(self):
|
|
70 |
pools = self.admin_stats_client.list_pools()['pools']
|
|
71 |
host_name = pools[0]['name']
|
|
72 |
self.do_request('show_backend_capabilities',
|
|
73 |
expected_status=exceptions.Forbidden,
|
|
74 |
host=host_name)
|
|
75 |
|
|
76 |
|
|
77 |
class ProjectReaderTests(ProjectMemberTests, base.BaseVolumeTest):
|
|
78 |
|
|
79 |
credentials = ['project_reader', 'project_admin', 'system_admin']
|