fix(ssh-console): fall back for Lenovo SOL activation - #2943
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
Summary by CodeRabbit
WalkthroughAdds Lenovo SR650 SOL fallback handling in SSH activation, updates the mock BMC prompt flow for Lenovo, and extends test scaffolding plus unit and integration coverage for the new command sequence. ChangesLenovo SOL fallback activation flow
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
c208254 to
a0fbbbd
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
crates/ssh-console/src/bmc/connection_impl/ssh.rs (2)
504-511: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract the byte-wise command transmission to remove the duplicated send loop.
This block is a verbatim copy of the primary activation send at lines 474-481 (per-byte
data()plus trailing newline and identicalConsoleActivateError::Requestmapping). Consolidating into a small async helper keeps the two paths from drifting.♻️ Proposed helper
async fn send_command_bytewise( ssh_client_channel: &mut Channel<russh::client::Msg>, command: &[u8], ) -> Result<(), ConsoleActivateError> { for byte in command { ssh_client_channel .data([*byte].as_slice()) .await .map_err(|error| ConsoleActivateError::Request { phase: "sending serial activate command to BMC", error, })?; } ssh_client_channel .data(b"\n".as_slice()) .await .map_err(|error| ConsoleActivateError::Request { phase: "sending data to BMC", error, }) }🤖 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/ssh-console/src/bmc/connection_impl/ssh.rs` around lines 504 - 511, The byte-wise SSH command send logic is duplicated between the main activation path and this serial activation block, so extract it into a shared async helper like send_command_bytewise in ssh.rs and reuse it here. Keep the existing per-byte data() behavior, trailing newline send, and ConsoleActivateError::Request mapping, but centralize the loop so both activation paths call the same helper and cannot drift.
658-707: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsolidate these predicate tests into a
value_scenarios!table and add the missing prompt-wait case.Two items here:
should_run_lenovo_sol_fallbackandshould_accept_sol_activation_outputare total operations returningbool, which is precisely the shape the style guide targets withvalue_scenarios!/check_values. The threeshould_accept_sol_activation_outputassertions (tests 1, 3, 4) in particular collapse cleanly into a single labeled table, making each branch one row. As per coding guidelines, "Prefer table-driven tests for any function that maps inputs to outputs, errors, or other observable results."- Issue
#2919's acceptance criteria require a test covering "waiting for the prompt betweenconsole killandconsole start." No test exercises that behaviour — which is consistent with the batched-command concern raised at lines 501-511. Once the prompt-wait question is settled, please add coverage for it.Want me to draft the
value_scenarios!table and the prompt-wait test?🤖 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/ssh-console/src/bmc/connection_impl/ssh.rs` around lines 658 - 707, The predicate tests in the Lenovo SOL activation block should be consolidated into a table-driven `value_scenarios!`/`check_values` style test, since `should_run_lenovo_sol_fallback` and `should_accept_sol_activation_output` are boolean-valued helpers. Move the existing `should_accept_sol_activation_output` cases into labeled rows and keep `should_run_lenovo_sol_fallback` covered in the same style if possible, using the existing function names to locate the assertions. Also add the missing prompt-wait scenario for the Lenovo batched-command flow, specifically covering the case where `console kill` is followed by a prompt before `console start`, so the acceptance behavior is exercised.Source: Coding guidelines
🤖 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/ssh-console/src/bmc/connection_impl/ssh.rs`:
- Around line 501-511: The Lenovo fallback in ssh_client_channel activation is
batching console kill and console start together, which skips the required
re-sync on system> and can fail on SR650 v4. Update the Lenovo fallback path in
the ssh.rs activation flow to send console kill first, wait for the system>
prompt to be observed, then send console start as a separate prompt-synced
request. Also tighten the lenovo_fallback_sent success handling so it only
treats activation as successful when the expected prompt/state is reached and
the Lenovo failure marker is not present in the response.
---
Nitpick comments:
In `@crates/ssh-console/src/bmc/connection_impl/ssh.rs`:
- Around line 504-511: The byte-wise SSH command send logic is duplicated
between the main activation path and this serial activation block, so extract it
into a shared async helper like send_command_bytewise in ssh.rs and reuse it
here. Keep the existing per-byte data() behavior, trailing newline send, and
ConsoleActivateError::Request mapping, but centralize the loop so both
activation paths call the same helper and cannot drift.
- Around line 658-707: The predicate tests in the Lenovo SOL activation block
should be consolidated into a table-driven `value_scenarios!`/`check_values`
style test, since `should_run_lenovo_sol_fallback` and
`should_accept_sol_activation_output` are boolean-valued helpers. Move the
existing `should_accept_sol_activation_output` cases into labeled rows and keep
`should_run_lenovo_sol_fallback` covered in the same style if possible, using
the existing function names to locate the assertions. Also add the missing
prompt-wait scenario for the Lenovo batched-command flow, specifically covering
the case where `console kill` is followed by a prompt before `console start`, so
the acceptance behavior is exercised.
🪄 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: 8077fa10-a8fb-4b4c-ae3e-d4b44c6f0b07
📒 Files selected for processing (1)
crates/ssh-console/src/bmc/connection_impl/ssh.rs
🔍 Container Scan Summary
Per-CVE detail lives in the per-service |
There was a problem hiding this comment.
Ideally we should be passing metadata about the model number in the BmcMetaDataGetResponse that lets ssh-console get this right the first time, but until that happens this is probably ok.
I think we ought to make the fallback logic more general-purpose though, with the lenovo-specific behavior placed in SshVendor.
Also, could you add an integration test to assert on this behavior? The tests in crates/ssh-console/tests/main.rs are at the level where they should be able to mock this. run_baseline_test_environment in crates/ssh-console/tests/util/mod.rs configures a mock SSH server from machine-a-tron with behavior from the PromptBehavior enum which currently has Dell and Dpu variants... you could create a third for LenovoSr650, and modify the data handler to check for that variant and override the behavior accordingly.
a0fbbbd to
92f0fb5
Compare
92f0fb5 to
e4ed22a
Compare
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/machine-a-tron/src/mock_ssh_server.rs`:
- Around line 335-344: The Lenovo mock in mock_ssh_server.rs currently accepts
PromptBehavior::LenovoSr650 "console start" directly from ConsoleState::Bmc, so
the prompt-wait behavior is not actually enforced. Add an intermediate Lenovo
fallback state in the console state machine inside the SSH command handling so
"console start" is only accepted after the "console kill" response has been
emitted and the prompt has returned, and keep the state transition logic in the
console kill/start branches aligned with that flow. Update or add a focused test
around the LenovoSr650 path to verify that "console start" is rejected until the
prompt-return step has completed.
In `@crates/ssh-console/src/bmc/vendor.rs`:
- Around line 545-613: Add a positive Lenovo success path to the focused tests
so the SR650 fallback behavior is not the only Lenovo coverage. Update
fallback_serial_activate_commands_if_needed_detects_lenovo_failure and
should_accept_sol_activation_output_handles_fallback_cases to include a Lenovo
case where the primary serial activation output is successful and no fallback is
triggered, using SshBmcVendor::Lenovo and the existing helper methods like
serial_activate_command, bmc_prompt,
fallback_serial_activate_commands_if_needed, and
should_accept_sol_activation_output to keep the assertions aligned with the
current test structure.
🪄 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: be89e23b-ca38-4cd0-83e7-6b27116dfe31
📒 Files selected for processing (5)
crates/machine-a-tron/src/mock_ssh_server.rscrates/ssh-console/src/bmc/connection_impl/ssh.rscrates/ssh-console/src/bmc/vendor.rscrates/ssh-console/tests/main.rscrates/ssh-console/tests/util/mod.rs
🚧 Files skipped from review as they are similar to previous changes (1)
- crates/ssh-console/src/bmc/connection_impl/ssh.rs
kensimon
left a comment
There was a problem hiding this comment.
Thanks for the updates! Looks good. ![]()
Summary
extraneous argumentsresponse and fall back toconsole kill/console startFixes #2919
Test plan
Note: William ran the cargo tests on Linux. Local macOS test execution is blocked by existing Linux-specific
io_util.rstermios compile errors.