Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if not io.exists(car_config_file):
raise exceptions.SystemSetupError("Unknown car [{}]. List the available cars with {} list cars.".format(name, PROGRAM_NAME))
config = self._config_loader(car_config_file)
root_paths = []
config_paths = []
config_base_vars = {}
description = self._value(config, ["meta", "description"], default="")
car_type = self._value(config, ["meta", "type"], default="car")
config_bases = self._value(config, ["config", "base"], default="").split(",")
for base in config_bases:
if base:
root_path = os.path.join(self.cars_dir, base)
root_paths.append(root_path)
config_paths.append(os.path.join(root_path, "templates"))
config_file = os.path.join(root_path, "config.ini")
if io.exists(config_file):
base_config = self._config_loader(config_file)
self._copy_section(base_config, "variables", config_base_vars)
# it's possible that some cars don't have a config base, e.g. mixins which only override variables
if len(config_paths) == 0:
self.logger.info("Car [%s] does not define any config paths. Assuming that it is used as a mixin.", name)
variables = self._copy_section(config, "variables", {})
# add all car params here to override any defaults
if car_params:
variables.update(car_params)
env = self._copy_section(config, "env", {})
return CarDescriptor(name, description, car_type, root_paths, config_paths, config_base_vars, variables, env)
def render_template_from_file(template_file_name, template_vars, complete_track_params=None):
def relative_glob(start, f):
result = glob.glob(os.path.join(start, f))
if result:
return [os.path.relpath(p, start) for p in result]
else:
return []
base_path = io.dirname(template_file_name)
template_source = TemplateSource(base_path, io.basename(template_file_name))
template_source.load_template_from_file()
register_all_params_in_track(template_source.assembled_source, complete_track_params)
return render_template(loader=jinja2.FileSystemLoader(base_path),
template_source=template_source.assembled_source,
template_vars=template_vars,
template_internal_vars=default_internal_template_vars(glob_helper=lambda f: relative_glob(base_path, f)))
cfg.add(config.Scope.applicationOverride, "mechanic", "keep.running", False)
cfg.add(config.Scope.applicationOverride, "mechanic", "preserve.install", convert.to_bool(args.preserve_install))
cfg.add(config.Scope.applicationOverride, "mechanic", "skip.rest.api.check", convert.to_bool(args.skip_rest_api_check))
cfg.add(config.Scope.applicationOverride, "mechanic", "runtime.jdk", args.runtime_jdk)
cfg.add(config.Scope.applicationOverride, "telemetry", "devices", opts.csv_to_list(args.telemetry))
cfg.add(config.Scope.applicationOverride, "telemetry", "params", opts.to_dict(args.telemetry_params))
cfg.add(config.Scope.applicationOverride, "race", "pipeline", args.pipeline)
cfg.add(config.Scope.applicationOverride, "race", "user.tag", args.user_tag)
cfg.add(config.Scope.applicationOverride, "track", "repository.revision", args.track_revision)
# We can assume here that if a track-path is given, the user did not specify a repository either (although argparse sets it to
# its default value)
if args.track_path:
cfg.add(config.Scope.applicationOverride, "track", "track.path", os.path.abspath(io.normalize_path(args.track_path)))
cfg.add(config.Scope.applicationOverride, "track", "repository.name", None)
if args.track_revision:
# stay as close as possible to argparse errors although we have a custom validation.
arg_parser.error("argument --track-revision not allowed with argument --track-path")
if args.track:
# stay as close as possible to argparse errors although we have a custom validation.
arg_parser.error("argument --track not allowed with argument --track-path")
# cfg.add(config.Scope.applicationOverride, "track", "track.name", None)
else:
# cfg.add(config.Scope.applicationOverride, "track", "track.path", None)
cfg.add(config.Scope.applicationOverride, "track", "repository.name", args.track_repository)
# set the default programmatically because we need to determine whether the user has provided a value
chosen_track = args.track if args.track else "geonames"
cfg.add(config.Scope.applicationOverride, "track", "track.name", chosen_track)
cfg.add(config.Scope.applicationOverride, "track", "params", opts.to_dict(args.track_params))
def _unzip(self, data_set_path):
# we assume that track data are always compressed and try to unzip them before running the benchmark
basename, extension = io.splitext(data_set_path)
if not os.path.isfile(basename):
logger.info("Unzipping track data from [%s] to [%s]." % (data_set_path, basename))
io.unzip(data_set_path, io.dirname(data_set_path))
return basename
# per node?
cfg.add(config.Scope.applicationOverride, "system", "offline.mode", args.offline)
cfg.add(config.Scope.applicationOverride, "system", "logging.output", args.logging)
# Local config per node
cfg.add(config.Scope.application, "node", "rally.root", paths.rally_root())
cfg.add(config.Scope.application, "node", "rally.cwd", os.getcwd())
cfg.add(config.Scope.applicationOverride, "mechanic", "source.revision", args.revision)
if args.distribution_version:
cfg.add(config.Scope.applicationOverride, "mechanic", "distribution.version", args.distribution_version)
cfg.add(config.Scope.applicationOverride, "mechanic", "distribution.repository", args.distribution_repository)
cfg.add(config.Scope.applicationOverride, "mechanic", "car.names", opts.csv_to_list(args.car))
if args.team_path:
cfg.add(config.Scope.applicationOverride, "mechanic", "team.path", os.path.abspath(io.normalize_path(args.team_path)))
cfg.add(config.Scope.applicationOverride, "mechanic", "repository.name", None)
else:
cfg.add(config.Scope.applicationOverride, "mechanic", "repository.name", args.team_repository)
cfg.add(config.Scope.applicationOverride, "mechanic", "car.plugins", opts.csv_to_list(args.elasticsearch_plugins))
cfg.add(config.Scope.applicationOverride, "mechanic", "car.params", opts.to_dict(args.car_params))
cfg.add(config.Scope.applicationOverride, "mechanic", "plugin.params", opts.to_dict(args.plugin_params))
if args.keep_cluster_running:
cfg.add(config.Scope.applicationOverride, "mechanic", "keep.running", True)
# force-preserve the cluster nodes.
cfg.add(config.Scope.applicationOverride, "mechanic", "preserve.install", True)
else:
cfg.add(config.Scope.applicationOverride, "mechanic", "keep.running", False)
cfg.add(config.Scope.applicationOverride, "mechanic", "preserve.install", convert.to_bool(args.preserve_install))
cfg.add(config.Scope.applicationOverride, "mechanic", "telemetry.devices", opts.csv_to_list(args.telemetry))
cfg.add(config.Scope.applicationOverride, "mechanic", "telemetry.params", opts.to_dict(args.telemetry_params))
@staticmethod
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)
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 _store(self, doc):
import json
io.ensure_dir(self.race_path)
with open(self._race_file(), mode="wt", encoding="utf-8") as f:
f.write(json.dumps(doc, indent=True, ensure_ascii=False))
def version():
"""
:return: The release version string and an optional suffix for the current git revision if Rally is installed in development mode.
"""
release = __version__
# noinspection PyBroadException
try:
if git.is_working_copy(io.normalize_path("%s/.." % paths.rally_root())):
revision = git.head_revision(paths.rally_root())
return "%s (git revision: %s)" % (release, revision.strip())
except BaseException:
pass
# cannot determine head revision so user has probably installed Rally via pip instead of git clone
return release
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)