keystonemiddleware/keystonemiddleware/audit/_notifier.py
Tin Lam 0f4d4f8010 Fix oslo.messaging deprecation of get_transport
Oslo.messaging has deprecated get_transport and splits it into
get_notification_transport and get_rpc_transport.  This patch set updates the
code and addresses a zuul check/gate error [1].

[1] http://logs.openstack.org/55/467155/2/check/gate-keystonemiddleware-python27-ubuntu-xenial/3b6d9ef/console.html#_2017-05-24_23_49_58_453129

Change-Id: I263bd1076b47749bd14393855803419d0be9d758
2017-05-24 22:14:07 -05:00

59 lines
1.7 KiB
Python

# 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 os
import sys
try:
import oslo_messaging
except ImportError:
oslo_messaging = None
class _LogNotifier(object):
def __init__(self, log):
self._log = log
def notify(self, context, event_type, payload):
self._log.info('Event type: %(event_type)s, Context: %(context)s, '
'Payload: %(payload)s', {'context': context,
'event_type': event_type,
'payload': payload})
class _MessagingNotifier(object):
def __init__(self, notifier):
self._notifier = notifier
def notify(self, context, event_type, payload):
self._notifier.info(context, event_type, payload)
def create_notifier(conf, log):
if oslo_messaging:
transport = oslo_messaging.get_notification_transport(
conf.oslo_conf_obj,
url=conf.get('transport_url'))
notifier = oslo_messaging.Notifier(
transport,
os.path.basename(sys.argv[0]),
driver=conf.get('driver'),
topics=conf.get('topics'))
return _MessagingNotifier(notifier)
else:
return _LogNotifier(log)