Register configuration options before load driver
The configuration should be set before the driver is loaded, this will avoid the message in tests: `WARNING [stevedore.named] Could not load prometheus_exporter`
This commit is contained in:
parent
a94a8d8eee
commit
f27a9fe299
@ -0,0 +1,7 @@
|
||||
from oslo_config import cfg
|
||||
|
||||
from ironic_prometheus_exporter import messaging
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
messaging.register_opts(CONF)
|
@ -9,18 +9,19 @@ prometheus_opts = [
|
||||
]
|
||||
|
||||
|
||||
def register_opts(conf):
|
||||
conf.register_opts(prometheus_opts, group='oslo_messaging_notifications')
|
||||
|
||||
|
||||
class PrometheusFileDriver(notifier.Driver):
|
||||
|
||||
"Publish notifications into a File to be used by Prometheus"
|
||||
|
||||
def __init__(self, conf, topics, transport):
|
||||
conf.register_opts(prometheus_opts,
|
||||
group='oslo_messaging_notifications')
|
||||
self.conf = conf
|
||||
if not os.path.exists(self.conf.oslo_messaging_notifications.file_dir):
|
||||
os.makedirs(self.conf.oslo_messaging_notifications.file_dir)
|
||||
self.file_dir = self.conf.oslo_messaging_notifications.file_dir
|
||||
self.file_name = self.conf.oslo_messaging_notifications.file_name
|
||||
self.file_dir = conf.oslo_messaging_notifications.file_dir
|
||||
self.file_name = conf.oslo_messaging_notifications.file_name
|
||||
if not os.path.exists(self.file_dir):
|
||||
os.makedirs(self.file_dir)
|
||||
super(PrometheusFileDriver, self).__init__(conf, topics, transport)
|
||||
|
||||
def notify(self, ctxt, message, priority, retry):
|
||||
|
@ -9,15 +9,14 @@ class TestPrometheusFileNotifier(test_utils.BaseTestCase):
|
||||
super(TestPrometheusFileNotifier, self).setUp()
|
||||
|
||||
def test_notifier(self):
|
||||
transport = oslo_messaging.get_notification_transport(self.conf)
|
||||
my_notifier = oslo_messaging.Notifier(transport,
|
||||
driver='prometheus_exporter',
|
||||
topics=['my_topics'])
|
||||
self.config(file_name='test.txt',
|
||||
file_dir='/tmp/ironic_prometheus_exporter',
|
||||
group='oslo_messaging_notifications')
|
||||
transport = oslo_messaging.get_notification_transport(self.conf)
|
||||
oslo_messaging.Notifier(transport, driver='prometheus_exporter',
|
||||
topics=['my_topics'])
|
||||
|
||||
self.assertEqual(self.conf.oslo_messaging_notifications.file_name,
|
||||
"test.txt")
|
||||
self.assertEqual(self.conf.oslo_messaging_notifications.file_dir,
|
||||
'/tmp/ironic_prometheus_exporter')
|
||||
my_notifier.debug({}, "My Event", 'Payload')
|
||||
|
Loading…
Reference in New Issue
Block a user