Add share access rules to shared file system
Introduce Share Access Rules class with basic methods including list, and get to shared file system storage service Change-Id: I120212e6f1a01644479dc9bc4547b022049c49a1
This commit is contained in:

committed by
Artem Goncharov

parent
6998a8b1eb
commit
012b5a128a
@@ -79,3 +79,13 @@ service.
|
||||
:noindex:
|
||||
:members: share_snapshots, get_share_snapshot, delete_share_snapshot,
|
||||
update_share_snapshot, create_share_snapshot
|
||||
|
||||
|
||||
Shared File System Share Access Rules
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
View access rules for shares from the Shared File Systems service.
|
||||
|
||||
.. autoclass:: openstack.shared_file_system.v2._proxy.Proxy
|
||||
:noindex:
|
||||
:members: access_rules, get_access_rule
|
||||
|
@@ -10,3 +10,4 @@ Shared File System service resources
|
||||
v2/share
|
||||
v2/user_message
|
||||
v2/share_snapshot
|
||||
v2/share_access_rule
|
||||
|
@@ -0,0 +1,13 @@
|
||||
openstack.shared_file_system.v2.share_access_rule
|
||||
=================================================
|
||||
|
||||
.. automodule:: openstack.shared_file_system.v2.share_access_rule
|
||||
|
||||
The ShareAccessRule Class
|
||||
-------------------------
|
||||
|
||||
The ``ShareAccessRule`` class inherits from
|
||||
:class:`~openstack.resource.Resource`.
|
||||
|
||||
.. autoclass:: openstack.shared_file_system.v2.share_access_rule.ShareAccessRule
|
||||
:members:
|
@@ -14,6 +14,9 @@ from openstack import proxy
|
||||
from openstack import resource
|
||||
from openstack.shared_file_system.v2 import (
|
||||
availability_zone as _availability_zone)
|
||||
from openstack.shared_file_system.v2 import (
|
||||
share_access_rule as _share_access_rule
|
||||
)
|
||||
from openstack.shared_file_system.v2 import (
|
||||
share_snapshot as _share_snapshot
|
||||
)
|
||||
@@ -318,3 +321,25 @@ class Proxy(proxy.Proxy):
|
||||
to delete failed to occur in the specified seconds.
|
||||
"""
|
||||
return resource.wait_for_delete(self, res, interval, wait)
|
||||
|
||||
def access_rules(self, share, **query):
|
||||
"""Lists the share access rules on a share.
|
||||
|
||||
:returns: A generator of the share access rules.
|
||||
:rtype: :class:`~openstack.shared_file_system.v2.
|
||||
share_access_rules.ShareAccessRules`
|
||||
"""
|
||||
share = self._get_resource(_share.Share, share)
|
||||
return self._list(
|
||||
_share_access_rule.ShareAccessRule,
|
||||
share_id=share.id, **query)
|
||||
|
||||
def get_access_rule(self, access_id):
|
||||
"""List details of an access rule.
|
||||
|
||||
:returns: Details of the identified access rule.
|
||||
:rtype: :class:`~openstack.shared_file_system.v2.
|
||||
share_access_rules.ShareAccessRules`
|
||||
"""
|
||||
return self._get(
|
||||
_share_access_rule.ShareAccessRule, access_id)
|
||||
|
56
openstack/shared_file_system/v2/share_access_rule.py
Normal file
56
openstack/shared_file_system/v2/share_access_rule.py
Normal file
@@ -0,0 +1,56 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from openstack import resource
|
||||
|
||||
|
||||
class ShareAccessRule(resource.Resource):
|
||||
resource_key = "share_access_rule"
|
||||
resources_key = "share_access_rules"
|
||||
base_path = "/share-access-rules"
|
||||
|
||||
# capabilities
|
||||
allow_create = False
|
||||
allow_fetch = True
|
||||
allow_commit = False
|
||||
allow_delete = False
|
||||
allow_list = True
|
||||
allow_head = False
|
||||
|
||||
_query_mapping = resource.QueryParameters("share_id")
|
||||
|
||||
_max_microversion = '2.45'
|
||||
|
||||
#: Properties
|
||||
#: The access credential of the entity granted share access.
|
||||
access_key = resource.Body("access_key", type=str)
|
||||
#: The access level to the share.
|
||||
access_level = resource.Body("access_level", type=str)
|
||||
#: The object of the access rule.
|
||||
access_list = resource.Body("access_list", type=str)
|
||||
#: The value that defines the access.
|
||||
access_to = resource.Body("access_to", type=str)
|
||||
#: The access rule type.
|
||||
access_type = resource.Body("access_type", type=str)
|
||||
#: The date and time stamp when the resource was created within the
|
||||
#: service’s database.
|
||||
created_at = resource.Body("created_at")
|
||||
#: One or more access rule metadata key and value pairs as a dictionary
|
||||
#: of strings.
|
||||
metadata = resource.Body("metadata", type=dict)
|
||||
#: The UUID of the share to which you are granted or denied access.
|
||||
share_id = resource.Body("share_id", type=str)
|
||||
#: The state of the access rule.
|
||||
state = resource.Body("state", type=str)
|
||||
#: The date and time stamp when the resource was last updated within
|
||||
#: the service’s database.
|
||||
updated_at = resource.Body("updated_at", type=str)
|
@@ -0,0 +1,38 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from openstack.tests.functional.shared_file_system import base
|
||||
|
||||
|
||||
class ShareAccessRuleTest(base.BaseSharedFileSystemTest):
|
||||
|
||||
def setUp(self):
|
||||
super(ShareAccessRuleTest, self).setUp()
|
||||
|
||||
self.SHARE_NAME = self.getUniqueString()
|
||||
mys = self.create_share(
|
||||
name=self.SHARE_NAME, size=2, share_type="dhss_false",
|
||||
share_protocol='NFS', description=None)
|
||||
self.operator_cloud.shared_file_system.wait_for_status(
|
||||
mys,
|
||||
status='available',
|
||||
failures=['error'],
|
||||
interval=5,
|
||||
wait=self._wait_for_timeout)
|
||||
self.assertIsNotNone(mys)
|
||||
self.assertIsNotNone(mys.id)
|
||||
self.SHARE_ID = mys.id
|
||||
|
||||
def test_access_rules(self):
|
||||
# TODO(kafilat): An Access Rule needs to be created
|
||||
# for the new share;
|
||||
pass
|
@@ -12,6 +12,9 @@
|
||||
|
||||
from unittest import mock
|
||||
|
||||
from openstack.shared_file_system.v2 import (
|
||||
share_access_rule
|
||||
)
|
||||
from openstack.shared_file_system.v2 import _proxy
|
||||
from openstack.shared_file_system.v2 import limit
|
||||
from openstack.shared_file_system.v2 import share
|
||||
@@ -172,3 +175,22 @@ class TestShareSnapshotResource(test_proxy_base.TestProxyBase):
|
||||
self.proxy.wait_for_delete(mock_resource)
|
||||
|
||||
mock_wait.assert_called_once_with(self.proxy, mock_resource, 2, 120)
|
||||
|
||||
|
||||
class TestAccessRuleProxy(test_proxy_base.TestProxyBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAccessRuleProxy, self).setUp()
|
||||
self.proxy = _proxy.Proxy(self.session)
|
||||
|
||||
def test_access_rules(self):
|
||||
self.verify_list(
|
||||
self.proxy.access_rules,
|
||||
share_access_rule.ShareAccessRule,
|
||||
method_args=["test_share"],
|
||||
expected_args=[],
|
||||
expected_kwargs={"share_id": "test_share"})
|
||||
|
||||
def test_access_rules_get(self):
|
||||
self.verify_get(
|
||||
self.proxy.get_access_rule, share_access_rule.ShareAccessRule)
|
||||
|
@@ -0,0 +1,58 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from openstack.shared_file_system.v2 import share_access_rule
|
||||
from openstack.tests.unit import base
|
||||
|
||||
EXAMPLE = {
|
||||
"access_level": "rw",
|
||||
"state": "error",
|
||||
"id": "507bf114-36f2-4f56-8cf4-857985ca87c1",
|
||||
"share_id": "fb213952-2352-41b4-ad7b-2c4c69d13eef",
|
||||
"access_type": "cert",
|
||||
"access_to": "example.com",
|
||||
"access_key": None,
|
||||
"created_at": "2021-09-12T02:01:04.000000",
|
||||
"updated_at": "2021-09-12T02:01:04.000000",
|
||||
"metadata": {
|
||||
"key1": "value1",
|
||||
"key2": "value2"}
|
||||
}
|
||||
|
||||
|
||||
class TestShareAccessRule(base.TestCase):
|
||||
|
||||
def test_basic(self):
|
||||
rules_resource = share_access_rule.ShareAccessRule()
|
||||
self.assertEqual('share_access_rules', rules_resource.resources_key)
|
||||
self.assertEqual('/share-access-rules', rules_resource.base_path)
|
||||
self.assertTrue(rules_resource.allow_list)
|
||||
|
||||
self.assertDictEqual({
|
||||
"limit": "limit",
|
||||
"marker": "marker",
|
||||
"share_id": "share_id"
|
||||
},
|
||||
rules_resource._query_mapping._mapping)
|
||||
|
||||
def test_make_share_access_rules(self):
|
||||
rules_resource = share_access_rule.ShareAccessRule(**EXAMPLE)
|
||||
self.assertEqual(EXAMPLE['id'], rules_resource.id)
|
||||
self.assertEqual(EXAMPLE['access_level'], rules_resource.access_level)
|
||||
self.assertEqual(EXAMPLE['state'], rules_resource.state)
|
||||
self.assertEqual(EXAMPLE['id'], rules_resource.id)
|
||||
self.assertEqual(EXAMPLE['access_type'], rules_resource.access_type)
|
||||
self.assertEqual(EXAMPLE['access_to'], rules_resource.access_to)
|
||||
self.assertEqual(EXAMPLE['access_key'], rules_resource.access_key)
|
||||
self.assertEqual(EXAMPLE['created_at'], rules_resource.created_at)
|
||||
self.assertEqual(EXAMPLE['updated_at'], rules_resource.updated_at)
|
||||
self.assertEqual(EXAMPLE['metadata'], rules_resource.metadata)
|
@@ -0,0 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Added support to list and get share access rules with the
|
||||
shared file system service.
|
Reference in New Issue
Block a user