def test_connect_host(self): port = utils.get_avalible_port() self.assertRaisesRegexp(r.ReqlDriverError, "Could not connect to 0.0.0.0:%d." % port, r.connect, host="0.0.0.0", port=port)
def test_connect_port(self): port = utils.get_avalible_port() with self.assertRaisesRegexp( r.ReqlDriverError, "Could not connect to localhost:%d." % port): yield r.connect(port=port)
def local_cluster_port(self): if self._local_cluster_port is None: self._local_cluster_port = utils.get_avalible_port() return self._local_cluster_port
def __init__(self, cluster, options, console_output=None, executable_path=None, command_prefix=None): global runningServers # - validate input assert isinstance(cluster, Cluster) assert cluster.metacluster is not None if command_prefix is None: command_prefix = [] if options is None: options = [] elif not hasattr(options, 'index'): raise ValueError('options must be an array of command line options, got: %s' % str(options)) if executable_path is None: executable_path = utils.find_rethinkdb_executable() assert os.access(executable_path, os.X_OK), "no such executable: %r" % executable_path self.executable_path = executable_path for other_cluster in cluster.metacluster.clusters: if other_cluster is not cluster: other_cluster._block_process(self) if self.console_file is None: if console_output is None: self.console_file = sys.stdout elif console_output in (False, True): self._close_console_output = True if console_output is False or self.files is None: self.console_file = tempfile.NamedTemporaryFile(mode='w+') else: self.console_file = open(os.path.join(self.files.db_path, 'console.txt'), 'w+') elif hasattr(console_output, 'write'): self.console_file = console_output else: self._close_console_output = True self.console_file = open(console_output, "a") # - add to the cluster self.cluster = cluster self.cluster.processes.append(self) # - set defaults if not '--bind' in options: options += ['--bind', 'all'] if not '--cluster-port' in options: options += ['--cluster-port', '0'] if not '--driver-port' in options: options += ['--driver-port', '0'] if not '--http-port' in options: options += ['--http-port', '0'] if not '--client-port' in options: # allows resunder to know what port to block self.local_cluster_port = utils.get_avalible_port() options += ['--client-port', str(self.local_cluster_port)] if not '--log-file' in options: options += ['--log-file', str(self.logfile_path)] if not '--no-update-check' in options: options += ['--no-update-check'] # supress update checks/reporting in # - set to join the cluster for peer in cluster.processes: if peer != self: options += ["--join", peer.host + ":" + str(peer.cluster_port)] break # - try: self.args = command_prefix + [self.executable_path] + options if os.path.exists(self.logfile_path): os.unlink(self.logfile_path) self.console_file.write("Launching:\n%s\n" % str(self.args)) self.process = subprocess.Popen(self.args, stdout=self.console_file, stderr=subprocess.STDOUT, preexec_fn=os.setpgrp) runningServers.append(self) self.process_group_id = self.process.pid self.running = True # - start thread to tail output for needed info thread.start_new_thread(self.read_ports_from_log, ()) except Exception: # `close()` won't be called because we haven't put ourself into # `cluster.processes` yet, so we have to clean up manually for other_cluster in cluster.metacluster.clusters: if other_cluster is not cluster: other_cluster._unblock_process(self) if self.cluster and self in self.cluster.processes: self.cluster.processes.remove(self) assert self not in self.cluster.processes raise
def local_cluster_port(self): if self._local_cluster_port is None: self._local_cluster_port = utils.get_avalible_port() return self._local_cluster_port