Back to index

rabbitmq-server  2.8.4
test_util.py
Go to the documentation of this file.
00001 import subprocess
00002 import socket
00003 import sys
00004 import os
00005 import os.path
00006 
00007 def ensure_ssl_auth_user():
00008     user = 'O=client,CN=%s' % socket.gethostname()
00009     rabbitmqctl(['stop_app'])
00010     rabbitmqctl(['reset'])
00011     rabbitmqctl(['start_app'])
00012     rabbitmqctl(['add_user', user, 'foo'])
00013     rabbitmqctl(['clear_password', user])
00014     rabbitmqctl(['set_permissions', user, '.*', '.*', '.*'])
00015 
00016 def enable_implicit_connect():
00017     switch_config(implicit_connect='true', default_user='[{login, "guest"}, {passcode, "guest"}]')
00018 
00019 def disable_implicit_connect():
00020     switch_config(implicit_connect='false', default_user='[]')
00021 
00022 def enable_default_user():
00023     switch_config(default_user='[{login, "guest"}, {passcode, "guest"}]')
00024 
00025 def disable_default_user():
00026     switch_config(default_user='[]')
00027 
00028 def switch_config(implicit_connect='', default_user=''):
00029     cmd = 'application:stop(rabbitmq_stomp),'
00030     if implicit_connect:
00031         cmd += 'application:set_env(rabbitmq_stomp,implicit_connect,' + implicit_connect + '),'
00032     if default_user:
00033         cmd += 'application:set_env(rabbitmq_stomp,default_user,' + default_user + '),'
00034     cmd += 'application:start(rabbitmq_stomp).'
00035     rabbitmqctl(['eval', cmd])
00036 
00037 def rabbitmqctl(args):
00038     ctl = os.path.normpath(os.path.join(os.getcwd(), sys.argv[0], '../../../../rabbitmq-server/scripts/rabbitmqctl'))
00039     cmdline = [ctl, '-n', 'rabbit-test']
00040     cmdline.extend(args)
00041     subprocess.check_call(cmdline)
00042