From 20f76006c731ab948dfe2b3a2e8f88054dc4694b Mon Sep 17 00:00:00 2001 From: Rick Boyd Date: Wed, 13 Jul 2022 13:24:23 -0400 Subject: [PATCH] Don't load libs path if not using it (#1540) This PR fixes an issue where a dependency installed via the Track Dependencies mechanism lingers for esrally invocations where it is not needed or wanted. Also fixes #1474 --- esrally/driver/driver.py | 2 +- esrally/racecontrol.py | 2 +- esrally/rally.py | 12 ++++++++++++ esrally/track/loader.py | 14 -------------- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/esrally/driver/driver.py b/esrally/driver/driver.py index 103fbe47b..a7fb42716 100644 --- a/esrally/driver/driver.py +++ b/esrally/driver/driver.py @@ -473,7 +473,7 @@ def receiveMsg_Bootstrap(self, msg, sender): # load node-specific config to have correct paths available self.cfg = load_local_config(msg.config) # this instance of load_track occurs once per host, so install dependencies if necessary - load_track(self.cfg, install_dependencies=True) + load_track(self.cfg, install_dependencies=False) self.send(sender, ReadyForWork()) @actor.no_retry("track preparator") # pylint: disable=no-value-for-parameter diff --git a/esrally/racecontrol.py b/esrally/racecontrol.py index f9be96486..bf3f1d32b 100644 --- a/esrally/racecontrol.py +++ b/esrally/racecontrol.py @@ -191,7 +191,7 @@ def setup(self, sources=False): if specified_version < min_es_version: raise exceptions.SystemSetupError(f"Cluster version must be at least [{min_es_version}] but was [{distribution_version}]") - self.current_track = track.load_track(self.cfg, install_dependencies=False) + self.current_track = track.load_track(self.cfg, install_dependencies=True) self.track_revision = self.cfg.opts("track", "repository.revision", mandatory=False) challenge_name = self.cfg.opts("track", "challenge.name") self.current_challenge = self.current_track.find_challenge_or_default(challenge_name) diff --git a/esrally/rally.py b/esrally/rally.py index 3bd56a197..4ad144882 100644 --- a/esrally/rally.py +++ b/esrally/rally.py @@ -20,6 +20,7 @@ import logging import os import platform +import shutil import sys import time import uuid @@ -1081,6 +1082,17 @@ def main(): sys.exit(0) logger.info("Detected a working Internet connection.") + def _trap(function, path, exc_info): + if exc_info[0] == FileNotFoundError: + # couldn't delete because it was already clean + return + logging.exception("Failed to clean up [%s] with [%s]", path, function, exc_info=True) + raise exceptions.SystemSetupError(f"Unable to clean [{paths.libs()}]. See Rally log for more information.") + + # fully destructive is fine, we only allow one Rally to run at a time and we will rely on the pip cache for download caching + logging.info("Cleaning track dependency directory [%s]...", paths.libs()) + shutil.rmtree(paths.libs(), onerror=_trap) + result = dispatch_sub_command(arg_parser, args, cfg) end = time.time() diff --git a/esrally/track/loader.py b/esrally/track/loader.py index 9e49c291b..724efea56 100644 --- a/esrally/track/loader.py +++ b/esrally/track/loader.py @@ -19,7 +19,6 @@ import logging import os import re -import shutil import subprocess import sys import tempfile @@ -195,18 +194,7 @@ def load_track(cfg, install_dependencies=False): def _install_dependencies(dependencies): - def _cleanup(): - # fully destructive is fine, we only allow one Rally to run at a time and we will rely on the pip cache for download caching - console.info("Cleaning track dependency directory...") - logging.info("Cleaning track dependency directory [%s]...", paths.libs()) - shutil.rmtree(paths.libs(), onerror=_trap) - - def _trap(function, path, exc_info): - logging.exception("Failed to clean up [%s] with [%s]", path, function, exc_info=True) - raise exceptions.SystemSetupError(f"Unable to clean [{paths.libs()}]. See Rally log for more information.") - if dependencies: - _cleanup() log_path = os.path.join(paths.logs(), "dependency.log") console.info(f"Installing track dependencies [{', '.join(dependencies)}]") try: @@ -249,7 +237,6 @@ def load_track_plugins( register_runner=None, register_scheduler=None, register_track_processor=None, - install_dependencies=False, force_update=False, ): """ @@ -260,7 +247,6 @@ def load_track_plugins( :param register_runner: An optional function where runners can be registered. :param register_scheduler: An optional function where custom schedulers can be registered. :param register_track_processor: An optional function where track processors can be registered. - :param install_dependencies: If set to ``True``, install declared dependencies from the track.py. Defaults to ``False``. :param force_update: If set to ``True`` this ensures that the track is first updated from the remote repository. Defaults to ``False``. :return: True iff this track defines plugins and they have been loaded.