Skip to content

[action] [PR:28530] [bmc_utils]: Fix bmc_log_zgrep self-matching Ansible command-invocation syslog lines - #1485

Merged
mssonicbld merged 1 commit into
Azure:202608from
mssonicbld:cherry/msft-202608/28530
Oct 14, 2026
Merged

mssonicbld merged 1 commit into
Azure:202608from
mssonicbld:cherry/msft-202608/28530

Conversation

@mssonicbld

Copy link
Copy Markdown
Collaborator

Description of PR

Summary:
Fixes a self-match bug in bmc_log_zgrep (tests/common/platform/bmc_utils.py).

bmc_log_zgrep runs its zgrep via duthost.shell(...). Ansible logs every shell/command module invocation to syslog, echoing the full command line (including the search pattern) in a line like:

<date> sonic INFO python3.13[725497]: ansible-ansible.legacy.command Invoked with _raw_params=zgrep -hI -E 'Mirroring TEMPERATURE_INFO to BMC STATE_DB' /var/log/syslog* ...

Because that line contains the search pattern verbatim, zgrep matches its OWN command-invocation syslog entry (a self-match), so the function returns a non-empty string even when the real daemon log line is absent. In test_thermalctld_chassis_thermal_monitoring this defeats the if not mirror_init_log: pytest.skip(...) guard, so the test proceeds, finds 0 real TEMPERATURE_INFO|* keys in STATE_DB, and FAILS instead of SKIPPING.

Fixes # (issue)

Type of change

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

Back port request

  • 202205
  • 202305
  • 202311
  • 202405
  • 202411
  • 202505
  • 202511
  • 202608

Approach

What is the motivation for this PR?

Prevent bmc_log_zgrep from matching Ansible's own command-invocation syslog line, which produced false-positive non-empty results and caused tests relying on the empty-result skip guard to fail incorrectly.

How did you do it?

In bmc_log_zgrep, the zgrep output is now piped through grep -vE 'ansible-ansible\.legacy\.(command|shell)' before tail, dropping Ansible's command/shell invocation lines so the function cannot self-match.

Because the pipeline's rc is now grep -v's / tail's rc (and grep -v returns rc=1 when it legitimately filters away all lines), the previous if r.get('rc') == 0 gate would wrongly discard valid empty results. The return logic now simply returns the stripped stdout regardless of rc (empty stdout already means "no match"). module_ignore_errors=True is retained, and the docstring documents the filtering.

How did you verify/test it?

  • python -c "import ast; ast.parse(open('tests/common/platform/bmc_utils.py').read())" — parses OK.
  • python -m flake8 --max-line-length=120 tests/common/platform/bmc_utils.py — no findings.

Any platform specific information?

No. This is a SmartSwitch/BMC test utility change; no platform-specific behavior.

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

N/A — not a new test case.

Documentation

N/A — updated the function docstring to note that Ansible's command-invocation syslog lines are filtered out to avoid self-matching.

Signed-off-by: Sonic Build Admin sonicbld@microsoft.com

…on syslog lines

### Description of PR
Summary:
Fixes a self-match bug in `bmc_log_zgrep` (`tests/common/platform/bmc_utils.py`).

`bmc_log_zgrep` runs its `zgrep` via `duthost.shell(...)`. Ansible logs every shell/command module invocation to syslog, echoing the full command line (including the search pattern) in a line like:

```
<date> sonic INFO python3.13[725497]: ansible-ansible.legacy.command Invoked with _raw_params=zgrep -hI -E 'Mirroring TEMPERATURE_INFO to BMC STATE_DB' /var/log/syslog* ...
```

Because that line contains the search pattern verbatim, `zgrep` matches its OWN command-invocation syslog entry (a self-match), so the function returns a non-empty string even when the real daemon log line is absent. In `test_thermalctld_chassis_thermal_monitoring` this defeats the `if not mirror_init_log: pytest.skip(...)` guard, so the test proceeds, finds 0 real `TEMPERATURE_INFO|*` keys in STATE_DB, and FAILS instead of SKIPPING.

Fixes # (issue)

### Type of change
- [x] Bug fix
- [ ] Testbed and Framework(new/improvement)
- [ ] New Test case
    - [ ] Skipped for non-supported platforms
- [ ] Test case improvement

### Back port request
- [ ] 202205
- [ ] 202305
- [ ] 202311
- [ ] 202405
- [ ] 202411
- [ ] 202505
- [ ] 202511
- [x] 202608

### Approach
#### What is the motivation for this PR?
Prevent `bmc_log_zgrep` from matching Ansible's own command-invocation syslog line, which produced false-positive non-empty results and caused tests relying on the empty-result skip guard to fail incorrectly.

#### How did you do it?
In `bmc_log_zgrep`, the `zgrep` output is now piped through `grep -vE 'ansible-ansible\.legacy\.(command|shell)'` before `tail`, dropping Ansible's command/shell invocation lines so the function cannot self-match.

Because the pipeline's rc is now `grep -v`'s / `tail`'s rc (and `grep -v` returns rc=1 when it legitimately filters away all lines), the previous `if r.get('rc') == 0` gate would wrongly discard valid empty results. The return logic now simply returns the stripped stdout regardless of rc (empty stdout already means "no match"). `module_ignore_errors=True` is retained, and the docstring documents the filtering.

#### How did you verify/test it?
- `python -c "import ast; ast.parse(open('tests/common/platform/bmc_utils.py').read())"` — parses OK.
- `python -m flake8 --max-line-length=120 tests/common/platform/bmc_utils.py` — no findings.

#### Any platform specific information?
No. This is a SmartSwitch/BMC test utility change; no platform-specific behavior.

#### Supported testbed topology if it's a new test case?
N/A — not a new test case.

### Documentation
N/A — updated the function docstring to note that Ansible's command-invocation syslog lines are filtered out to avoid self-matching.

Signed-off-by: Sonic Build Admin <sonicbld@microsoft.com>
@mssonicbld

Copy link
Copy Markdown
Collaborator Author

Original PR: sonic-net/sonic-mgmt#28530

@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 Author

/azp run

1 similar comment
@mssonicbld

Copy link
Copy Markdown
Collaborator Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
1 pipeline(s) were filtered out due to trigger conditions.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
1 pipeline(s) were filtered out due to trigger conditions.

@mssonicbld
mssonicbld merged commit 56391be into Azure:202608 Oct 14, 2026
5 checks passed
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.

1 participant