Skip to content

Refactor code and add txPowerReadingError value#5428

Open
priyaranjannanda wants to merge 1 commit into
openconfig:mainfrom
priyaranjannanda:TRANSCEIVER-4.1_1
Open

Refactor code and add txPowerReadingError value#5428
priyaranjannanda wants to merge 1 commit into
openconfig:mainfrom
priyaranjannanda:TRANSCEIVER-4.1_1

Conversation

@priyaranjannanda
Copy link
Copy Markdown
Contributor

The changes include

  • Refactoring the code for validation check
  • Adding txPowerReadingError value for consistent validation
  • Updated the constant values for inactive optical channel power

@priyaranjannanda priyaranjannanda requested a review from a team as a code owner May 6, 2026 03:02
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on refactoring the transceiver power validation tests to improve code quality and consistency. By centralizing validation logic and standardizing constant values, the changes ensure more robust testing of optical channel states and power readings.

Highlights

  • Code Refactoring: Consolidated power validation logic by introducing a helper function to handle nil checks and streamline validation calls.
  • Constant Updates: Updated inactive optical channel power constants to 0.0 and increased the txPowerReadingError threshold to 3.
  • Test Lifecycle Improvement: Refactored the interface lifecycle testing logic into a reusable function to improve readability and maintainability.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

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

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 refactors the zr_input_output_power_test.go file to improve modularity and readability by introducing helper functions for interface lifecycle management and consolidating power validation logic. Feedback from the reviewer highlights concerns regarding the increased power thresholds and error tolerances, which may be too permissive for accurate telemetry validation. Suggestions were also provided to mitigate potential test flakiness during state transitions and to enhance the clarity of error messages.

Comment on lines +19 to +21
inactiveOCHRxPower = 0.0
inactiveOCHTxPower = 0.0
inactiveTransceiverRxPower = 0.0
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.

medium

Setting the inactive power thresholds to 0.0 dBm is extremely permissive. In optical networking, 0.0 dBm (1mW) is a significant amount of power and often falls within the normal operating range of an active transceiver. Typically, values like -30.0 or -40.0 are used to ensure the laser is truly off or no signal is present. Using 0.0 might fail to detect cases where a port is reported as DOWN but is still emitting or receiving significant power.

inactiveTransceiverRxPower = 0.0
rxPowerReadingError = 3
txPowerReadingError = 0.5
txPowerReadingError = 3
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.

medium

Increasing txPowerReadingError to 3 dB significantly loosens the validation tolerance. A 3 dB difference represents a factor of 2 in power levels. Most ZR specifications and related tests in this repository use a much tighter tolerance, typically between 0.5 and 1.0 dB, to ensure accurate telemetry reporting.

Comment on lines +123 to 125
if operStatus != expectedStatus {
t.Errorf("Invalid %v operStatus value: want %v, got %v", p.Name(), expectedStatus, operStatus)
}
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.

medium

This check is likely to cause test flakiness. The samplestream starts collecting data before the interface is toggled, and gnmi.Await waits for the status to change. Consequently, the stream will contain samples from the transition period where the operStatus is still the old value. Since validateSampleStream already verifies that power levels are correct for the status reported in each sample, failing the test here for status mismatches is unnecessary and prone to error.

Suggested change
if operStatus != expectedStatus {
t.Errorf("Invalid %v operStatus value: want %v, got %v", p.Name(), expectedStatus, operStatus)
}
if operStatus != expectedStatus {
continue
}

}

if !isValid {
t.Errorf("Invalid %v sample when %v is %v --> min : %v, max : %v, avg : %v, instant : %v", pm, portName, operStatus, min, max, avg, instant)
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.

medium

The error message would be more useful for debugging if it included the expected validation bounds (minAllowed, maxAllowed, or inactiveValue) that caused the failure.

Suggested change
t.Errorf("Invalid %v sample when %v is %v --> min : %v, max : %v, avg : %v, instant : %v", pm, portName, operStatus, min, max, avg, instant)
t.Errorf("Invalid %v sample when %v is %v --> min: %v, max: %v, avg: %v, instant: %v (expected range [%v, %v] or inactive <= %v)", pm, portName, operStatus, min, max, avg, instant, minAllowed, maxAllowed, inactiveValue)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants