Add test code for the rabbit driver
These are just a couple of silly sample scripts. Proper unit tests will follow. Change-Id: I6f27ae071c7e6f96059fd665d1163c89227833b9
This commit is contained in:
parent
b7350fa229
commit
29dcc87052
39
doc/messaging/test-rabbit-client.py
Normal file
39
doc/messaging/test-rabbit-client.py
Normal file
@ -0,0 +1,39 @@
|
||||
import eventlet
|
||||
|
||||
eventlet.monkey_patch(os=False)
|
||||
|
||||
import logging
|
||||
import socket
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from oslo import messaging
|
||||
|
||||
_opts = [
|
||||
cfg.StrOpt('host', default=socket.gethostname()),
|
||||
]
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.register_opts(_opts)
|
||||
|
||||
LOG = logging.getLogger('client')
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
CONF()
|
||||
CONF.log_opt_values(LOG, logging.DEBUG)
|
||||
|
||||
class Client(object):
|
||||
|
||||
def __init__(self, transport):
|
||||
target = messaging.Target(topic='topic')
|
||||
self._client = messaging.RPCClient(transport, target)
|
||||
super(Client, self).__init__()
|
||||
|
||||
def ping(self, ctxt):
|
||||
return self._client.call(ctxt, 'ping')
|
||||
|
||||
transport = messaging.get_transport(CONF, 'rabbit:///test')
|
||||
|
||||
client = Client(transport)
|
||||
print client.ping({})
|
52
doc/messaging/test-rabbit-server.py
Normal file
52
doc/messaging/test-rabbit-server.py
Normal file
@ -0,0 +1,52 @@
|
||||
|
||||
import eventlet
|
||||
|
||||
eventlet.monkey_patch(os=False)
|
||||
|
||||
import logging
|
||||
import socket
|
||||
|
||||
from oslo.config import cfg
|
||||
|
||||
from oslo import messaging
|
||||
|
||||
_opts = [
|
||||
cfg.StrOpt('host', default=socket.gethostname()),
|
||||
]
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.register_opts(_opts)
|
||||
|
||||
LOG = logging.getLogger('server')
|
||||
|
||||
CONF()
|
||||
CONF.log_opt_values(LOG, logging.DEBUG)
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
class Server(object):
|
||||
|
||||
def __init__(self, transport):
|
||||
self.target = messaging.Target(topic='topic',
|
||||
server=transport.conf.host)
|
||||
self._server = messaging.get_rpc_server(transport,
|
||||
self.target,
|
||||
[self],
|
||||
executor='eventlet')
|
||||
super(Server, self).__init__()
|
||||
|
||||
def start(self):
|
||||
self._server.start()
|
||||
|
||||
def wait(self):
|
||||
self._server.wait()
|
||||
|
||||
def ping(self, ctxt):
|
||||
LOG.info("PING")
|
||||
return 'ping'
|
||||
|
||||
transport = messaging.get_transport(CONF, 'rabbit:///test')
|
||||
|
||||
server = Server(transport)
|
||||
server.start()
|
||||
server.wait()
|
Loading…
x
Reference in New Issue
Block a user