From 27a8a06dd9a8c7186965d6c94d0854f5096a6630 Mon Sep 17 00:00:00 2001 From: silvacarloss Date: Tue, 17 May 2022 20:33:14 +0000 Subject: [PATCH] Add functional tests for group type access This change tests the positive scenarios for share group type access commands. Co-authored-by: Vida Haririan Change-Id: I244a9526832cf683d9a2b466aeae6c09f2073a25 --- manilaclient/tests/functional/osc/base.py | 38 ++++++++ .../osc/test_share_group_type_access.py | 88 +++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 manilaclient/tests/functional/osc/test_share_group_type_access.py diff --git a/manilaclient/tests/functional/osc/base.py b/manilaclient/tests/functional/osc/base.py index ad04da6d7..260f511b1 100644 --- a/manilaclient/tests/functional/osc/base.py +++ b/manilaclient/tests/functional/osc/base.py @@ -348,3 +348,41 @@ class OSCClientTestBase(base.ClientTestBase): cmd = (f'replica export location list {replica}') export_locations = self.listing_result('share', cmd) return export_locations + + def create_share_group_type(self, name=None, share_types=None, + group_specs=None, public=True, + add_cleanup=True): + + name = name or data_utils.rand_name('autotest_share_group_types_name') + share_types = share_types or 'None' + + cmd = (f'group type create ' + f'{name} ' + f'{share_types} ') + + if group_specs: + cmd = cmd + f' --group_specs {group_specs} ' + if not public: + cmd = cmd + f' --public {public} ' + + share_object = self.dict_result('share', cmd) + + if add_cleanup: + self.addCleanup( + self.openstack, + 'share group type delete %s' % share_object['id']) + return share_object + + def share_group_type_access_create(self, group_type, project): + cmd = (f'group type access create ' + f'{group_type} ' + f'{project} ') + + self.dict_result('share', cmd) + + def share_group_type_access_delete(self, group_type, access_id): + cmd = (f'group type access delete ' + f'{group_type} ' + f'{access_id} ') + + self.dict_result('share', cmd) diff --git a/manilaclient/tests/functional/osc/test_share_group_type_access.py b/manilaclient/tests/functional/osc/test_share_group_type_access.py new file mode 100644 index 000000000..2ea865e0f --- /dev/null +++ b/manilaclient/tests/functional/osc/test_share_group_type_access.py @@ -0,0 +1,88 @@ +# 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 oslo_serialization import jsonutils + +from manilaclient.tests.functional.osc import base + + +class SharesGroupTypeAccessCLITest(base.OSCClientTestBase): + + def test_share_group_type_access_create(self): + share_group_type_name = self.create_share_group_type( + share_types='dhss_false', public=False)['name'] + + access_list = self.listing_result( + 'share', f'group type access list {share_group_type_name}') + self.assertEqual(0, len(access_list)) + + cmd_output = jsonutils.loads(self.openstack('token issue -f json ')) + auth_project_id = cmd_output['project_id'] + + self.share_group_type_access_create( + share_group_type_name, auth_project_id) + + share_group_type_access_list = self.listing_result( + 'share', f'group type access list {share_group_type_name}') + + self.assertEqual(1, len(share_group_type_access_list)) + + def test_share_group_type_access_delete(self): + share_group_type_name = self.create_share_group_type( + share_types='dhss_false', public=False)['name'] + + access_list = self.listing_result( + 'share', f'group type access list {share_group_type_name}') + self.assertEqual(0, len(access_list)) + + cmd_output = jsonutils.loads(self.openstack('token issue -f json ')) + auth_project_id = cmd_output['project_id'] + + # Create using name to ensure that we are "translating" the + # name into the actual ID in the CLI + self.share_group_type_access_create( + share_group_type_name, auth_project_id) + + share_group_type_access_list = self.listing_result( + 'share', f'group type access list {share_group_type_name}') + + self.assertEqual(1, len(share_group_type_access_list)) + self.assertEqual( + share_group_type_access_list[0]['Project ID'], auth_project_id) + + self.share_group_type_access_delete( + share_group_type_name, auth_project_id) + + access_list = self.listing_result( + 'share', f'group type access list {share_group_type_name}') + self.assertEqual(0, len(access_list)) + + def test_share_group_type_access_list(self): + share_group_type_name = self.create_share_group_type( + share_types='dhss_false', public=False)['name'] + + access_list = self.listing_result( + 'share', f'group type access list {share_group_type_name}') + self.assertEqual(0, len(access_list)) + + cmd_output = jsonutils.loads(self.openstack('token issue -f json ')) + auth_project_id = cmd_output['project_id'] + + self.share_group_type_access_create( + share_group_type_name, auth_project_id) + + share_group_type_access_list = self.listing_result( + 'share', f'group type access list {share_group_type_name}') + + self.assertEqual(1, len(share_group_type_access_list)) + self.assertTableStruct(access_list, ['Project ID'])