From 38ab09ccbe9cea02fe7230a2580dfc8d64503662 Mon Sep 17 00:00:00 2001 From: alexv Date: Fri, 17 Dec 2021 12:01:03 +0200 Subject: [PATCH] fix use cinder "update_volume_type() got an unexpected keyword argument 'name' " Change-Id: Ie11b428e69c7a4208652d90addbc33b9792e9250 --- .zuul.d/zuul.yaml | 4 ++-- rally_openstack/common/services/storage/block.py | 6 +++--- .../common/services/storage/cinder_v2.py | 3 +-- .../common/services/storage/cinder_v3.py | 13 ++++++------- .../task/scenarios/cinder/volume_types.py | 14 +++++++++++--- .../unit/common/services/storage/test_cinder_v2.py | 10 ++++++---- .../unit/common/services/storage/test_cinder_v3.py | 10 ++++++---- .../task/scenarios/cinder/test_volume_types.py | 7 +++++-- 8 files changed, 40 insertions(+), 27 deletions(-) diff --git a/.zuul.d/zuul.yaml b/.zuul.d/zuul.yaml index 1cde6a6e..073d9423 100644 --- a/.zuul.d/zuul.yaml +++ b/.zuul.d/zuul.yaml @@ -19,8 +19,7 @@ - rally_openstack/task/cleanup/resources.py - rally_openstack/task/scenarios/barbican - tests/ci/playbooks - - rally-task-cinder: - voting: false + - rally-task-cinder - rally-task-designate: files: - .zuul.d/zuul.yaml @@ -101,6 +100,7 @@ - rally_openstack/task/cleanup/resources.py - rally_openstack/task/scenarios/barbican - tests/ci/playbooks + - rally-task-cinder #- rally-task-heat - rally-task-ironic - rally-task-keystone-glance-swift diff --git a/rally_openstack/common/services/storage/block.py b/rally_openstack/common/services/storage/block.py index 9e6acfb2..ddee73fe 100755 --- a/rally_openstack/common/services/storage/block.py +++ b/rally_openstack/common/services/storage/block.py @@ -377,10 +377,10 @@ class BlockStorage(service.UnifiedService): :param volume_type: Volume type name or ID to add access for the given project - :project: Project ID to add volume type access for + :param project: Project ID to add volume type access for :return: An instance of cinderclient.apiclient.base.TupleWithMeta """ - return self._impl.update_volume_type( + return self._impl.add_type_access( volume_type=volume_type, project=project ) @@ -391,7 +391,7 @@ class BlockStorage(service.UnifiedService): :param volume_type: Filter results by volume type name or ID :return: VolumeTypeAccess of specific project """ - return self._impl.volume_type_access.list(volume_type) + return self._impl.list_type_access(volume_type) @service.should_be_overridden def get_volume_type(self, volume_type): diff --git a/rally_openstack/common/services/storage/cinder_v2.py b/rally_openstack/common/services/storage/cinder_v2.py index 8d14272e..32a0027d 100755 --- a/rally_openstack/common/services/storage/cinder_v2.py +++ b/rally_openstack/common/services/storage/cinder_v2.py @@ -182,12 +182,11 @@ class CinderV2Service(service.Service, cinder_common.CinderMixin): :param volume_type: The ID or an instance of the :class:`VolumeType` to update. - :param name: if None, updates name by generating random name. + :param name: if None, name cannot be updated. else updates name with provided name :param description: Description of the volume type. :rtype: :class:`VolumeType` """ - name = name or self.generate_random_name() return self._get_client().volume_types.update(volume_type, name, description, is_public) diff --git a/rally_openstack/common/services/storage/cinder_v3.py b/rally_openstack/common/services/storage/cinder_v3.py index 8f120740..1ddb181b 100755 --- a/rally_openstack/common/services/storage/cinder_v3.py +++ b/rally_openstack/common/services/storage/cinder_v3.py @@ -178,20 +178,19 @@ class CinderV3Service(service.Service, cinder_common.CinderMixin): return self._get_client().volume_types.create(**kwargs) @atomic.action_timer("cinder_v3.update_volume_type") - def update_volume_type(self, volume_type, update_name=False, + def update_volume_type(self, volume_type, name=None, description=None, is_public=None): """Update the name and/or description for a volume type. :param volume_type: The ID or a instance of the :class:`VolumeType` to update. - :param update_name: if True, can update name by generating random name. - if False, don't update name. + :param name: if None, name cannot be updated. + else updates name with provided name :param description: Description of the volume type. + :param is_public: :rtype: :class:`VolumeType` """ - name = None - if update_name: - name = self.generate_random_name() + return self._get_client().volume_types.update( volume_type=volume_type, name=name, description=description, is_public=is_public) @@ -202,7 +201,7 @@ class CinderV3Service(service.Service, cinder_common.CinderMixin): :param volume_type: Volume type name or ID to add access for the given project - :project: Project ID to add volume type access for + :param project: Project ID to add volume type access for :return: An instance of cinderclient.apiclient.base.TupleWithMeta """ return self._get_client().volume_type_access.add_project_access( diff --git a/rally_openstack/task/scenarios/cinder/volume_types.py b/rally_openstack/task/scenarios/cinder/volume_types.py index 02d1fc39..a4b292fd 100644 --- a/rally_openstack/task/scenarios/cinder/volume_types.py +++ b/rally_openstack/task/scenarios/cinder/volume_types.py @@ -81,18 +81,26 @@ class CreateAndUpdateVolumeType(cinder_utils.CinderBasic): :param is_public: Volume type visibility :param update_name: if True, can update name by generating random name. if False, don't update name. - :param update_description: update Description of the volume type + :param update_description: a description to set while update :param update_is_public: update Volume type visibility """ volume_type = self.admin_cinder.create_volume_type( description=description, is_public=is_public) + updated_name = self.generate_random_name() if update_name else None + if not update_name and not update_description and not update_is_public: + LOG.warning("Something should be updated.") + # transmit at least some value to update api call + updated_name = volume_type.name + + updated_is_public = not is_public if update_is_public else None + self.admin_cinder.update_volume_type( volume_type, - name=volume_type.name if not update_name else False, + name=updated_name, description=update_description, - is_public=update_is_public) + is_public=updated_is_public) @validation.add("required_services", services=[consts.Service.CINDER]) diff --git a/tests/unit/common/services/storage/test_cinder_v2.py b/tests/unit/common/services/storage/test_cinder_v2.py index e584af8d..0618b17a 100755 --- a/tests/unit/common/services/storage/test_cinder_v2.py +++ b/tests/unit/common/services/storage/test_cinder_v2.py @@ -235,10 +235,12 @@ class CinderV2ServiceTestCase(test.ScenarioTestCase): return_value=name) description = "test update" - result = self.service.update_volume_type(volume_type, - description=description, - name=None, - is_public=None) + result = self.service.update_volume_type( + volume_type, + description=description, + name=self.service.generate_random_name(), + is_public=None + ) self.assertEqual( self.cinder.volume_types.update.return_value, result) diff --git a/tests/unit/common/services/storage/test_cinder_v3.py b/tests/unit/common/services/storage/test_cinder_v3.py index 3861810f..eb4c5431 100755 --- a/tests/unit/common/services/storage/test_cinder_v3.py +++ b/tests/unit/common/services/storage/test_cinder_v3.py @@ -240,10 +240,12 @@ class CinderV3ServiceTestCase(test.ScenarioTestCase): return_value=name) description = "test update" - result = self.service.update_volume_type(volume_type, - description=description, - update_name=True, - is_public=None) + result = self.service.update_volume_type( + volume_type, + description=description, + name=self.service.generate_random_name(), + is_public=None + ) self.assertEqual( self.cinder.volume_types.update.return_value, result) diff --git a/tests/unit/task/scenarios/cinder/test_volume_types.py b/tests/unit/task/scenarios/cinder/test_volume_types.py index 9cbc07b1..9cdb3188 100644 --- a/tests/unit/task/scenarios/cinder/test_volume_types.py +++ b/tests/unit/task/scenarios/cinder/test_volume_types.py @@ -169,9 +169,12 @@ class CinderVolumeTypesTestCase(test.ScenarioTestCase): description=create_description, is_public=True) mock_service.update_volume_type.assert_called_once_with( - fake_type, name="any", + fake_type, description=update_description, - is_public=None) + # update_is_public and update_name are not specified, so should + # not be used + is_public=None, name=None + ) def test_create_volume_type_and_encryption_type(self): mock_service = self.mock_cinder.return_value