Skip to content

Fix post-reboot Ansible readiness check - #26636

Open
LinJin23 wants to merge 5 commits into
sonic-net:masterfrom
LinJin23:fix-reboot-readiness
Open

LinJin23 wants to merge 5 commits into
sonic-net:masterfrom
LinJin23:fix-reboot-readiness

Conversation

@LinJin23

@LinJin23 LinJin23 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Description of PR

Summary:

Wait for the DUT to successfully execute an Ansible command after post-reboot SSH startup before reading its uptime.

Fixes #

Type of change

  • Bug fix
  • Testbed and Framework(new/improvement)
  • New Test case
    • Skipped for non-supported platforms
  • Test case improvement

Back port request

  • 202311
  • 202405
  • 202411
  • 202505
  • 202511
  • 202512
  • 202605

Tracking issue/work item for backport/cherry-pick request (GitHub issue or Microsoft ADO): N/A
Failure type: Flaky post-reboot readiness issue

Tested branch

  • master
  • 202311
  • 202405
  • 202411
  • 202505
  • 202511
  • 202512
  • 202605
  • N/A

Test result

Approach

What is the motivation for this PR?

SSH can become available before the DUT is ready to execute Ansible commands through privilege escalation, causing a flaky uptime -s failure after reboot.

How did you do it?

Added a bounded readiness check that waits for a lightweight Ansible command to succeed before reading the DUT uptime.

How did you verify/test it?

Ran the targeted pre-commit checks for tests/platform_tests/test_link_down.py. The test also passed 10 out of 10 runs across three physical Arista T0 testbeds using SONiC.20260510.08.

Any platform specific information?

No.

Supported testbed topology if it's a new test case?

Not applicable.

Documentation

Not applicable.

Wait for a lightweight Ansible command to succeed after SSH startup before reading DUT uptime.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 0d08e59d-63c7-4189-9be9-29045dd91d20
Signed-off-by: Lin Jin <linjin@microsoft.com>
Copilot AI lite review requested due to automatic review settings July 28, 2026 23:33
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves the robustness of the test_link_status_on_host_reboot workflow by adding a bounded post-reboot readiness check to ensure the DUT can successfully execute an Ansible command (including privilege escalation) before reading uptime, reducing flakiness where SSH is up but Ansible/become isn’t fully ready yet.

Changes:

  • Import wait_until and introduce a wait_for_dut_ready() helper that polls a lightweight Ansible command (true) until it succeeds.
  • Add bounded timeout/interval constants for the new post-reboot readiness polling.
  • Invoke the readiness check immediately after wait_for_startup() and before dut.get_up_time().

@LinJin23
LinJin23 marked this pull request as ready for review July 28, 2026 23:36
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@mssonicbld

Copy link
Copy Markdown
Collaborator

This PR has backport request label(s) for branch(es): 202605, but is missing required test information. Please make sure you tick the tested branch(es) in the Tested branch section and provide test evidence (e.g., 202605: <test result>) in the Test result section as well in your PR description.

---Powered by SONiC BuildBot

Comment thread tests/platform_tests/test_link_down.py Outdated
return duts_and_ports


def wait_for_dut_ready(dut):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use an existing library function for this? eg. "wait_critical_process" ?
the reboot tests (eg. test_reboot.py / reboot_utils/py / process_utils.py) should already have infrastructure for this. We shouldnt reinvent the wheel in this test

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait_critical_processes()  waits for full SONiC process readiness, which is more than needed here. This check only verifies that the Ansible/become command path is ready before calling  get_up_time() . I could not find an existing lightweight helper for this purpose.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait for startup should do this - is it not sufficient? That function is used for many tests for ssh readyness - it should be robust

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would opt to fix that function instead if its not doing what it should be.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I'll update the code accordingly.

@LinJin23

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@mssonicbld mssonicbld added the Tested for 202605 branch Tested for 202605 branch label Jul 29, 2026
@mssonicbld

Copy link
Copy Markdown
Collaborator

The Tested branch section has been ticked and Test result is provided for branch(es): 202605. Added label(s): Tested for 202605 Branch.

---Powered by SONiC BuildBot

Signed-off-by: Lin Jin <linjin@microsoft.com>
Copilot AI review requested due to automatic review settings August 4, 2026 13:20
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Suppressed comments (2)

tests/common/reboot.py:251

  • The Ansible-readiness wait currently uses a fixed ANSIBLE_READY_TIMEOUT regardless of how much of timeout was already spent waiting for SSH. If timeout is meant as the overall startup budget, compute an ansible_timeout from the remaining time to avoid waiting longer than intended.
    logger.info('waiting for Ansible commands to become ready on {}'.format(hostname))

    def is_ansible_ready():
        result = duthost.command("true", module_ignore_errors=True)
        return result.is_successful

    pytest_assert(
        wait_until(ANSIBLE_READY_TIMEOUT, ANSIBLE_READY_INTERVAL, 0, is_ansible_ready),
        "DUT {} did not become ready for Ansible commands after SSH startup".format(hostname),
    )

tests/common/reboot.py:212

  • To keep timeout acting as an end-to-end bound for wait_for_startup(), it helps to record a function-level start timestamp before the SSH polling begins so the subsequent Ansible-readiness wait can consume only the remaining budget.

This issue also appears on line 242 of the same file.

def wait_for_startup(duthost, localhost, delay, timeout, port=SONIC_SSH_PORT,
                     wait_for_ansible=True):

@LinJin23

LinJin23 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

judyjoseph
judyjoseph previously approved these changes Aug 4, 2026
@judyjoseph

Copy link
Copy Markdown
Contributor

@StormLiangMS could you please help review/merge

@StormLiangMS

Copy link
Copy Markdown
Collaborator

@LinJin23 — ❌ I found one blocking cleanup issue in the current head (6ec2c1e4).

In tests/common/reboot.py, the new pytest_assert(...) readiness timeout raises pytest Failed, which derives from BaseException, not Exception. Therefore it bypasses reboot()'s existing except Exception handler around wait_for_startup(). That handler is responsible for disconnecting the console session and terminating the thread pool, so an Ansible-readiness timeout can leave both resources active.

Please either raise a normal Exception here, consistent with the SSH timeout failures earlier in wait_for_startup(), or guarantee cleanup with finally/explicit handling of pytest.fail.Exception.

The shared-helper placement and command("true") probe otherwise look sound. Non-blocking: please also confirm that the fixed 90-second readiness limit is sufficient for slow physical chassis/platform recovery paths, since this now applies by default to all callers.

Signed-off-by: Lin Jin <linjin@microsoft.com>
@LinJin23
LinJin23 dismissed stale reviews from liamkearney-msft and judyjoseph via 4591ce8 September 1, 2026 07:26
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Comment thread tests/common/reboot.py
duthost.meta("clear_facts")

if not wait_for_ansible:
return
Comment thread tests/common/reboot.py
if not wait_for_ansible:
return

logger.info('waiting for Ansible commands to become ready on {}'.format(hostname))
Comment thread tests/common/reboot.py
return

logger.info('waiting for Ansible commands to become ready on {}'.format(hostname))

Comment thread tests/common/reboot.py
logger.info('waiting for Ansible commands to become ready on {}'.format(hostname))

def is_ansible_ready():
result = duthost.command("true", module_ignore_errors=True)
Signed-off-by: Lin Jin <linjin@microsoft.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Signed-off-by: Lin Jin <linjin@microsoft.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants