Skip to content

Commit

Permalink
Merge pull request #16 from SvenskaSpel/use-built-in-locustfile-distr…
Browse files Browse the repository at this point in the history
…ibution-instead-of-rsync

Use built-in locustfile distribution instead of rsync.
  • Loading branch information
DennisKrone authored Feb 20, 2024
2 parents 796ca0e + 3dbd3fe commit c93aad9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
35 changes: 22 additions & 13 deletions locust_swarm/swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,18 @@
default=[],
help="A list of extra files or directories to upload. Space-separated, e.g. --extra-files testdata.csv *.py my-directory/",
)
parser.add_argument( # secret parameter to optimize by not uploading locust-plugins every time
parser.add_argument(
"--skip-plugins",
action="store_true",
default=False,
help=configargparse.SUPPRESS,
)
parser.add_argument(
"--upload-plugins",
action="store_true",
default=False,
help="Upload locust-plugins to load gens (useful if you are developing locust-plugins)",
)

parser.add_argument(
"--version",
Expand Down Expand Up @@ -248,8 +254,8 @@ def cleanup(server_list):


def upload(server):
files = [args.locustfile or "locustfile.py"] + args.extra_files
if not args.skip_plugins:
files = args.extra_files.copy()
if args.upload_plugins:
try:
files.append(os.path.dirname(svs_locust.__file__))
except NameError:
Expand All @@ -260,7 +266,12 @@ def upload(server):

files.append(os.path.dirname(locust_plugins.__file__))
except ModuleNotFoundError:
logging.debug("locust-plugins wasnt installed, not adding it to files to upload")
logging.error("locust-plugins wasnt installed")
sys.exit(1)

if not files:
return

if len(files) > 1:
filestr = "{" + ",".join(files) + "}"
else:
Expand All @@ -272,7 +283,7 @@ def upload(server):
check_output(f"rsync -qrtl --exclude __pycache__ --exclude .mypy_cache {filestr} {server}:")


def start_worker_process(server, port, locustfile_filename):
def start_worker_process(server, port):
upload(server)

if args.selenium:
Expand Down Expand Up @@ -344,7 +355,7 @@ def start_worker_process(server, port, locustfile_filename):
"--expect-workers-max-wait",
"30",
"-f",
locustfile_filename,
"-",
*ensure_remote_kill,
"'",
]
Expand Down Expand Up @@ -375,17 +386,15 @@ def main():

locustfile = args.locustfile or "locustfile.py"

if "/" in locustfile:
parser.error(
"Locustfile (-f) must be a file in the current directory (I'm lazy and havent fixed support for this yet)"
)

locustfile_filename = os.path.split(locustfile)[1]
port = int(args.port)
if args.processes_per_loadgen:
parser.error(
f"--processes-per-loadgen has been removed in favour of locusts native --processes parameter (you had it set to {args.processes_per_loadgen})"
)
if args.skip_plugins:
parser.error(
"--skip-plugins has been removed, the default is now NOT to upload plugins (but you can enable it with --upload-plugins)"
)
worker_process_count = args.processes * args.loadgens
loadgen_list = args.loadgen_list.split(",")
if args.loadgens < 0:
Expand Down Expand Up @@ -503,7 +512,7 @@ def get_available_servers_and_lock_them():
for server in server_list:
# fail early if master has already terminated
check_proc_running(master_proc)
worker_procs.extend(start_worker_process(server, port, locustfile_filename))
worker_procs.extend(start_worker_process(server, port))

# check that worker procs didnt immediately terminate for some reason (like invalid parameters)
try:
Expand Down
10 changes: 1 addition & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# -*- coding: utf-8 -*-
import os
import sys

import importlib.util
from setuptools import find_packages, setup
from setuptools.command.install import install
from setuptools.command.egg_info import egg_info
Expand Down Expand Up @@ -31,12 +29,6 @@ def run(self):
install_check(self, egg_info)


requirement_list = ["locust>=2.19.0"]
# if locust-plugins IS installed, then require a version known to work with this version of swarm.
spec = importlib.util.find_spec("locust_plugins")
if spec is not None:
requirement_list.append("locust-plugins>=2.7.0")

setup(
name="locust-swarm",
description="Load test + test data distribution & launching tool for Locust",
Expand Down Expand Up @@ -65,7 +57,7 @@ def run(self):
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires=requirement_list,
install_requires=["locust>=2.23.0"],
entry_points={
"console_scripts": ["swarm = locust_swarm.swarm:main"],
},
Expand Down

0 comments on commit c93aad9

Please sign in to comment.