fix(machine-a-tron): validate ipmi_sim before startup#3753
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Summary by CodeRabbit
WalkthroughIPMI simulation now validates that its executable is available and runnable in ChangesIPMI executable validation
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/bmc-mock/src/ipmi_sim.rs`:
- Around line 76-79: Update the #[error] message for ExecutableUnavailable to
begin with lowercase wording, changing the initial “IPMI” capitalization while
preserving the existing message content and formatting.
- Around line 98-116: Update validate_executable_in_path to resolve and return
the executable’s absolute PathBuf rather than only validating availability;
preserve the existing executable-file and permission checks, and return the
unavailable error when no candidate matches. Update the command-launching flow
to pass that resolved path to Command::new before applying the child
current_dir, and add a regression test covering a relative PATH entry.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: b32abf84-ae94-4349-86ff-89afb725f625
📒 Files selected for processing (2)
crates/bmc-mock/src/ipmi_sim.rscrates/machine-a-tron/src/config.rs
| #[error( | ||
| "IPMI simulation requires {executable}, but it was not found or is not executable in PATH" | ||
| )] | ||
| ExecutableUnavailable { executable: &'static str }, |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Lowercase the new error message.
lint-error-messages requires normal error wording to start lowercase.
- "IPMI simulation requires {executable}, but it was not found or is not executable in PATH"
+ "ipmi simulation requires {executable}, but it was not found or is not executable in PATH"Based on learnings, normal Rust #[error(...)] wording must be lowercased.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| #[error( | |
| "IPMI simulation requires {executable}, but it was not found or is not executable in PATH" | |
| )] | |
| ExecutableUnavailable { executable: &'static str }, | |
| #[error( | |
| "ipmi simulation requires {executable}, but it was not found or is not executable in PATH" | |
| )] | |
| ExecutableUnavailable { executable: &'static str }, |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@crates/bmc-mock/src/ipmi_sim.rs` around lines 76 - 79, Update the #[error]
message for ExecutableUnavailable to begin with lowercase wording, changing the
initial “IPMI” capitalization while preserving the existing message content and
formatting.
Source: Learnings
| fn validate_executable_in_path(path: Option<&OsStr>) -> Result<(), Error> { | ||
| let executable_available = path | ||
| .into_iter() | ||
| .flat_map(std::env::split_paths) | ||
| .map(|directory| directory.join(IPMI_SIM_EXECUTABLE)) | ||
| .any(|candidate| { | ||
| candidate.metadata().is_ok_and(|metadata| { | ||
| metadata.is_file() && metadata.permissions().mode() & 0o111 != 0 | ||
| }) | ||
| }); | ||
|
|
||
| if executable_available { | ||
| Ok(()) | ||
| } else { | ||
| Err(Error::ExecutableUnavailable { | ||
| executable: IPMI_SIM_EXECUTABLE, | ||
| }) | ||
| } | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
ast-grep outline crates/bmc-mock/src/ipmi_sim.rs --items all
sed -n '94,116p;176,176p;479,508p' crates/bmc-mock/src/ipmi_sim.rs
workdir="$(mktemp -d)"
trap 'rm -rf "$workdir"' EXIT
mkdir -p "$workdir/bin" "$workdir/child"
printf '#!/bin/sh\nexit 0\n' > "$workdir/bin/ipmi_sim"
chmod 700 "$workdir/bin/ipmi_sim"
(
cd "$workdir"
PATH='bin' command -v ipmi_sim >/dev/null
cd child
! PATH='bin' command -v ipmi_sim >/dev/null
)Repository: NVIDIA/infra-controller
Length of output: 5120
🏁 Script executed:
#!/bin/bash
set -euo pipefail
sed -n '143,240p' crates/bmc-mock/src/ipmi_sim.rs
python3 - <<'PY'
import os, tempfile, subprocess, textwrap, shutil, stat
workdir = tempfile.mkdtemp()
try:
os.makedirs(os.path.join(workdir, "bin"))
os.makedirs(os.path.join(workdir, "child"))
exe = os.path.join(workdir, "bin", "ipmi_sim")
with open(exe, "w") as f:
f.write("#!/bin/sh\nexit 0\n")
os.chmod(exe, 0o700)
for cwd in [workdir, os.path.join(workdir, "child")]:
p = subprocess.run(
["sh", "-c", "PATH='bin' command -v ipmi_sim"],
cwd=cwd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)
print("cwd=", cwd)
print("rc=", p.returncode)
print("stdout=", p.stdout.strip())
print("stderr=", p.stderr.strip())
finally:
shutil.rmtree(workdir)
PYRepository: NVIDIA/infra-controller
Length of output: 3784
Resolve the executable before changing the child CWD. A relative PATH entry can pass the lookup here, but current_dir(temp_dir.path()) makes Command::new(IPMI_SIM_EXECUTABLE) search from a different directory and fail to launch. Return the resolved absolute PathBuf from the helper, pass it to Command::new, and add a regression test for a relative PATH entry.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@crates/bmc-mock/src/ipmi_sim.rs` around lines 98 - 116, Update
validate_executable_in_path to resolve and return the executable’s absolute
PathBuf rather than only validating availability; preserve the existing
executable-file and permission checks, and return the unavailable error when no
candidate matches. Update the command-launching flow to pass that resolved path
to Command::new before applying the child current_dir, and add a regression test
covering a relative PATH entry.
Source: Path instructions
Signed-off-by: Dmitry Porokh <dporokh@nvidia.com>
f056268 to
5613074
Compare
|
🌿 Preview your docs: https://nvidia-preview-pull-request-3753.docs.buildwithfern.com/infra-controller |
Machine-a-tron currently discovers a missing
ipmi_simexecutable only when constructing an IPMI-capable BMC. At that point startup continues retrying BMC setup, which obscures the configuration problem and can repeatedly replace partially registered mock BMC state.Fail configuration validation immediately when IPMI simulation is enabled but
ipmi_simis missing or not executable inPATH.The executable name and availability check live in the IPMI simulator module, which also uses the same constant when launching the process. This keeps preflight validation aligned with runtime behavior.
Related issues
Follow-up to #3378
Type of Change
Breaking Changes
Testing
Additional Notes