Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable unit tests and code coverage for telemetry.go #186

Merged
merged 19 commits into from
Feb 8, 2024

Conversation

zbud-msft
Copy link
Contributor

@zbud-msft zbud-msft commented Feb 1, 2024

Why I did it

telemetry.go currently is bypassing UT and diff code coverage checks.

What this PR is doing:

  1. No longer uses a global config in order to make flag parsing and other goroutine functions easier to test by passing local config. Instead uses a local config struct TelemetryConfig for parsing and is created within setupFlags which parses flags passed by cmd line arguments.
  2. Logic for creating gnmi server and calling Serve() is now done inside of a goroutine such that it allows the main thread to support concurrent tasks in the future.
  3. Call server stop after Serve() returns
  4. MD5 checksum is replaced with SHA512 checksum as per semgrep findings. MD5 checksum is no longer considered secure as "MD5 hash algorithm is considered insecure. MD5 is not collision resistant and is therefore not suitable as a cryptographic signature."
  5. Enable UT and code coverage for telemetry.go

How I did it

Removed global config, changed md5 checksum semgrep issue, enabled UT and CC checks for telemetry.go

How to verify it

Pipeline/UT

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111

Description for the changelog

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

@@ -209,3 +210,19 @@ func getflag(name string) string {
})
return val
}

func validateSHA512(file string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function performs two tasks: it computes the checksum of a given file using the SHA-512 algorithm and it logs a message to the system logger with the file name and the checksum value. Therefore, the function name validateSHA512 is misleading, as it implies that the function only validate checksum.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

@ganglyu
Copy link
Contributor

ganglyu commented Feb 2, 2024

How long does it take to calculate SHA512 checksum? Much slower?
It seems that our pr checker does not cover this file, would you please add unit test and check coverage?

@zbud-msft zbud-msft changed the title Log certificate SHA512 checksum instead of MD5 checksum Enable unit tests and code coverage for telemetry.go Feb 5, 2024
@zbud-msft
Copy link
Contributor Author

How long does it take to calculate SHA512 checksum? Much slower? It seems that our pr checker does not cover this file, would you please add unit test and check coverage?

Added UT and code coverage for telemetry.go. Since we are computing SHA512 checksum of a cert file (~4KB for private key), we can expect it to take only a couple of MS.

@sonic-net sonic-net deleted a comment from azure-pipelines bot Feb 6, 2024
@sonic-net sonic-net deleted a comment from mssonicbld Feb 6, 2024
@zbud-msft
Copy link
Contributor Author

/azpw run

@mssonicbld
Copy link

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@zbud-msft
Copy link
Contributor Author

/azpw run

@mssonicbld
Copy link

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@zbud-msft
Copy link
Contributor Author

/azpw run

@mssonicbld
Copy link

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

ganglyu
ganglyu previously approved these changes Feb 7, 2024
@zbud-msft
Copy link
Contributor Author

/azpw run

@mssonicbld
Copy link

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@zbud-msft zbud-msft merged commit d8d15c7 into sonic-net:master Feb 8, 2024
5 checks passed
zbud-msft added a commit to zbud-msft/sonic-gnmi that referenced this pull request Apr 10, 2024
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.

3 participants