telemetry: add support for Gnocchi capabilities

Change-Id: Id16bd2fbe1b6d71f0a6a746b6e40429daaf4c15d
This commit is contained in:
Julien Danjou 2015-02-10 12:22:24 +01:00
parent 53b4459792
commit 284894bd35
8 changed files with 144 additions and 0 deletions

View File

View File

@ -0,0 +1,24 @@
# 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 openstack.auth import service_filter
class MetricService(service_filter.ServiceFilter):
"""The metric service."""
valid_versions = [service_filter.ValidVersion('v1')]
def __init__(self, version=None):
"""Create a metric service."""
super(MetricService, self).__init__(service_type='metric',
version=version)

View File

View File

@ -0,0 +1,38 @@
# 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 six
from openstack.metric import metric_service
from openstack import resource
class Capability(resource.Resource):
base_path = '/capabilities'
service = metric_service.MetricService()
# Supported Operations
allow_list = True
# Properties
value = resource.prop('value')
@classmethod
def page(cls, session, limit, marker=None, path_args=None, **params):
if marker:
return []
resp = super(Capability, cls).page(session, limit,
marker, path_args, **params)
return [{"id": key, "value": value}
for key, value in six.iteritems(resp)]

View File

View File

@ -0,0 +1,28 @@
# 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 testtools
from openstack.metric import metric_service
class TestMetricService(testtools.TestCase):
def test_service(self):
sot = metric_service.MetricService()
self.assertEqual('metric', sot.service_type)
self.assertEqual('public', sot.visibility)
self.assertIsNone(sot.region)
self.assertIsNone(sot.service_name)
self.assertEqual(1, len(sot.valid_versions))
self.assertEqual('v1', sot.valid_versions[0].module)
self.assertEqual('v1', sot.valid_versions[0].path)

View File

View File

@ -0,0 +1,54 @@
# 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
import testtools
from openstack.metric.v1 import capability
EXAMPLE = {
"id": "123",
"value": False,
}
BODY = {
"aggregation_methods": ['mean', 'max', 'avg'],
}
class TestCapability(testtools.TestCase):
def test_basic(self):
sot = capability.Capability()
self.assertEqual('/capabilities', sot.base_path)
self.assertEqual('metric', sot.service.service_type)
self.assertFalse(sot.allow_create)
self.assertFalse(sot.allow_retrieve)
self.assertFalse(sot.allow_update)
self.assertFalse(sot.allow_delete)
self.assertTrue(sot.allow_list)
def test_make_it(self):
sot = capability.Capability(EXAMPLE)
self.assertEqual(EXAMPLE['id'], sot.id)
self.assertEqual(EXAMPLE['value'], sot.value)
def test_list(self):
sess = mock.Mock()
resp = mock.Mock()
resp.body = BODY
sess.get = mock.Mock(return_value=resp)
caps = capability.Capability.list(sess)
caps = sorted(caps, key=lambda cap: cap.id)
self.assertEqual(1, len(caps))
self.assertEqual('aggregation_methods', caps[0].id)
self.assertEqual(['mean', 'max', 'avg'], caps[0].value)