deb-ceilometer/tests/test_tools_notificationclient.py
Doug Hellmann b76f67d11f Publish and receive metering messages
bug 1004198
bug 1004200

- Set up the collector to receive the metering messages.
- Make the collector republish notifications as metering data.
- Add a "monitor" mode to tools/notificationclient.py to simply print
  the events without writing them to a file.
- Add a --topic flag to tools/notificationclient.py so it can be made
  to listen events other than notifications (for monitoring metering
  events).
- Change "counter_datetime" within the metering message to "timestamp"
  to be consistent with the notification message format.
- Add a configuration option to control the secret value for signing
  metering messages.
- Make the collector and agent daemon control topics more specific.
- Use the config setting to set the metering topic subscription.
- Set a short interval for polling to get more data for development
  testing.
- Log after successful load of pollsters instead of before attempt.

Change-Id: Iedfe26f8a4fa80d88cd0a76e5738001ba5689bdc
2012-05-25 19:31:58 -04:00

41 lines
1.2 KiB
Python

import os
import cPickle as pickle
from StringIO import StringIO
import sys
import types
import mox
from nova.rpc import impl_kombu
# The module being tested is part of the tools directory,
# so make sure it is in our import path.
sys.path.insert(0, os.path.normpath(os.path.join(os.path.dirname(__file__),
'..', 'tools')))
import notificationclient
def test_send_messages():
message = {'timestamp': 'date goes here',
'event_type': 'compute.instance.exists',
# real messages have more fields...
}
input = StringIO(pickle.dumps(message))
conn = mox.MockObject(impl_kombu.Connection)
conn.topic_send('notifications.info', message)
mox.Replay(conn)
notificationclient.send_messages(conn, 'notifications.info', input)
mox.Verify(conn)
return
def test_record_messages():
conn = mox.MockObject(impl_kombu.Connection)
conn.declare_topic_consumer('notifications.info',
mox.IsA(types.FunctionType))
conn.consume()
mox.Replay(conn)
notificationclient.record_messages(conn, 'notifications.info', StringIO())
mox.Verify(conn)
return