def _start_process(binary_path, env): if os.name == "posix" and os.geteuid() == 0: raise exceptions.LaunchError("Cannot launch Elasticsearch as root. Please run Rally as a non-root user.") os.chdir(binary_path) cmd = [io.escape_path(os.path.join(".", "bin", "elasticsearch"))] cmd.extend(["-d", "-p", "pid"]) ret = process.run_subprocess_with_logging(command_line=" ".join(cmd), env=env, detach=True) if ret != 0: msg = "Daemon startup failed with exit code [{}]".format(ret) logging.error(msg) raise exceptions.LaunchError(msg) return wait_for_pidfile(io.escape_path(os.path.join(".", "pid")))
def clone(src, remote): io.ensure_dir(src) # Don't swallow subprocess output, user might need to enter credentials... if process.run_subprocess_with_logging("git clone %s %s" % (remote, io.escape_path(src))): raise exceptions.SupplyError("Could not clone from [%s] to [%s]" % (remote, src))
def pull_ts(src_dir, ts): fetch(src_dir) clean_src = io.escape_path(src_dir) revision = process.run_subprocess_with_output( "git -C {0} rev-list -n 1 --before=\"{1}\" --date=iso8601 origin/master".format(clean_src, ts))[0].strip() if process.run_subprocess_with_logging("git -C {0} checkout {1}".format(clean_src, revision)): raise exceptions.SupplyError("Could not checkout source tree for timestamped revision [%s]" % ts)
def branches(src_dir, remote=True): clean_src = io.escape_path(src_dir) if remote: # alternatively: git for-each-ref refs/remotes/ --format='%(refname:short)' return _cleanup_remote_branch_names(process.run_subprocess_with_output( "git -C {src} for-each-ref refs/remotes/ --format='%(refname:short)'".format(src=clean_src))) else: return _cleanup_local_branch_names( process.run_subprocess_with_output( "git -C {src} for-each-ref refs/heads/ --format='%(refname:short)'".format(src=clean_src)))
def probe(src, *args, **kwargs): # Probe for -C if not process.exit_status_as_bool(lambda: process.run_subprocess_with_logging( "git -C {} --version".format(io.escape_path(src)), level=logging.DEBUG), quiet=True): version = process.run_subprocess_with_output("git --version") if version: version = str(version).strip() else: version = "Unknown" raise exceptions.SystemSetupError("Your git version is [%s] but Rally requires at least git 1.9. Please update git." % version) return f(src, *args, **kwargs)
def install_default_log_config(): """ Ensures a log configuration file is present on this machine. The default log configuration is based on the template in resources/logging.json. It also ensures that the default log path has been created so log files can be successfully opened in that directory. """ log_config = log_config_path() if not io.exists(log_config): io.ensure_dir(io.dirname(log_config)) source_path = io.normalize_path( os.path.join(os.path.dirname(__file__), "resources", "logging.json")) with open(log_config, "w", encoding="UTF-8") as target: with open(source_path, "r", encoding="UTF-8") as src: # Ensure we have a trailing path separator as after LOG_PATH there will only be the file name log_path = os.path.join(paths.logs(), "") # the logging path might contain backslashes that we need to escape log_path = io.escape_path(log_path) contents = src.read().replace("${LOG_PATH}", log_path) target.write(contents) io.ensure_dir(paths.logs())
def fetch(src, remote="origin"): if process.run_subprocess_with_logging( "git -C {0} fetch --prune --tags {1}".format( io.escape_path(src), remote)): raise exceptions.SupplyError("Could not fetch source tree from [%s]" % remote)
def tags(src_dir): return _cleanup_tag_names( process.run_subprocess_with_output("git -C {0} tag".format( io.escape_path(src_dir))))
def current_branch(src_dir): return process.run_subprocess_with_output( "git -C {0} rev-parse --abbrev-ref HEAD".format( io.escape_path(src_dir)))[0].strip()
def head_revision(src_dir): return process.run_subprocess_with_output( "git -C {0} rev-parse --short HEAD".format( io.escape_path(src_dir)))[0].strip()
def pull_revision(src_dir, revision): fetch(src_dir) if process.run_subprocess_with_logging("git -C {0} checkout {1}".format( io.escape_path(src_dir), revision)): raise exceptions.SupplyError( "Could not checkout source tree for revision [%s]" % revision)