Skip to content

Update default_copp_test.go#5132

Merged
AmrNJ merged 3 commits intomainfrom
sys-1.1
Feb 27, 2026
Merged

Update default_copp_test.go#5132
AmrNJ merged 3 commits intomainfrom
sys-1.1

Conversation

@AmrNJ
Copy link
Copy Markdown
Contributor

@AmrNJ AmrNJ commented Feb 25, 2026

Made the following updates to the code

  1. The test is now prefix-agnostic and will work regardless of whether the hardware uses sand, platform, or other vendor-specific naming.
  2. Added parseDroppedValue, a helper that safely handles type switching between string and float64 avoiding crashes.
  3. Removed the checkCPUUtilization calls from inside the 15-second traffic loop which causes the gNMI agent to time out or disconnect during Get requests.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @AmrNJ, 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 significantly enhances the robustness and reliability of the default_copp_test.go by making its counter parsing logic more flexible and resilient to variations in hardware naming conventions. It also addresses a critical issue causing gNMI agent timeouts during traffic generation by optimizing the test's monitoring approach. These changes aim to improve the overall stability and compatibility of the control plane traffic tests.

Highlights

  • Prefix-Agnostic Counter Matching: The getDroppedPktsForCounter function was refactored to be prefix-agnostic, allowing it to match counters regardless of vendor-specific prefixes like 'sand' or 'platform' by attempting exact matches and then suffix matches.
  • Safe Dropped Value Parsing: A new helper function, parseDroppedValue, was introduced to safely handle the parsing of 'dropped' counter values, accommodating both string and float64 types to prevent crashes during type switching.
  • Removed CPU Utilization Checks: Calls to checkCPUUtilization were removed from within the 15-second traffic generation loop to prevent gNMI agent timeouts or disconnections during Get requests, improving test stability.
  • Updated Test Case Counter Prefixes: Test cases were updated to use the 'arista-platform' prefix for control plane traffic counters, aligning with the new prefix-agnostic matching logic.
Changelog
  • feature/system/control_plane_traffic/otg_tests/default_copp_test/default_copp_test.go
    • Refactored getDroppedPktsForCounter to support prefix-agnostic matching for counter names, first by exact match, then by suffix.
    • Introduced parseDroppedValue helper function to safely convert 'dropped' counter values from either string or float64 to float64.
    • Removed checkCPUUtilization calls from the traffic generation loop to prevent gNMI agent timeouts.
    • Increased the post-traffic sleep duration from 10 seconds to 30 seconds to allow more time for traffic stats to complete.
    • Updated all test case counter strings from 'arista-sand-control-plane-traffic-counters' to 'arista-platform-control-plane-traffic-counters'.
Activity
  • The author, AmrNJ, created this pull request to update the default_copp_test.go file with several improvements.
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 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 counter productive. 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

@OpenConfigBot
Copy link
Copy Markdown

OpenConfigBot commented Feb 25, 2026

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 introduces several valuable improvements to the default_copp_test. Making the counter parsing prefix-agnostic and handling different value types for dropped packets significantly increases the test's robustness across different hardware. Removing the CPU utilization check during the traffic loop is a good change to prevent gNMI agent timeouts and improve test stability. I have one suggestion to enhance error logging in the new parseDroppedValue helper function to make test failures easier to diagnose.

Comment on lines +221 to 247
func parseDroppedValue(t *testing.T, counterVal any, keyName string) float64 {
counterMap, ok := counterVal.(map[string]any)
if !ok {
return logAndReturnErroredCount("getDroppedPktsForCounter: Error getting stats for counter: %s", counterName)
return -1
}

dropped, ok := counterMap["dropped"]
if !ok {
return logAndReturnErroredCount("getDroppedPktsForCounter: Error getting stats for counter: %s", counterName)
return -1
}
droppedStr, ok := dropped.(string)
if !ok {
return logAndReturnErroredCount("getDroppedPktsForCounter: Error converting dropped value to string for counter: %s", counterName)

var droppedStr string
switch v := dropped.(type) {
case string:
droppedStr = v
case float64:
return v
default:
return -1
}

packetsDropped, err := strconv.ParseFloat(droppedStr, 64)
if err != nil {
return logAndReturnErroredCount("getDroppedPktsForCounter: Error getting packets dropped for counter: %s", counterName)
return -1
}
return packetsDropped
}
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 helper function parseDroppedValue is a great addition for handling different data types. However, it currently returns -1 on parsing errors without logging any details. This can make debugging test failures difficult as the root cause of the parsing failure (e.g., unexpected data type, missing 'dropped' key) would not be reported. To improve diagnostics, please consider adding error logging using t.Errorf in the failure paths before returning.

func parseDroppedValue(t *testing.T, counterVal any, keyName string) float64 {
	counterMap, ok := counterVal.(map[string]any)
	if !ok {
		t.Errorf("parseDroppedValue: value for key %q is not a map[string]any, but %T", keyName, counterVal)
		return -1
	}

	dropped, ok := counterMap["dropped"]
	if !ok {
		t.Errorf("parseDroppedValue: 'dropped' field not found in map for key %q", keyName)
		return -1
	}

	var droppedStr string
	switch v := dropped.(type) {
	case string:
		droppedStr = v
	case float64:
		return v
	default:
		t.Errorf("parseDroppedValue: 'dropped' field for key %q has unexpected type %T", keyName, v)
		return -1
	}

	packetsDropped, err := strconv.ParseFloat(droppedStr, 64)
	if err != nil {
		t.Errorf("parseDroppedValue: Error converting dropped value %q to float for key %q: %v", droppedStr, keyName, err)
		return -1
	}
	return packetsDropped
}

@AmrNJ AmrNJ marked this pull request as ready for review February 25, 2026 07:28
@AmrNJ AmrNJ requested a review from a team as a code owner February 25, 2026 07:28
@AmrNJ AmrNJ merged commit 4603c6a into main Feb 27, 2026
17 checks passed
@AmrNJ AmrNJ deleted the sys-1.1 branch February 27, 2026 13:00
ampattan pushed a commit to nokia/featureprofiles that referenced this pull request Apr 1, 2026
* Update default_copp_test.go

* Update default_copp_test.go
nsadhasivam pushed a commit to nsadhasivam/featureprofiles that referenced this pull request Apr 6, 2026
* Update default_copp_test.go

* Update default_copp_test.go
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.

4 participants