Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion test/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ def redfish_conn_mock():
def run_cli_command():
"""Fixture that returns a function to run CLI commands."""

def _run_command(args: List[str], check: bool = False):
def _run_command(args: List[str], check: bool = False, cwd=None):
"""Run a node-scraper CLI command.

Args:
args: List of command-line arguments
check: If True, raise CalledProcessError on non-zero exit
cwd: Working directory for the command (default: the caller's). Use a tmp dir for
plugins whose probes write files to the cwd, e.g. wget saving index.html

Returns:
subprocess.CompletedProcess instance
Expand All @@ -68,6 +70,7 @@ def _run_command(args: List[str], check: bool = False):
capture_output=True,
text=True,
check=check,
cwd=cwd,
)

return _run_command
3 changes: 2 additions & 1 deletion test/functional/test_cli_no_console_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import sys


def test_no_console_log_with_log_path_none_still_parses():
def test_no_console_log_with_log_path_none_still_parses(tmp_path):
"""--log-path None + --no-console-log defaults to ./scraper_logs_* (no argparse error)."""
result = subprocess.run(
[
Expand All @@ -44,6 +44,7 @@ def test_no_console_log_with_log_path_none_still_parses():
],
capture_output=True,
text=True,
cwd=tmp_path,
)
assert result.returncode == 0, result.stderr
combined = (result.stdout or "") + (result.stderr or "")
Expand Down
1 change: 1 addition & 0 deletions test/functional/test_network_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def test_network_plugin_with_netprobe_wget(run_cli_command, tmp_path):
"wget",
],
check=False,
cwd=tmp_path, # wget saves the fetched page (index.html, index.html.1, ...) into the cwd
)

assert result.returncode in [0, 1, 2]
Expand Down
19 changes: 14 additions & 5 deletions test/functional/test_plugin_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,25 +181,34 @@ def test_plugin_config_with_multiple_configs(run_cli_command, plugin_config_file
def test_plugin_config_with_nonexistent_file(run_cli_command, tmp_path):
"""Test that a nonexistent config file path fails gracefully."""
nonexistent_path = str(tmp_path / "nonexistent_config.json")
result = run_cli_command([f"--plugin-configs={nonexistent_path}"], check=False)
result = run_cli_command(
["--log-path", str(tmp_path / "logs"), f"--plugin-configs={nonexistent_path}"],
check=False,
)

assert result.returncode != 0
output = (result.stdout + result.stderr).lower()
assert "error" in output or "no plugin config found" in output


def test_plugin_config_with_invalid_builtin_name(run_cli_command):
def test_plugin_config_with_invalid_builtin_name(run_cli_command, tmp_path):
"""Test that an invalid built-in config name fails gracefully."""
result = run_cli_command(["--plugin-configs=NonExistentConfig"], check=False)
result = run_cli_command(
["--log-path", str(tmp_path / "logs"), "--plugin-configs=NonExistentConfig"],
check=False,
)

assert result.returncode != 0
output = (result.stdout + result.stderr).lower()
assert "error" in output or "no plugin config found" in output


def test_plugin_config_with_invalid_json(run_cli_command, invalid_plugin_config):
def test_plugin_config_with_invalid_json(run_cli_command, invalid_plugin_config, tmp_path):
"""Test that an invalid JSON file fails gracefully."""
result = run_cli_command([f"--plugin-configs={invalid_plugin_config}"], check=False)
result = run_cli_command(
["--log-path", str(tmp_path / "logs"), f"--plugin-configs={invalid_plugin_config}"],
check=False,
)

assert result.returncode != 0
output = (result.stdout + result.stderr).lower()
Expand Down
7 changes: 5 additions & 2 deletions test/functional/test_run_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,12 @@ def test_run_all_plugins_together(run_cli_command, all_plugins, tmp_path):
assert len(output) > 0


def test_run_plugin_with_invalid_name(run_cli_command):
def test_run_plugin_with_invalid_name(run_cli_command, tmp_path):
"""Test that running a non-existent plugin logs a warning and falls back to default config."""
result = run_cli_command(["run-plugins", "NonExistentPlugin"], check=False)
result = run_cli_command(
["--log-path", str(tmp_path / "logs"), "run-plugins", "NonExistentPlugin"],
check=False,
)

# Invalid plugin is ignored and default config runs instead
# Exit code depends on whether default config plugins succeed
Expand Down
18 changes: 12 additions & 6 deletions test/unit/framework/test_compare_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,32 +126,38 @@ def test_run_compare_runs_no_data(caplog, tmp_path):
(tmp_path / "run2").mkdir()
logger = logging.getLogger()
plugin_reg = PluginRegistry()
run_compare_runs(str(tmp_path / "run1"), str(tmp_path / "run2"), plugin_reg, logger)
run_compare_runs(
str(tmp_path / "run1"),
str(tmp_path / "run2"),
plugin_reg,
logger,
artifact_dir=str(tmp_path),
)
assert "No plugin data found" in caplog.text


def test_run_compare_runs_with_fixture_dirs(caplog, framework_fixtures_path):
def test_run_compare_runs_with_fixture_dirs(caplog, framework_fixtures_path, tmp_path):
"""With two log dirs using fixture (same content), table is produced and no diffs."""
caplog.set_level(logging.INFO)
logger = logging.getLogger()
plugin_reg = PluginRegistry()
base = framework_fixtures_path / "log_dir"
run_compare_runs(str(base), str(base), plugin_reg, logger)
run_compare_runs(str(base), str(base), plugin_reg, logger, artifact_dir=str(tmp_path))
assert "Loading run 1" in caplog.text
assert "Loading run 2" in caplog.text
assert "Plugin" in caplog.text
assert "No differences" in caplog.text or "difference" in caplog.text.lower()


def test_run_compare_runs_sysctl_fixture(caplog, framework_fixtures_path):
def test_run_compare_runs_sysctl_fixture(caplog, framework_fixtures_path, tmp_path):
"""Compare runs using compare_runs_sysctl fixtures; run1 and run2 differ (SysctlPlugin)."""
caplog.set_level(logging.INFO)
logger = logging.getLogger()
base = framework_fixtures_path / "compare_runs_sysctl"
run1 = base / "run1"
run2 = base / "run2"
plugin_reg = PluginRegistry()
run_compare_runs(str(run1), str(run2), plugin_reg, logger)
run_compare_runs(str(run1), str(run2), plugin_reg, logger, artifact_dir=str(tmp_path))
assert "Loading run 1" in caplog.text
assert "Loading run 2" in caplog.text
assert "Sysctl" in caplog.text or "sysctl" in caplog.text
Expand All @@ -167,7 +173,7 @@ def test_run_compare_runs_one_run_missing_plugin(caplog, framework_fixtures_path
run2 = tmp_path / "run2"
run2.mkdir()
# run2 has no collector dirs
run_compare_runs(str(run1), str(run2), plugin_reg, logger)
run_compare_runs(str(run1), str(run2), plugin_reg, logger, artifact_dir=str(tmp_path))
assert "Loading run 1" in caplog.text
assert "Loading run 2" in caplog.text
assert "not found in run 2" in caplog.text or "NOT_RAN" in caplog.text
Expand Down
Loading