Merge "Add new transformer for Magnum pollster"

This commit is contained in:
Zuul 2019-02-19 06:23:35 +00:00 committed by Gerrit Code Review
commit 3efc5c26c3
3 changed files with 69 additions and 0 deletions

View File

@ -399,3 +399,38 @@ class TestNetworkServiceTransformer(base.DistilTestCase):
FAKE_DATA.t1)
self.assertEqual({'fake_meter': 0}, usage)
@mock.patch.object(general, 'get_transformer_config',
mock.Mock(return_value=FAKE_CONFIG))
class TestMagnumTransformer(base.DistilTestCase):
def test_basic_sum(self):
"""Tests that the transformer correctly calculate the sum value.
"""
data = [
{'timestamp': '2014-01-01T00:00:00', 'volume': 1},
{'timestamp': '2014-01-01T00:10:00', 'volume': 0},
{'timestamp': '2014-01-01T01:00:00', 'volume': 2},
]
xform = conversion.MagnumTransformer()
usage = xform.transform_usage('fake_meter', data, FAKE_DATA.t0,
FAKE_DATA.t1)
self.assertEqual({'fake_meter': 1}, usage)
def test_only_non_charged(self):
"""Tests that the transformer correctly calculate the sum value.
"""
data = [
{'timestamp': '2014-01-01T00:00:00', 'volume': 1},
{'timestamp': '2014-01-01T00:10:00', 'volume': 1},
{'timestamp': '2014-01-01T01:00:00', 'volume': 18},
]
xform = conversion.MagnumTransformer()
usage = xform.transform_usage('fake_meter', data, FAKE_DATA.t0,
FAKE_DATA.t1)
self.assertEqual({'fake_meter': 0}, usage)

View File

@ -161,3 +161,25 @@ class NetworkServiceTransformer(BaseTransformer):
max_vol = max(volumes) if len(volumes) else 0
hours = (end - start).total_seconds() / 3600.0
return {name: max_vol * hours}
class MagnumTransformer(BaseTransformer):
"""Transformer for Magnum clusters.
"""
def _transform_usage(self, name, data, start, end):
# NOTE(flwang): The magnum pollster of Ceilometer is using
# status as the volume(see ceilometer/cim/magnum.py), so we have
# to check the volume to make sure only the active clusters are
# charged.
charged_cluster_status = [2, 3, 4, 5, 9, 10, 11,
12, 13, 14, 15, 16, 17]
volumes = [v["volume"] for v in data if
v["volume"] in charged_cluster_status]
# If there is any valid status in this hour, then we think it's a valid
# sample.
max_vol = 1 if len(volumes) else 0
hours = (end - start).total_seconds() / 3600.0
return {name: max_vol * hours}

View File

@ -241,3 +241,15 @@
name:
sources:
- name
-
meter: cim.coe.cluster
service: p1.coe
type: COE Cluster
transformer: MagnumTransformer
unit: hour
metadata:
name:
sources:
- name