Merge "Handles dns.domain.exists event in Ceilometer"
This commit is contained in:
commit
cfe81a584e
0
ceilometer/dns/__init__.py
Normal file
0
ceilometer/dns/__init__.py
Normal file
74
ceilometer/dns/notifications.py
Normal file
74
ceilometer/dns/notifications.py
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
#
|
||||||
|
# Copyright 2015 Hewlett Packard
|
||||||
|
#
|
||||||
|
# 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 oslo_config import cfg
|
||||||
|
import oslo_messaging
|
||||||
|
from oslo_utils import timeutils
|
||||||
|
|
||||||
|
from ceilometer.agent import plugin_base
|
||||||
|
from ceilometer import sample
|
||||||
|
|
||||||
|
OPTS = [
|
||||||
|
cfg.StrOpt('dns_control_exchange',
|
||||||
|
default='central',
|
||||||
|
help="Exchange name for DNS notifications."),
|
||||||
|
|
||||||
|
]
|
||||||
|
|
||||||
|
cfg.CONF.register_opts(OPTS)
|
||||||
|
SERVICE = 'dns'
|
||||||
|
|
||||||
|
|
||||||
|
class DnsMetricsNotificationBase(plugin_base.NotificationBase):
|
||||||
|
"""Base class for DNSaaS(Designate) notifications."""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_targets(conf):
|
||||||
|
"""Return a sequence of oslo.messaging.Target
|
||||||
|
|
||||||
|
This sequence is defining the exchange and topics to be connected for
|
||||||
|
this plugin.
|
||||||
|
"""
|
||||||
|
return [oslo_messaging.Target(topic=topic,
|
||||||
|
exchange=conf.dns_control_exchange)
|
||||||
|
for topic in conf.notification_topics]
|
||||||
|
|
||||||
|
|
||||||
|
class DomainExists(DnsMetricsNotificationBase):
|
||||||
|
"""Handles DNS domain exists notification.
|
||||||
|
|
||||||
|
Emits a sample for a measurable audit interval.
|
||||||
|
"""
|
||||||
|
|
||||||
|
event_types = ['%s.domain.exists' % SERVICE]
|
||||||
|
|
||||||
|
def process_notification(self, message):
|
||||||
|
|
||||||
|
period_start = timeutils.normalize_time(timeutils.parse_isotime(
|
||||||
|
message['payload']['audit_period_beginning']))
|
||||||
|
period_end = timeutils.normalize_time(timeutils.parse_isotime(
|
||||||
|
message['payload']['audit_period_ending']))
|
||||||
|
|
||||||
|
period_difference = timeutils.delta_seconds(period_start, period_end)
|
||||||
|
|
||||||
|
yield sample.Sample.from_notification(
|
||||||
|
name=message['event_type'],
|
||||||
|
type=sample.TYPE_CUMULATIVE,
|
||||||
|
unit='s',
|
||||||
|
volume=period_difference,
|
||||||
|
resource_id=message['payload']['id'],
|
||||||
|
user_id=message['_context_user'],
|
||||||
|
project_id=message['payload']['tenant_id'],
|
||||||
|
message=message)
|
0
ceilometer/tests/dns/__init__.py
Normal file
0
ceilometer/tests/dns/__init__.py
Normal file
102
ceilometer/tests/dns/test_notifications.py
Normal file
102
ceilometer/tests/dns/test_notifications.py
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
#
|
||||||
|
# Copyright (c) 2015 Hewlett Packard 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 oslo_utils import timeutils
|
||||||
|
from oslotest import base
|
||||||
|
|
||||||
|
from ceilometer.dns import notifications
|
||||||
|
from ceilometer import sample
|
||||||
|
|
||||||
|
NOW = timeutils.isotime()
|
||||||
|
|
||||||
|
TENANT_ID = u'76538754af6548f5b53cf9af2d35d582'
|
||||||
|
USER_ID = u'b70ece400e4e45c187168c40fa42ff7a'
|
||||||
|
DOMAIN_STATUS = u'ACTIVE'
|
||||||
|
RESOURCE_ID = u'a8b55824-e731-40a3-a32d-de81474d74b2'
|
||||||
|
PUBLISHER_ID = u'central.ubuntu'
|
||||||
|
POOL_ID = u'794ccc2c-d751-44fe-b57f-8894c9f5c842'
|
||||||
|
|
||||||
|
|
||||||
|
def _dns_notification_for(operation):
|
||||||
|
|
||||||
|
return {
|
||||||
|
u'event_type': '%s.domain.%s' % (notifications.SERVICE,
|
||||||
|
operation),
|
||||||
|
u'_context_roles': [u'admin'],
|
||||||
|
u'timestamp': NOW,
|
||||||
|
u'_context_tenant': TENANT_ID,
|
||||||
|
u'payload': {
|
||||||
|
u'status': DOMAIN_STATUS,
|
||||||
|
u'retry': 600,
|
||||||
|
u'description': None,
|
||||||
|
u'expire': 86400,
|
||||||
|
u'deleted': u'0',
|
||||||
|
u'tenant_id': TENANT_ID,
|
||||||
|
u'created_at': u'2015-07-10T20:05:29.870091Z',
|
||||||
|
u'updated_at': None,
|
||||||
|
u'refresh': 3600,
|
||||||
|
u'pool_id': POOL_ID,
|
||||||
|
u'email': u'admin@hpcloud.com',
|
||||||
|
u'minimum': 3600,
|
||||||
|
u'parent_domain_id': None,
|
||||||
|
u'version': 1,
|
||||||
|
u'ttl': 3600,
|
||||||
|
u'action': operation.upper(),
|
||||||
|
u'serial': 1426295326,
|
||||||
|
u'deleted_at': None,
|
||||||
|
u'id': RESOURCE_ID,
|
||||||
|
u'name': u'paas.hpcloud.com.',
|
||||||
|
u'audit_period_beginning': u'2015-07-10T20:05:29.870091Z',
|
||||||
|
u'audit_period_ending': u'2015-07-10T21:05:29.870091Z'
|
||||||
|
},
|
||||||
|
u'_context_user': USER_ID,
|
||||||
|
u'_context_auth_token': u'b95d4fc3bb2e4a5487cad06af65ffcfc',
|
||||||
|
u'_context_tenant': TENANT_ID,
|
||||||
|
u'priority': u'INFO',
|
||||||
|
u'_context_is_admin': False,
|
||||||
|
u'publisher_id': PUBLISHER_ID,
|
||||||
|
u'message_id': u'67ba0a2a-32bd-4cdf-9bfb-ef9cefcd0f63',
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TestNotification(base.BaseTestCase):
|
||||||
|
def _verify_common_sample(self, actual, operation):
|
||||||
|
self.assertIsNotNone(actual)
|
||||||
|
self.assertEqual('%s.domain.%s' % (notifications.SERVICE, operation),
|
||||||
|
actual.name)
|
||||||
|
self.assertEqual(NOW, actual.timestamp)
|
||||||
|
self.assertEqual(sample.TYPE_CUMULATIVE, actual.type)
|
||||||
|
self.assertEqual(TENANT_ID, actual.project_id)
|
||||||
|
self.assertEqual(RESOURCE_ID, actual.resource_id)
|
||||||
|
self.assertEqual(USER_ID, actual.user_id)
|
||||||
|
metadata = actual.resource_metadata
|
||||||
|
self.assertEqual(PUBLISHER_ID, metadata.get('host'))
|
||||||
|
self.assertEqual(operation.upper(), metadata.get('action'))
|
||||||
|
self.assertEqual(DOMAIN_STATUS, metadata.get('status'))
|
||||||
|
|
||||||
|
self.assertEqual(3600, actual.volume)
|
||||||
|
self.assertEqual('s', actual.unit)
|
||||||
|
|
||||||
|
def _test_operation(self, operation):
|
||||||
|
notif = _dns_notification_for(operation)
|
||||||
|
handler = notifications.DomainExists(mock.Mock())
|
||||||
|
data = list(handler.process_notification(notif))
|
||||||
|
self.assertEqual(1, len(data))
|
||||||
|
self._verify_common_sample(data[0], operation)
|
||||||
|
|
||||||
|
def test_exists(self):
|
||||||
|
self._test_operation('exists')
|
@ -396,6 +396,15 @@
|
|||||||
fields: parent_domain_id
|
fields: parent_domain_id
|
||||||
serial:
|
serial:
|
||||||
fields: payload.serial
|
fields: payload.serial
|
||||||
|
- event_type: dns.domain.exists
|
||||||
|
traits:
|
||||||
|
<<: *dns_domain_traits
|
||||||
|
audit_period_beginning:
|
||||||
|
type: datetime
|
||||||
|
fields: payload.audit_period_beginning
|
||||||
|
audit_period_ending:
|
||||||
|
type: datetime
|
||||||
|
fields: payload.audit_period_ending
|
||||||
- event_type: trove.*
|
- event_type: trove.*
|
||||||
traits: &trove_base_traits
|
traits: &trove_base_traits
|
||||||
state:
|
state:
|
||||||
|
@ -96,6 +96,7 @@ ceilometer.notification =
|
|||||||
objectstore.request.meters = ceilometer.objectstore.notifications:SwiftWsgiMiddlewareMeters
|
objectstore.request.meters = ceilometer.objectstore.notifications:SwiftWsgiMiddlewareMeters
|
||||||
_sample = ceilometer.telemetry.notifications:TelemetryApiPost
|
_sample = ceilometer.telemetry.notifications:TelemetryApiPost
|
||||||
trove.instance.exists = ceilometer.database.notifications:InstanceExists
|
trove.instance.exists = ceilometer.database.notifications:InstanceExists
|
||||||
|
dns.domain.exists = ceilometer.dns.notifications:DomainExists
|
||||||
|
|
||||||
ceilometer.discover =
|
ceilometer.discover =
|
||||||
local_instances = ceilometer.compute.discovery:InstanceDiscovery
|
local_instances = ceilometer.compute.discovery:InstanceDiscovery
|
||||||
|
Loading…
Reference in New Issue
Block a user