-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure use of
localhost
when stopping Redis
This is a back-port of commit c84c6ed (PR #2863) from `main`. When `pbench-tool-meister-stop` is invoked where the Redis server was created locally by `pbench-tool-meister-start`, we always want to use the `localhost` IP address to talk to it. Also added unit tests for the `tool_meister_stop.py` module's `RedisServer` class, and corrected the `pbench-tool-meister-stop` CLI param default value for the `--redis-server` switch. Fixes issue #2861 [1]. [1] #2861
- Loading branch information
Showing
2 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""Tests for the Tool Meister "stop" module. | ||
""" | ||
from pbench.agent.tool_meister_stop import RedisServer | ||
|
||
|
||
class TestRedisServer: | ||
"""Verify the RedisServer class use by Tool Meister "stop".""" | ||
|
||
def test_locally_managed(self, tmp_path): | ||
# Locally managed means we have a run directory, ... | ||
rundir = tmp_path / "run-dir" | ||
rundir.mkdir() | ||
# ... with a "tm" sub-directory, ... | ||
tmdir = rundir / "tm" | ||
tmdir.mkdir() | ||
# ... containing a "redis.pid" file. | ||
pidfile = tmdir / "redis.pid" | ||
pidfile.write_text("12345") | ||
|
||
rs = RedisServer("", rundir, "notme.example.com") | ||
assert ( | ||
rs.locally_managed() | ||
), "RedisServer incorrectly inferred a non-locally managed instance from a run directory with a 'tm/redis.pid' file" | ||
assert ( | ||
rs.host == "localhost" | ||
), f"Expected 'RedisServer.host' to be 'localhost', got '{rs.host}'" | ||
|
||
def test_not_locally_managed(self, tmp_path): | ||
# Empty benchmark run directory indicates not locally managed. | ||
rundir = tmp_path / "empty-run-dir" | ||
rundir.mkdir() | ||
|
||
rs_host = "redis.example.com" | ||
rs = RedisServer(f"{rs_host}:4343", rundir, "notme.example.com") | ||
assert ( | ||
not rs.locally_managed() | ||
), "RedisServer incorrectly inferred a locally managed instance from an empty run directory" | ||
assert ( | ||
rs.host == "redis.example.com" | ||
), f"Expected 'RedisServer.host' to be '{rs_host}', got '{rs.host}'" |