Skip to content

Commit

Permalink
Don't load libs path if not using it (elastic#1540)
Browse files Browse the repository at this point in the history

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 elastic#1474
  • Loading branch information
Rick Boyd authored Jul 13, 2022
1 parent 82c698e commit 20f7600
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion esrally/driver/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion esrally/racecontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions esrally/rally.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import logging
import os
import platform
import shutil
import sys
import time
import uuid
Expand Down Expand Up @@ -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()
Expand Down
14 changes: 0 additions & 14 deletions esrally/track/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import logging
import os
import re
import shutil
import subprocess
import sys
import tempfile
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -249,7 +237,6 @@ def load_track_plugins(
register_runner=None,
register_scheduler=None,
register_track_processor=None,
install_dependencies=False,
force_update=False,
):
"""
Expand All @@ -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.
Expand Down

0 comments on commit 20f7600

Please sign in to comment.