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 <juha.kosonen@nokia.com>
This commit is contained in:
Juha Kosonen 2018-03-15 13:34:40 +02:00
parent 745afdd67a
commit cea28fb0b3
12 changed files with 328 additions and 4 deletions

View File

@ -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

View File

@ -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)

View File

@ -0,0 +1,63 @@
# Copyright 2017 Red Hat, Inc. <http://www.redhat.com>
#
# 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)

View File

@ -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):

View File

@ -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
}
}
}
]
}

View File

@ -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

View File

@ -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
}
}
}
]
}

View File

@ -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

View File

@ -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
}
}
}
]
}

View File

@ -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

View File

@ -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):

View File

@ -0,0 +1,71 @@
# Copyright 2017 Red Hat, Inc. <http://www.redhat.com>
#
# 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")