def run(redis_connection, node_url, node_name, node_port, num_workers, no_redis, queue, module, datadir, read_only): if not node_url.endswith("/"): node_url += "/" if node_name is None: node_name = node_url datadir = abspath(datadir) register_shutdown() redis_connection_info = parse_redis_connection(redis_connection) if node_port is None: node_port = int(urlparse.urlparse(node_url).netloc.split(":")[-1]) print ("**port", node_port) pid_file = "ks-%s.pid" % node_port if not no_redis: print ("Starting redis on %s" % redis_connection) start_redis(pid_file, redis_connection_info['port'], os.getcwd()) time.sleep(1) cmd = [sys.executable, '-m', 'kitchensink.scripts.start_worker', '--node-url', node_url, '--node-name', node_name, '--redis-connection', redis_connection, '--datadir', datadir, ] if module: cmd.extend(('--module', module)) if read_only: cmd.append('--read-only') app = make_app(redis_connection_info, node_port, node_url, node_name, datadir, read_only) app.debug_log_format = FORMAT for c in range(10): try: result = settings.redis_conn.ping() break except ConnectionError: time.sleep(1.0) if queue is None: queue = ['default', 'data'] for q in queue: cmd.extend(['--queue', q]) for c in range(num_workers): print ('**cmd', cmd) ManagedProcess(cmd, 'worker-%s' % c, pid_file) data_rpc = make_data_rpc() register_rpc(data_rpc, 'data') default_rpc = RPC() register_rpc(default_rpc, 'default') admin = make_admin_rpc() register_rpc(admin, 'admin') if module: mod = __import__(module) runserver(gevent=gevent)
def setup_module(node3_read_only=False): global dir1 global dir2 global dir3 global redis_dir global rport global url1 global url2 global url3 dir1 = tempfile.mkdtemp(prefix="ks-test") dir2 = tempfile.mkdtemp(prefix="ks-test") dir3 = tempfile.mkdtemp(prefix="ks-test") redis_dir = tempfile.mkdtemp(prefix="ks-test") port1 = 6323 port2 = 6324 port3 = 6325 rport = 6326 url1 = "http://localhost:%s/" % port1 url2 = "http://localhost:%s/" % port2 url3 = "http://localhost:%s/" % port3 redis_url = "tcp://localhost:%s?db=9" % rport start_redis(pid_file, rport, redis_dir, stdout=None, stderr=None) wait_redis_start(rport) cmd = [ "python", "-m", "kitchensink.scripts.start", "--datadir", dir1, "--no-redis", "--node-name", "node1", "--node-url", url1, "--num-workers", "1", "--redis-connection", redis_url, ] p = ManagedProcess(cmd, "node1", pid_file) wait_ks_start(url1) cmd = [ "python", "-m", "kitchensink.scripts.start", "--datadir", dir2, "--no-redis", "--node-name", "node2", "--node-url", url2, "--num-workers", "1", "--redis-connection", redis_url, ] p = ManagedProcess(cmd, "node2", pid_file) wait_ks_start(url2) cmd = [ "python", "-m", "kitchensink.scripts.start", "--datadir", dir3, "--no-redis", "--node-name", "node3", "--node-url", url3, "--num-workers", "1", "--redis-connection", redis_url, ] if node3_read_only: cmd.append("--read-only") p = ManagedProcess(cmd, "node3", pid_file) wait_ks_start(url3) # hack - wait for workers to sleep. necessary if # we want tests to accurately reflect performance time.sleep(1)