-
Notifications
You must be signed in to change notification settings - Fork 207
Adding certz baseline test #5286
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
Open
ASHNA-AGGARWAL-KEYSIGHT
wants to merge
6
commits into
openconfig:main
Choose a base branch
from
open-traffic-generator:fpt_otg_CERTZ
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+187
−0
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
97f46de
Adding certz baseline test
ASHNA-AGGARWAL-KEYSIGHT 97d5ca2
Delete feature/gnsi/certz/tests/baseline/README.md
ASHNA-AGGARWAL-KEYSIGHT a33ed25
Merge branch 'main' into fpt_otg_CERTZ
ASHNA-AGGARWAL-KEYSIGHT c67cd75
Update certz_baseline_test
ASHNA-AGGARWAL-KEYSIGHT 50bed85
addressed review comments
ASHNA-AGGARWAL-KEYSIGHT 80e3ab8
Merge branch 'main' into fpt_otg_CERTZ
ASHNA-AGGARWAL-KEYSIGHT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
180 changes: 180 additions & 0 deletions
180
feature/gnsi/certz/tests/baseline/certz_baseline_test.go
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| package certzbaseline_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "slices" | ||
| "testing" | ||
| "time" | ||
|
|
||
| setupService "github.com/openconfig/featureprofiles/feature/gnsi/certz/tests/internal/setup_service" | ||
| "github.com/openconfig/featureprofiles/internal/fptest" | ||
| certzpb "github.com/openconfig/gnsi/certz" | ||
| "github.com/openconfig/ondatra" | ||
| "github.com/openconfig/ondatra/binding" | ||
| "google.golang.org/grpc/codes" | ||
| "google.golang.org/grpc/status" | ||
| ) | ||
|
|
||
| func TestMain(m *testing.M) { | ||
| fptest.RunTests(m) | ||
| } | ||
|
|
||
| const ( | ||
| dirPath = "../../test_data/" | ||
| timeOutVar time.Duration = 2 * time.Minute | ||
| testProfile = "test-profile" | ||
| rpcTimeout = 2 * time.Minute | ||
| ) | ||
|
|
||
| var ( | ||
| serverAddr string | ||
| creds DUTCredentialer | ||
| ) | ||
|
|
||
| // DUTCredentialer is an interface for getting credentials from a DUT binding. | ||
| type DUTCredentialer interface { | ||
| RPCUsername() string | ||
| RPCPassword() string | ||
| } | ||
|
|
||
| func TestCertzBaseline(t *testing.T) { | ||
| dut := ondatra.DUT(t, "dut") | ||
| serverAddr = dut.Name() //returns the device name. | ||
| if err := binding.DUTAs(dut.RawAPIs().BindingDUT(), &creds); err != nil { | ||
| t.Fatalf("STATUS:Failed to get DUT credentials using binding.DUTs: %v. The binding for %s must implement the DUTCredentialer interface.", err, dut.Name()) | ||
| } | ||
|
|
||
| //Generate testdata certificates | ||
| t.Logf("STATUS:Generation of test data certificates.") | ||
| if err := setupService.TestdataMakeCleanup(t, dirPath, timeOutVar, "./mk_cas.sh"); err != nil { | ||
| t.Fatalf("STATUS:Generation of testdata certificates failed!: %v", err) | ||
| } | ||
|
|
||
| type testCase struct { | ||
| Name string | ||
| Description string | ||
| testFunc func(t *testing.T, dut *ondatra.DUTDevice) | ||
| } | ||
|
|
||
| testCases := []testCase{ | ||
| { | ||
| Name: "Testcase: Add Profile", | ||
| Description: "Add a new TLS service profile to the DUT", | ||
| testFunc: addTLSProfileTest, | ||
| }, | ||
| { | ||
| Name: "Testcase: Delete Profile", | ||
| Description: "Delete an aged TLS service profile from the DUT", | ||
| testFunc: deleteTLSProfileTest, | ||
| }, | ||
| { | ||
| Name: "Testcase: Get Profile Details", | ||
| Description: "Get the current details of a TLS service profile from the DUT", | ||
| testFunc: getTLSProfileDetailsTest, | ||
| }, | ||
| { | ||
| Name: "Testcase: Validate Metrics", | ||
| Description: "Validate that appropriate metrics are returned from streaming telemetry", | ||
| testFunc: validateMetricsTest, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.Name, func(t *testing.T) { | ||
| tc.testFunc(t, dut) | ||
| }) | ||
| } | ||
|
|
||
| t.Logf("STATUS:Cleanup of test data.") | ||
| //Cleanup of test data | ||
| if err := setupService.TestdataMakeCleanup(t, dirPath, timeOutVar, "./mk_cas.sh"); err != nil { | ||
| t.Logf("STATUS:Generation of testdata certificates failed!: %v", err) | ||
| } | ||
| t.Logf("STATUS:Test completed!") | ||
| } | ||
|
|
||
| // Implementation for adding a TLS service profile to the DUT | ||
| func addTLSProfileTest(t *testing.T, dut *ondatra.DUTDevice) { | ||
| ctx, cancel := context.WithTimeout(context.Background(), rpcTimeout) | ||
| defer cancel() | ||
| certzClient := dut.RawAPIs().GNSI(t).Certz() | ||
|
|
||
| resp, err := certzClient.AddProfile(ctx, &certzpb.AddProfileRequest{ | ||
| SslProfileId: testProfile, | ||
| }) | ||
|
|
||
| if err != nil { | ||
| // If the profile already exists from a prior run, that is also acceptable. | ||
| if st, ok := status.FromError(err); ok && st.Code() == codes.AlreadyExists { | ||
| t.Logf("profile %q already exists on DUT", testProfile) | ||
| return | ||
| } | ||
| t.Errorf("AddProfile %s failed: %v", testProfile, err) | ||
| } | ||
| if resp == nil { | ||
| t.Fatalf("AddProfile %s returned nil response", testProfile) | ||
| } | ||
|
|
||
| //Get ssl profile list. | ||
| if getResp := setupService.GetSslProfilelist(ctx, t, certzClient, &certzpb.GetProfileListRequest{}); slices.Contains(getResp.SslProfileIds, testProfile) { | ||
| t.Logf("profile: %s is added.", testProfile) | ||
| } else { | ||
| t.Errorf("profile: %s not found in profile list after add profile", testProfile) | ||
| } | ||
| } | ||
|
|
||
| // Implementation for deleting an aged TLS service profile from the DUT | ||
| func deleteTLSProfileTest(t *testing.T, dut *ondatra.DUTDevice) { | ||
| ctx, cancel := context.WithTimeout(context.Background(), rpcTimeout) | ||
| defer cancel() | ||
| certzClient := dut.RawAPIs().GNSI(t).Certz() | ||
|
|
||
| //Get ssl profile list. | ||
| if getResp := setupService.GetSslProfilelist(ctx, t, certzClient, &certzpb.GetProfileListRequest{}); slices.Contains(getResp.SslProfileIds, testProfile) { | ||
| t.Logf("profile: %s already added.", testProfile) | ||
| } else { | ||
| t.Fatalf("profile: %s not found in profile list", testProfile) | ||
| } | ||
|
|
||
| _, err := certzClient.DeleteProfile(ctx, &certzpb.DeleteProfileRequest{SslProfileId: testProfile}) | ||
| if err != nil { | ||
| t.Errorf("delete profile: %s failed: %v", testProfile, err) | ||
| } | ||
|
|
||
| //Get ssl profile list. | ||
| if getResp := setupService.GetSslProfilelist(ctx, t, certzClient, &certzpb.GetProfileListRequest{}); slices.Contains(getResp.SslProfileIds, testProfile) { | ||
| t.Errorf("profile: %s still found in profile list after delete profile", testProfile) | ||
| } else { | ||
| t.Logf("profile: %s successfully deleted.", testProfile) | ||
| } | ||
| } | ||
|
|
||
| // Implementation for getting the current details of a TLS service profile from the DUT | ||
| func getTLSProfileDetailsTest(t *testing.T, dut *ondatra.DUTDevice) { | ||
| ctx, cancel := context.WithTimeout(context.Background(), rpcTimeout) | ||
| defer cancel() | ||
| certzClient := dut.RawAPIs().GNSI(t).Certz() | ||
|
|
||
| _, err := certzClient.AddProfile(ctx, &certzpb.AddProfileRequest{ | ||
| SslProfileId: testProfile, | ||
| }) | ||
|
|
||
| if err != nil { | ||
| // If the profile already exists from a prior run, that is also acceptable. | ||
| if st, ok := status.FromError(err); ok && st.Code() == codes.AlreadyExists { | ||
| t.Logf("profile %q exists on DUT", testProfile) | ||
| } | ||
| } | ||
|
|
||
| //Get ssl profile list. | ||
| if getResp := setupService.GetSslProfilelist(ctx, t, certzClient, &certzpb.GetProfileListRequest{}); slices.Contains(getResp.SslProfileIds, testProfile) { | ||
| t.Logf("profile: %s already added.", testProfile) | ||
| } else { | ||
| t.Errorf("profile: %s not found in profile list", testProfile) | ||
| } | ||
| } | ||
|
|
||
| // Implementation for validating that appropriate metrics are returned from streaming telemetry | ||
| func validateMetricsTest(t *testing.T, dut *ondatra.DUTDevice) { | ||
| t.Errorf("raised issue 489348277") | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # proto-file: github.com/openconfig/featureprofiles/proto/metadata.proto | ||
| # proto-message: Metadata | ||
|
|
||
| uuid: "b98eb655-8b22-49d3-b0f4-4df12292685a" | ||
| plan_id: "Certz-1" | ||
| description: "gNSI Client Certificate Tests" | ||
| testbed: TESTBED_DUT_ATE_2LINKS |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation of
getTLSProfileDetailsTestdoes not actually call theGetProfileRPC, which is what the test name and description imply. It currently only verifies the profile's presence in the list returned byGetProfileList. Please update the test to callGetProfileand validate the returned details.