From cea28fb0b3e8d131c8ff8d5f575ae220eccc90a3 Mon Sep 17 00:00:00 2001 From: Juha Kosonen Date: Thu, 15 Mar 2018 13:34:40 +0200 Subject: [PATCH] Add Gnocchi resource type scenarios This patch is based on [1] and adds following scenarios: GnocchiResourceType.list_resource_type GnocchiResourceType.create_resource_type GnocchiResourceType.create_delete_resource_type [1] https://review.openstack.org/#/c/453861/ Change-Id: I54d9706ecf466ff28e2c18862c61a0f64b95cae5 Signed-off-by: Juha Kosonen --- rally-jobs/telemetry.yaml | 50 +++++++++++++ rally_openstack/cleanup/resources.py | 6 ++ .../scenarios/gnocchi/resource_type.py | 63 ++++++++++++++++ rally_openstack/services/gnocchi/metric.py | 11 +-- .../gnocchi/create-delete-resource-type.json | 28 ++++++++ .../gnocchi/create-delete-resource-type.yaml | 18 +++++ .../gnocchi/create-resource-type.json | 28 ++++++++ .../gnocchi/create-resource-type.yaml | 18 +++++ .../scenarios/gnocchi/list-resource-type.json | 22 ++++++ .../scenarios/gnocchi/list-resource-type.yaml | 14 ++++ tests/ci/osresources.py | 3 + .../scenarios/gnocchi/test_resource_type.py | 71 +++++++++++++++++++ 12 files changed, 328 insertions(+), 4 deletions(-) create mode 100644 rally_openstack/scenarios/gnocchi/resource_type.py create mode 100644 samples/tasks/scenarios/gnocchi/create-delete-resource-type.json create mode 100644 samples/tasks/scenarios/gnocchi/create-delete-resource-type.yaml create mode 100644 samples/tasks/scenarios/gnocchi/create-resource-type.json create mode 100644 samples/tasks/scenarios/gnocchi/create-resource-type.yaml create mode 100644 samples/tasks/scenarios/gnocchi/list-resource-type.json create mode 100644 samples/tasks/scenarios/gnocchi/list-resource-type.yaml create mode 100644 tests/unit/scenarios/gnocchi/test_resource_type.py diff --git a/rally-jobs/telemetry.yaml b/rally-jobs/telemetry.yaml index 1332b93a..bdccaab1 100644 --- a/rally-jobs/telemetry.yaml +++ b/rally-jobs/telemetry.yaml @@ -106,3 +106,53 @@ sla: failure_rate: max: 0 + + GnocchiResourceType.list_resource_type: + - + runner: + type: "constant" + times: 10 + concurrency: 2 + context: + users: + tenants: 2 + users_per_tenant: 3 + sla: + failure_rate: + max: 0 + + GnocchiResourceType.create_resource_type: + - + args: + attributes: + foo: + required: false + type: "string" + bar: + required: true + type: "number" + runner: + type: "constant" + times: 10 + concurrency: 2 + sla: + failure_rate: + max: 0 + + GnocchiResourceType.create_delete_resource_type: + - + args: + attributes: + foo: + required: false + type: "string" + bar: + required: true + type: "number" + runner: + type: "constant" + times: 10 + concurrency: 2 + sla: + failure_rate: + max: 0 diff --git a/rally_openstack/cleanup/resources.py b/rally_openstack/cleanup/resources.py index 391198ea..d5f89aa2 100644 --- a/rally_openstack/cleanup/resources.py +++ b/rally_openstack/cleanup/resources.py @@ -870,6 +870,12 @@ class GnocchiArchivePolicy(GnocchiMixin): pass +@base.resource("gnocchi", "resource_type", order=next(_gnocchi_order), + admin_required=True, perform_for_admin_only=True) +class GnocchiResourceType(GnocchiMixin): + pass + + # WATCHER _watcher_order = get_order(1500) diff --git a/rally_openstack/scenarios/gnocchi/resource_type.py b/rally_openstack/scenarios/gnocchi/resource_type.py new file mode 100644 index 00000000..e0c240ad --- /dev/null +++ b/rally_openstack/scenarios/gnocchi/resource_type.py @@ -0,0 +1,63 @@ +# Copyright 2017 Red Hat, Inc. +# +# 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 rally import consts +from rally.task import validation + +from rally_openstack import scenario +from rally_openstack.scenarios.gnocchi import utils as gnocchiutils + +"""Scenarios for Gnocchi resource type.""" + + +@validation.add("required_services", services=[consts.Service.GNOCCHI]) +@validation.add("required_platform", platform="openstack", users=True) +@scenario.configure(name="GnocchiResourceType.list_resource_type") +class ListResourceType(gnocchiutils.GnocchiBase): + + def run(self): + """List resource types.""" + self.gnocchi.list_resource_type() + + +@validation.add("required_services", services=[consts.Service.GNOCCHI]) +@validation.add("required_platform", platform="openstack", admin=True) +@scenario.configure( + context={"admin_cleanup@openstack": ["gnocchi.resource_type"]}, + name="GnocchiResourceType.create_resource_type") +class CreateResourceType(gnocchiutils.GnocchiBase): + + def run(self, attributes=None): + """Create resource type. + + :param attributes: List of attributes + """ + name = self.generate_random_name() + self.admin_gnocchi.create_resource_type(name, attributes=attributes) + + +@validation.add("required_services", services=[consts.Service.GNOCCHI]) +@validation.add("required_platform", platform="openstack", admin=True) +@scenario.configure( + context={"admin_cleanup@openstack": ["gnocchi.resource_type"]}, + name="GnocchiResourceType.create_delete_resource_type") +class CreateDeleteResourceType(gnocchiutils.GnocchiBase): + def run(self, attributes=None): + """Create resource type and then delete it. + + :param attributes: List of attributes + """ + name = self.generate_random_name() + self.admin_gnocchi.create_resource_type(name, attributes=attributes) + self.admin_gnocchi.delete_resource_type(name) diff --git a/rally_openstack/services/gnocchi/metric.py b/rally_openstack/services/gnocchi/metric.py index 46baf411..6eace64f 100644 --- a/rally_openstack/services/gnocchi/metric.py +++ b/rally_openstack/services/gnocchi/metric.py @@ -157,22 +157,25 @@ class GnocchiService(service.Service): resource_type=resource_type) @atomic.action_timer("gnocchi.create_resource_type") - def create_resource_type(self, name): + def create_resource_type(self, name, attributes=None): """Create a resource type. :param name: Name of the resource type """ resource_type = {"name": name or self.generate_random_name()} + if attributes is not None: + resource_type["attributes"] = attributes + return self._clients.gnocchi().resource_type.create( resource_type) @atomic.action_timer("gnocchi.delete_resource_type") - def delete_resource_type(self, resource_type): + def delete_resource_type(self, name): """Delete a resource type. - :param resource_type: Resource type dict + :param name: Name of the resource type """ - return self._clients.gnocchi().resource_type.delete(resource_type) + return self._clients.gnocchi().resource_type.delete(name) @atomic.action_timer("gnocchi.list_resource_type") def list_resource_type(self): diff --git a/samples/tasks/scenarios/gnocchi/create-delete-resource-type.json b/samples/tasks/scenarios/gnocchi/create-delete-resource-type.json new file mode 100644 index 00000000..39cb488f --- /dev/null +++ b/samples/tasks/scenarios/gnocchi/create-delete-resource-type.json @@ -0,0 +1,28 @@ +{ + "GnocchiResourceType.create_delete_resource_type": [ + { + "args": { + "attributes": { + "foo": { + "required": false, + "type": "string" + }, + "bar": { + "required": true, + "type": "number" + } + } + }, + "runner": { + "type": "constant", + "times": 10, + "concurrency": 2 + }, + "sla": { + "failure_rate": { + "max": 0 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/gnocchi/create-delete-resource-type.yaml b/samples/tasks/scenarios/gnocchi/create-delete-resource-type.yaml new file mode 100644 index 00000000..16c1bf7b --- /dev/null +++ b/samples/tasks/scenarios/gnocchi/create-delete-resource-type.yaml @@ -0,0 +1,18 @@ +--- + GnocchiResourceType.create_delete_resource_type: + - + args: + attributes: + foo: + required: false + type: "string" + bar: + required: true + type: "number" + runner: + type: "constant" + times: 10 + concurrency: 2 + sla: + failure_rate: + max: 0 diff --git a/samples/tasks/scenarios/gnocchi/create-resource-type.json b/samples/tasks/scenarios/gnocchi/create-resource-type.json new file mode 100644 index 00000000..c34a85a8 --- /dev/null +++ b/samples/tasks/scenarios/gnocchi/create-resource-type.json @@ -0,0 +1,28 @@ +{ + "GnocchiResourceType.create_resource_type": [ + { + "args": { + "attributes": { + "foo": { + "required": false, + "type": "string" + }, + "bar": { + "required": true, + "type": "number" + } + } + }, + "runner": { + "type": "constant", + "times": 10, + "concurrency": 2 + }, + "sla": { + "failure_rate": { + "max": 0 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/gnocchi/create-resource-type.yaml b/samples/tasks/scenarios/gnocchi/create-resource-type.yaml new file mode 100644 index 00000000..7d55a21e --- /dev/null +++ b/samples/tasks/scenarios/gnocchi/create-resource-type.yaml @@ -0,0 +1,18 @@ +--- + GnocchiResourceType.create_resource_type: + - + args: + attributes: + foo: + required: false + type: "string" + bar: + required: true + type: "number" + runner: + type: "constant" + times: 10 + concurrency: 2 + sla: + failure_rate: + max: 0 diff --git a/samples/tasks/scenarios/gnocchi/list-resource-type.json b/samples/tasks/scenarios/gnocchi/list-resource-type.json new file mode 100644 index 00000000..fae088a5 --- /dev/null +++ b/samples/tasks/scenarios/gnocchi/list-resource-type.json @@ -0,0 +1,22 @@ +{ + "GnocchiResourceType.list_resource_type": [ + { + "runner": { + "type": "constant", + "times": 10, + "concurrency": 2 + }, + "context": { + "users": { + "tenants": 2, + "users_per_tenant": 3 + } + }, + "sla": { + "failure_rate": { + "max": 0 + } + } + } + ] +} diff --git a/samples/tasks/scenarios/gnocchi/list-resource-type.yaml b/samples/tasks/scenarios/gnocchi/list-resource-type.yaml new file mode 100644 index 00000000..53422b2a --- /dev/null +++ b/samples/tasks/scenarios/gnocchi/list-resource-type.yaml @@ -0,0 +1,14 @@ +--- + GnocchiResourceType.list_resource_type: + - + runner: + type: "constant" + times: 10 + concurrency: 2 + context: + users: + tenants: 2 + users_per_tenant: 3 + sla: + failure_rate: + max: 0 diff --git a/tests/ci/osresources.py b/tests/ci/osresources.py index 5b13d60b..ee20c8e8 100755 --- a/tests/ci/osresources.py +++ b/tests/ci/osresources.py @@ -323,6 +323,9 @@ class Gnocchi(ResourceManager): def list_archive_policy(self): return self.client.archive_policy.list() + def list_resource_type(self): + return self.client.resource_type.list() + class Ironic(ResourceManager): diff --git a/tests/unit/scenarios/gnocchi/test_resource_type.py b/tests/unit/scenarios/gnocchi/test_resource_type.py new file mode 100644 index 00000000..7daab446 --- /dev/null +++ b/tests/unit/scenarios/gnocchi/test_resource_type.py @@ -0,0 +1,71 @@ +# Copyright 2017 Red Hat, Inc. +# +# 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. + +import mock + +from rally_openstack.scenarios.gnocchi import resource_type +from tests.unit import test + + +class GnocchiResourceTypeTestCase(test.ScenarioTestCase): + + def get_test_context(self): + context = super(GnocchiResourceTypeTestCase, self).get_test_context() + context.update({ + "admin": { + "user_id": "fake", + "credential": mock.MagicMock() + }, + "user": { + "user_id": "fake", + "credential": mock.MagicMock() + }, + "tenant": {"id": "fake"} + }) + return context + + def setUp(self): + super(GnocchiResourceTypeTestCase, self).setUp() + patch = mock.patch( + "rally_openstack.services.gnocchi.metric.GnocchiService") + self.addCleanup(patch.stop) + self.mock_metric = patch.start() + + def test_list_resource_type(self): + metric_service = self.mock_metric.return_value + scenario = resource_type.ListResourceType(self.context) + scenario.run() + metric_service.list_resource_type.assert_called_once_with() + + def test_create_resource_type(self): + metric_service = self.mock_metric.return_value + scenario = resource_type.CreateResourceType(self.context) + scenario.generate_random_name = mock.MagicMock(return_value="name") + attrs = {"foo": {"required": "false", "type": "bool"}} + + scenario.run(attributes=attrs) + metric_service.create_resource_type.assert_called_once_with( + "name", attributes=attrs) + + def test_create_delete_resource_type(self): + metric_service = self.mock_metric.return_value + scenario = resource_type.CreateDeleteResourceType(self.context) + scenario.generate_random_name = mock.MagicMock(return_value="name") + attrs = {"bar": {"required": "true", "type": "number", "max": 7}} + + scenario.run(attributes=attrs) + metric_service.create_resource_type.assert_called_once_with( + "name", attributes=attrs) + metric_service.delete_resource_type.assert_called_once_with( + "name")