Skip to content

Fix phc2sys source failover test to handle multiple log matches#231

Closed
gtannous-spec wants to merge 1 commit into
k8snetworkplumbingwg:mainfrom
gtannous-spec:fix-phc2sys-ha-multi-select-assertion
Closed

Fix phc2sys source failover test to handle multiple log matches#231
gtannous-spec wants to merge 1 commit into
k8snetworkplumbingwg:mainfrom
gtannous-spec:fix-phc2sys-ha-multi-select-assertion

Conversation

@gtannous-spec

Copy link
Copy Markdown
Contributor

Summary

The phc2sys source failover test assumed exactly one log match for the
source interface pattern, causing false failures when phc2sys logs
multiple source selection lines (e.g., during restarts or re-syncs).

  • Changed assertion from == 1 to >= 1 to accept multiple matches
  • Use the last match instead of the first, which reflects the most
    recent source interface selection
  • Added logging for selected interface names to aid debugging

@gtannous-spec
gtannous-spec force-pushed the fix-phc2sys-ha-multi-select-assertion branch from 7582cff to 83a1adb Compare May 13, 2026 12:24

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request updates the phc2sys log parsing logic in test/conformance/serial/ptp.go to accept multiple log matches and select the most recent one instead of the first. It also adds additional logging for the selected interface. The reviewer suggests refactoring the duplicated interface extraction logic into a helper function to improve maintainability.

Comment on lines +1036 to +1039
lastMatch := logMatches[len(logMatches)-1]
logrus.Infof("phc2sys log matching line: %v", lastMatch[0])
selectedInterface = lastMatch[1]
logrus.Infof("selected interface: %s", selectedInterface)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The logic for extracting the interface from the phc2sys logs is duplicated in this file. Consider refactoring this into a helper function to improve maintainability and reduce code duplication.

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.

Optional: Will modify that after we validate all ci-tests pass.

@sebsoto

sebsoto commented May 13, 2026

Copy link
Copy Markdown
Collaborator

/assign @nocturnalastro

phc2sysLogPattern, false, pkg.TimeoutIn1Minute)
Expect(err).NotTo(HaveOccurred())
Expect(len(logMatches)).To(BeNumerically("==", 1), "Could not identify which interface phc2sys is using")
Expect(len(logMatches)).To(BeNumerically(">=", 1), "Could not identify which interface phc2sys is using")

@nocturnalastro nocturnalastro May 13, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why should we see more than 1?

Last time it was more than 1 we had a bug that was duplicating lines.

The other reason would be it is switching master then switching again which would also be odd.

Do you have an example of this happening?

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.

This test is causing this #223 PR to fail on this test (after enabling PTP authentication), I added there a CI negative test to verify that slaves don't sync to master in case we have keys mismatch.

while we change SPP from 1 to 0 on the GM config and then from 0 to 1 each change causes the daemon to restart the ptp4l/phc2sys processes inside the same pod.
phc2sys re-selects its interface each time and logs "selecting". By the time the DualNICBCHA test ("DualNICBCHA phc2sys switches to secondary ptp4l when primary interface fails") runs, the pod has 3 accumulated entries: 1 from initial startup + 1 from spp change + 1 from spp restore.

I was not tracking the bug you talked about following the fact that "was duplicating lines", if this could lead to another issue then I can try a different approach to "get rid" of the 3 log entries.

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.

I fixed that PR, now all tests pass. I guess problem was replacing the pod before it was in LOCKED state.
which leads the operator to reconcile causing another process to restart so pod ends up selecting multiple entries.

Will close this one.

@gtannous-spec
gtannous-spec marked this pull request as draft May 13, 2026 22:25
@gtannous-spec

Copy link
Copy Markdown
Contributor Author

Flaky Ci-test failures were fixed for PR#223 ,
will close this PR !

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.

3 participants