drop kwapi pollster

we deprecated this in newton and it's been dead for far longer.

Change-Id: I790e36c7daefb07eefe68298f91c14211f9a8df0
This commit is contained in:
gord chung 2017-02-10 16:20:49 -05:00 committed by gordon chung
parent 09aa7ef3c9
commit 47ae182b4d
7 changed files with 5 additions and 265 deletions

View File

@ -1,123 +0,0 @@
# -*- coding: utf-8 -*-
#
# 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 keystoneauth1 import exceptions
from oslo_config import cfg
from oslo_log import log
import requests
import six
from ceilometer.agent import plugin_base
from ceilometer import keystone_client
from ceilometer import sample
LOG = log.getLogger(__name__)
SERVICE_OPTS = [
cfg.StrOpt('kwapi',
default='energy',
help='Kwapi service type.'),
]
class KwapiClient(object):
"""Kwapi API client."""
def __init__(self, conf, url, token=None):
"""Initializes client."""
self.conf = conf
self.url = url
self.token = token
def iter_probes(self):
"""Returns a list of dicts describing all probes."""
probes_url = self.url + '/probes/'
headers = {}
if self.token is not None:
headers = {'X-Auth-Token': self.token}
timeout = self.conf.http_timeout
request = requests.get(probes_url, headers=headers, timeout=timeout)
message = request.json()
probes = message['probes']
for key, value in six.iteritems(probes):
probe_dict = value
probe_dict['id'] = key
yield probe_dict
class _Base(plugin_base.PollsterBase):
"""Base class for the Kwapi pollster, derived from PollsterBase."""
@property
def default_discovery(self):
return 'endpoint:%s' % self.conf.service_types.kwapi
def get_kwapi_client(self, ksclient, endpoint):
"""Returns a KwapiClient configured with the proper url and token."""
return KwapiClient(self.conf, endpoint,
keystone_client.get_auth_token(ksclient))
CACHE_KEY_PROBE = 'kwapi.probes'
def _iter_probes(self, ksclient, cache, endpoint):
"""Iterate over all probes."""
key = '%s-%s' % (endpoint, self.CACHE_KEY_PROBE)
if key not in cache:
cache[key] = self._get_probes(ksclient, endpoint)
return iter(cache[key])
def _get_probes(self, ksclient, endpoint):
try:
client = self.get_kwapi_client(ksclient, endpoint)
except exceptions.EndpointNotFound:
LOG.debug("Kwapi endpoint not found")
return []
return list(client.iter_probes())
class EnergyPollster(_Base):
"""Measures energy consumption."""
def get_samples(self, manager, cache, resources):
"""Returns all samples."""
for endpoint in resources:
for probe in self._iter_probes(manager.keystone, cache, endpoint):
yield sample.Sample(
name='energy',
type=sample.TYPE_CUMULATIVE,
unit='kWh',
volume=probe['kwh'],
user_id=None,
project_id=None,
resource_id=probe['id'],
resource_metadata={}
)
class PowerPollster(_Base):
"""Measures power consumption."""
def get_samples(self, manager, cache, resources):
"""Returns all samples."""
for endpoint in resources:
for probe in self._iter_probes(manager.keystone, cache, endpoint):
yield sample.Sample(
name='power',
type=sample.TYPE_GAUGE,
unit='W',
volume=probe['w'],
user_id=None,
project_id=None,
resource_id=probe['id'],
resource_metadata={}
)

View File

@ -31,7 +31,6 @@ import ceilometer.dispatcher
import ceilometer.dispatcher.file
import ceilometer.dispatcher.gnocchi_opts
import ceilometer.dispatcher.http
import ceilometer.energy.kwapi
import ceilometer.event.converter
import ceilometer.exchange_control
import ceilometer.hardware.discovery
@ -114,8 +113,7 @@ def list_opts():
('publisher_notifier', ceilometer.publisher.messaging.NOTIFIER_OPTS),
('rgw_admin_credentials', ceilometer.objectstore.rgw.CREDENTIAL_OPTS),
('service_types',
itertools.chain(ceilometer.energy.kwapi.SERVICE_OPTS,
ceilometer.image.discovery.SERVICE_OPTS,
itertools.chain(ceilometer.image.discovery.SERVICE_OPTS,
ceilometer.neutron_client.SERVICE_OPTS,
ceilometer.nova_client.SERVICE_OPTS,
ceilometer.objectstore.rgw.SERVICE_OPTS,

View File

@ -1,137 +0,0 @@
# -*- coding: utf-8 -*-
#
# 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 keystoneauth1 import exceptions
import mock
from oslo_config import fixture as fixture_config
from oslotest import base
from oslotest import mockpatch
import six
from ceilometer.agent import manager
from ceilometer.energy import kwapi
PROBE_DICT = {
"probes": {
"A": {
"timestamp": 1357730232.68754,
"w": 107.3,
"kwh": 0.001058255421506034
},
"B": {
"timestamp": 1357730232.048158,
"w": 15.0,
"kwh": 0.029019045026169896
},
"C": {
"timestamp": 1357730232.223375,
"w": 95.0,
"kwh": 0.17361822634312918
}
}
}
ENDPOINT = 'end://point'
class TestManager(manager.AgentManager):
def __init__(self, worker_id, conf):
super(TestManager, self).__init__(worker_id, conf)
self._keystone = mock.Mock()
class _BaseTestCase(base.BaseTestCase):
@mock.patch('ceilometer.pipeline.setup_pipeline', mock.MagicMock())
def setUp(self):
super(_BaseTestCase, self).setUp()
self.CONF = self.useFixture(fixture_config.Config()).conf
self.manager = TestManager(0, self.CONF)
class TestKwapi(_BaseTestCase):
@staticmethod
def fake_get_kwapi_client(ksclient, endpoint):
raise exceptions.EndpointNotFound("fake keystone exception")
def test_endpoint_not_exist(self):
with mockpatch.PatchObject(kwapi._Base, 'get_kwapi_client',
side_effect=self.fake_get_kwapi_client):
pollster = kwapi.EnergyPollster(self.CONF)
samples = list(pollster.get_samples(self.manager, {},
[ENDPOINT]))
self.assertEqual(0, len(samples))
class TestEnergyPollster(_BaseTestCase):
pollster_cls = kwapi.EnergyPollster
unit = 'kwh'
def setUp(self):
super(TestEnergyPollster, self).setUp()
self.useFixture(mockpatch.PatchObject(
kwapi._Base, '_iter_probes', side_effect=self.fake_iter_probes))
@staticmethod
def fake_iter_probes(ksclient, cache, endpoint):
probes = PROBE_DICT['probes']
for key, value in six.iteritems(probes):
probe_dict = value
probe_dict['id'] = key
yield probe_dict
def test_default_discovery(self):
pollster = kwapi.EnergyPollster(self.CONF)
self.assertEqual('endpoint:energy', pollster.default_discovery)
def test_sample(self):
cache = {}
samples = list(self.pollster_cls(self.CONF).get_samples(
self.manager, cache, [ENDPOINT]))
self.assertEqual(len(PROBE_DICT['probes']), len(samples))
samples_by_name = dict((s.resource_id, s) for s in samples)
for name, probe in PROBE_DICT['probes'].items():
sample = samples_by_name[name]
self.assertEqual(probe[self.unit], sample.volume)
class TestPowerPollster(TestEnergyPollster):
pollster_cls = kwapi.PowerPollster
unit = 'w'
class TestEnergyPollsterCache(_BaseTestCase):
pollster_cls = kwapi.EnergyPollster
def test_get_samples_cached(self):
probe = {'id': 'A'}
probe.update(PROBE_DICT['probes']['A'])
cache = {
'%s-%s' % (ENDPOINT, self.pollster_cls.CACHE_KEY_PROBE): [probe],
}
self.manager._keystone = mock.Mock()
pollster = self.pollster_cls(self.CONF)
with mock.patch.object(pollster, '_get_probes') as do_not_call:
do_not_call.side_effect = AssertionError('should not be called')
samples = list(pollster.get_samples(self.manager, cache,
[ENDPOINT]))
self.assertEqual(1, len(samples))
class TestPowerPollsterCache(TestEnergyPollsterCache):
pollster_cls = kwapi.PowerPollster

View File

@ -0,0 +1,4 @@
---
deprecations:
- |
Previously deprecated kwapi meters are not removed.

View File

@ -154,8 +154,6 @@ ceilometer.poll.central =
storage.objects = ceilometer.objectstore.swift:ObjectsPollster
storage.objects.size = ceilometer.objectstore.swift:ObjectsSizePollster
storage.objects.containers = ceilometer.objectstore.swift:ObjectsContainersPollster
energy = ceilometer.energy.kwapi:EnergyPollster
power = ceilometer.energy.kwapi:PowerPollster
switch.port = ceilometer.network.statistics.port:PortPollster
switch.port.receive.packets = ceilometer.network.statistics.port:PortPollsterReceivePackets
switch.port.transmit.packets = ceilometer.network.statistics.port:PortPollsterTransmitPackets