diff --git a/rally-jobs/cinder.yaml b/rally-jobs/cinder.yaml index 231949e4fa..9543ad0f66 100755 --- a/rally-jobs/cinder.yaml +++ b/rally-jobs/cinder.yaml @@ -1209,3 +1209,19 @@ sla: failure_rate: max: 0 + + CinderVolumeTypes.create_volume_type_add_and_list_type_access: + - + args: + description: "rally tests creating types" + runner: + type: "constant" + times: 4 + concurrency: 2 + context: + users: + tenants: 2 + users_per_tenant: 2 + sla: + failure_rate: + max: 0 diff --git a/rally/plugins/openstack/scenarios/cinder/volume_types.py b/rally/plugins/openstack/scenarios/cinder/volume_types.py index d4aff817fe..91d466ebd7 100644 --- a/rally/plugins/openstack/scenarios/cinder/volume_types.py +++ b/rally/plugins/openstack/scenarios/cinder/volume_types.py @@ -366,3 +366,30 @@ class CreateAndUpdateEncryptionType(cinder_utils.CinderBasic): specs=create_specs) self.admin_cinder.update_encryption_type(volume_type["id"], specs=update_specs) + + +@validation.add("required_platform", platform="openstack", admin=True) +@validation.add("required_api_versions", component="cinder", versions=["2"]) +@validation.add("required_services", services=consts.Service.CINDER) +@scenario.configure(context={"admin_cleanup": ["cinder"]}, + name="CinderVolumeTypes.create_volume_type_" + "add_and_list_type_access") +class CreateVolumeTypeAddAndListTypeAccess(scenario.OpenStackScenario): + + def run(self, description=None, is_public=False): + """Add and list volume type access for the given project. + + This scenario first creates a private volume type, then add project + access and list project access to it. + + :param description: Description of the volume type + :param is_public: Volume type visibility + """ + service = cinder_v2.CinderV2Service(self._admin_clients, + self.generate_random_name, + atomic_inst=self.atomic_actions()) + volume_type = service.create_volume_type(description=description, + is_public=is_public) + service.add_type_access(volume_type, + project=self.context["tenant"]["id"]) + service.list_type_access(volume_type) diff --git a/rally/plugins/openstack/services/storage/cinder_v2.py b/rally/plugins/openstack/services/storage/cinder_v2.py index c7af348e83..1dcaf50220 100644 --- a/rally/plugins/openstack/services/storage/cinder_v2.py +++ b/rally/plugins/openstack/services/storage/cinder_v2.py @@ -194,6 +194,27 @@ class CinderV2Service(service.Service, cinder_common.CinderMixin): return self._get_client().volume_types.update(volume_type, name, description, is_public) + @atomic.action_timer("cinder_v2.add_type_access") + def add_type_access(self, volume_type, project): + """Add a project to the given volume type access list. + + :param volume_type: Volume type name or ID to add access for the given + project + :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( + volume_type, project) + + @atomic.action_timer("cinder_v2.list_type_access") + def list_type_access(self, volume_type): + """Print access information about the given volume type + + :param volume_type: Filter results by volume type name or ID + :return: VolumeTypeAcces of specific project + """ + return self._get_client().volume_type_access.list(volume_type) + @service.compat_layer(CinderV2Service) class UnifiedCinderV2Service(cinder_common.UnifiedCinderMixin, diff --git a/samples/tasks/scenarios/cinder/create-volume-type-add-and-list-type-access.json b/samples/tasks/scenarios/cinder/create-volume-type-add-and-list-type-access.json new file mode 100644 index 0000000000..a11de209c8 --- /dev/null +++ b/samples/tasks/scenarios/cinder/create-volume-type-add-and-list-type-access.json @@ -0,0 +1,25 @@ +{ + "CinderVolumeTypes.create_volume_type_add_and_list_type_access": [ + { + "args": { + "description": "rally tests creating types" + }, + "runner": { + "type": "constant", + "times": 4, + "concurrency": 2 + }, + "context": { + "users": { + "tenants": 2, + "users_per_tenant": 2 + } + }, + "sla": { + "failure_rate": { + "max": 0 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/cinder/create-volume-type-add-and-list-type-access.yaml b/samples/tasks/scenarios/cinder/create-volume-type-add-and-list-type-access.yaml new file mode 100644 index 0000000000..8afb735b7b --- /dev/null +++ b/samples/tasks/scenarios/cinder/create-volume-type-add-and-list-type-access.yaml @@ -0,0 +1,16 @@ +--- + CinderVolumeTypes.create_volume_type_add_and_list_type_access: + - + args: + description: "rally tests creating types" + runner: + type: "constant" + times: 4 + concurrency: 2 + context: + users: + tenants: 2 + users_per_tenant: 2 + sla: + failure_rate: + max: 0 diff --git a/tests/unit/plugins/openstack/scenarios/cinder/test_volume_types.py b/tests/unit/plugins/openstack/scenarios/cinder/test_volume_types.py index f2de0aeb6f..bd82aca9fa 100644 --- a/tests/unit/plugins/openstack/scenarios/cinder/test_volume_types.py +++ b/tests/unit/plugins/openstack/scenarios/cinder/test_volume_types.py @@ -290,3 +290,20 @@ class CinderVolumeTypesTestCase(test.ScenarioTestCase): "fake_id", specs=create_specs) mock_service.update_encryption_type.assert_called_once_with( "fake_id", specs=update_specs) + + @mock.patch("%s.list_type_access" % CINDER_V2_PATH) + @mock.patch("%s.add_type_access" % CINDER_V2_PATH) + @mock.patch("%s.create_volume_type" % CINDER_V2_PATH) + def test_create_volume_type_add_and_list_type_access( + self, mock_create_volume_type, mock_add_type_access, + mock_list_type_access): + scenario = volume_types.CreateVolumeTypeAddAndListTypeAccess( + self._get_context()) + fake_type = mock.Mock() + mock_create_volume_type.return_value = fake_type + + scenario.run(description=None, is_public=False) + mock_create_volume_type.assert_called_once_with( + description=None, is_public=False) + mock_add_type_access.assert_called_once_with(fake_type, project="fake") + mock_list_type_access.assert_called_once_with(fake_type) diff --git a/tests/unit/plugins/openstack/services/storage/test_cinder_v2.py b/tests/unit/plugins/openstack/services/storage/test_cinder_v2.py index 5acf2567a6..079eddd5d6 100644 --- a/tests/unit/plugins/openstack/services/storage/test_cinder_v2.py +++ b/tests/unit/plugins/openstack/services/storage/test_cinder_v2.py @@ -239,6 +239,29 @@ class CinderV2ServiceTestCase(test.ScenarioTestCase): self._test_atomic_action_timer(self.atomic_actions(), "cinder_v2.update_volume_type") + def test_add_type_access(self): + volume_type = mock.Mock() + project = mock.Mock() + type_access = self.service.add_type_access(volume_type, + project=project) + add_project_access = self.cinder.volume_type_access.add_project_access + add_project_access.assert_called_once_with( + volume_type, project) + self.assertEqual(add_project_access.return_value, + type_access) + self._test_atomic_action_timer(self.atomic_actions(), + "cinder_v2.add_type_access") + + def test_list_type_access(self): + volume_type = mock.Mock() + type_access = self.service.list_type_access(volume_type) + self.cinder.volume_type_access.list.assert_called_once_with( + volume_type) + self.assertEqual(self.cinder.volume_type_access.list.return_value, + type_access) + self._test_atomic_action_timer(self.atomic_actions(), + "cinder_v2.list_type_access") + class UnifiedCinderV2ServiceTestCase(test.TestCase): def setUp(self):