Repository navigation
[action] [PR:28530] [bmc_utils]: Fix bmc_log_zgrep self-matching Ansible command-invocation syslog lines - #1485
Merged
Conversation
…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>
Collaborator
Author
|
Original PR: sonic-net/sonic-mgmt#28530 |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Collaborator
Author
|
/azp run |
1 similar comment
Collaborator
Author
|
/azp run |
|
Azure Pipelines: 1 pipeline(s) were filtered out due to trigger conditions. |
2 of 13 tasks
|
Azure Pipelines: 1 pipeline(s) were filtered out due to trigger conditions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of PR
Summary:
Fixes a self-match bug in
bmc_log_zgrep(tests/common/platform/bmc_utils.py).bmc_log_zgrepruns itszgrepviaduthost.shell(...). Ansible logs every shell/command module invocation to syslog, echoing the full command line (including the search pattern) in a line like:Because that line contains the search pattern verbatim,
zgrepmatches 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. Intest_thermalctld_chassis_thermal_monitoringthis defeats theif not mirror_init_log: pytest.skip(...)guard, so the test proceeds, finds 0 realTEMPERATURE_INFO|*keys in STATE_DB, and FAILS instead of SKIPPING.Fixes # (issue)
Type of change
Back port request
Approach
What is the motivation for this PR?
Prevent
bmc_log_zgrepfrom 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, thezgrepoutput is now piped throughgrep -vE 'ansible-ansible\.legacy\.(command|shell)'beforetail, 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 (andgrep -vreturns rc=1 when it legitimately filters away all lines), the previousif r.get('rc') == 0gate 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=Trueis 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