Skip to content

Instantly share code, notes, and snippets.

@markmc
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save markmc/8953856 to your computer and use it in GitHub Desktop.

Select an option

Save markmc/8953856 to your computer and use it in GitHub Desktop.

Revisions

  1. markmc revised this gist Feb 12, 2014. 2 changed files with 1 addition and 1 deletion.
    1 change: 1 addition & 0 deletions console
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    $> python ./test-notification-server.py

    $> python test-notification.py --config-file ./test.conf --debug
    $> git reset --hard 5315399
    $> python test-notification-old.py --config-file ./test.conf --debug
    1 change: 0 additions & 1 deletion test-notification-server.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    class Kombu(object):

    def __init__(self):
  2. markmc revised this gist Feb 12, 2014. 4 changed files with 0 additions and 3 deletions.
    1 change: 0 additions & 1 deletion test-notification-old.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    import eventlet

    eventlet.monkey_patch(os=False)
    1 change: 0 additions & 1 deletion test-notification-server.py
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@


    class Kombu(object):

    def __init__(self):
    1 change: 0 additions & 1 deletion test-notification.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    import eventlet

    eventlet.monkey_patch(os=False)
    File renamed without changes.
  3. markmc created this gist Feb 12, 2014.
    4 changes: 4 additions & 0 deletions console
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    $> python ./test-notification-server.py

    $> python test-notification.py --config-file ./test.conf --debug
    $> python test-notification-old.py --config-file ./test.conf --debug
    9 changes: 9 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    [DEFAULT]
    rpc_backend = nova.openstack.common.rpc.impl_kombu
    rabbit_host = localhost
    rabbit_port = 5672
    rabbit_virtual_host = /
    control_exchange = nova

    notification_driver = nova.openstack.common.notifier.rpc_notifier
    notification_topics = notifications
    18 changes: 18 additions & 0 deletions test-notification-old.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@

    import eventlet

    eventlet.monkey_patch(os=False)

    import sys

    from nova import config
    from nova import context
    from nova.openstack.common import log as logging
    from nova.openstack.common.notifier import api as notifier_api

    config.parse_args(sys.argv)

    logging.setup("nova")

    notifier_api.notify(context.RequestContext('user', 'project', is_admin=True),
    'compute.blaa', 'foo', notifier_api.INFO, {})
    72 changes: 72 additions & 0 deletions test-notification-server.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,72 @@


    class Kombu(object):

    def __init__(self):

    self.params = {
    'hostname': 'localhost',
    'port': 5672,
    'virtual_host': '/',
    }

    self.exchange_name = 'nova'
    self.topic = 'notifications.info'

    def connect(self):
    import kombu.connection
    import kombu.entity

    self.connection = kombu.connection.BrokerConnection(**self.params)
    self.connection.connect()

    self.channel = self.connection.channel()

    exchange = kombu.entity.Exchange(name=self.exchange_name,
    type='topic',
    durable=False,
    auto_delete=False)

    queue = kombu.entity.Queue(name=self.topic,
    exchange=exchange,
    routing_key=self.topic,
    channel=self.channel,
    durable=False,
    auto_delete=False,
    exclusive=False)
    queue.declare()

    queue.consume(consumer_tag=str(1),
    nowait=False,
    callback=self.callback)

    def callback(self, raw_message):
    message = self.channel.message_to_python(raw_message)
    print message.payload
    message.ack()

    @property
    def sock(self):
    return self.connection.connection.sock

    def process_pending(self):
    self.connection.drain_events(timeout=0)


    import select
    import socket
    import errno

    k = Kombu()
    k.connect()

    p = select.poll()
    p.register(k.sock, select.POLLIN|select.POLLPRI)

    while True:
    try:
    k.process_pending()
    except socket.error as e:
    if e.errno != errno.EAGAIN:
    raise e
    p.poll()
    18 changes: 18 additions & 0 deletions test-notification.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@

    import eventlet

    eventlet.monkey_patch(os=False)

    import sys

    from nova import config
    from nova import context
    from nova.openstack.common import log as logging
    from nova import rpc

    config.parse_args(sys.argv)

    logging.setup("nova")

    notifier = rpc.get_notifier(service='compute', host='blaa')
    notifier.info(context.RequestContext('user', 'project', is_admin=True), 'foo', {})