From ddd53d5f8ece668571ae6b260e38a357a4dd888a Mon Sep 17 00:00:00 2001 From: mojiiba <91647529+mojiiba@users.noreply.github.com> Date: Wed, 16 Nov 2022 02:42:32 -0500 Subject: [PATCH] gNOI-3.4: fix gnoi path for component and reboot status with empty subcomponent (#717) * add InterfaceOperStatus deviation * Revert "add InterfaceOperStatus deviation" This reverts commit f9855b42c0c73ecc87a4cb5e1f306d04ff918f17. * status test is passing * fix gnoi path and subcomponent name for reboot status --- .../chassis_reboot_status_and_cancel_test.go | 33 ++++++++++++++++--- internal/components/components.go | 18 ++++++++++ internal/deviations/deviations.go | 4 +++ 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/feature/gnoi/system/tests/chassis_reboot_status_and_cancel_test/chassis_reboot_status_and_cancel_test.go b/feature/gnoi/system/tests/chassis_reboot_status_and_cancel_test/chassis_reboot_status_and_cancel_test.go index 5410fb09598..bdc396351fd 100644 --- a/feature/gnoi/system/tests/chassis_reboot_status_and_cancel_test/chassis_reboot_status_and_cancel_test.go +++ b/feature/gnoi/system/tests/chassis_reboot_status_and_cancel_test/chassis_reboot_status_and_cancel_test.go @@ -18,9 +18,13 @@ import ( "context" "testing" + "github.com/openconfig/featureprofiles/internal/components" + "github.com/openconfig/featureprofiles/internal/deviations" "github.com/openconfig/featureprofiles/internal/fptest" spb "github.com/openconfig/gnoi/system" + tpb "github.com/openconfig/gnoi/types" "github.com/openconfig/ondatra" + "github.com/openconfig/ondatra/telemetry" ) const ( @@ -83,6 +87,16 @@ func TestRebootStatus(t *testing.T) { }, } + statusReq := &spb.RebootStatusRequest{Subcomponents: []*tpb.Path{}} + if !*deviations.GNOIStatusWithEmptySubcomponent { + supervisors := components.FindComponentsByType(t, dut, telemetry.PlatformTypes_OPENCONFIG_HARDWARE_COMPONENT_CONTROLLER_CARD) + // the test reboots the chasis, so any subcomponent should be ok to check the status + statusReq = &spb.RebootStatusRequest{ + Subcomponents: []*tpb.Path{ + components.GetSubcomponentPath(supervisors[0]), + }, + } + } for _, tc := range cases { t.Run(tc.desc, func(t *testing.T) { if tc.rebootRequest != nil { @@ -93,8 +107,7 @@ func TestRebootStatus(t *testing.T) { t.Fatalf("Failed to request reboot with unexpected err: %v", err) } } - - resp, err := gnoiClient.System().RebootStatus(context.Background(), &spb.RebootStatusRequest{}) + resp, err := gnoiClient.System().RebootStatus(context.Background(), statusReq) t.Logf("DUT rebootStatus: %v, err: %v", resp, err) if err != nil { t.Fatalf("Failed to get reboot status with unexpected err: %v", err) @@ -117,6 +130,7 @@ func TestRebootStatus(t *testing.T) { }) t.Logf("Cancel reboot request after the test") + rebootCancel, err := gnoiClient.System().CancelReboot(context.Background(), &spb.CancelRebootRequest{}) if err != nil { t.Fatalf("Failed to cancel reboot with unexpected err: %v", err) @@ -149,8 +163,17 @@ func TestCancelReboot(t *testing.T) { if err != nil { t.Fatalf("Failed to request reboot with unexpected err: %v", err) } - - rebootStatus, err := gnoiClient.System().RebootStatus(context.Background(), &spb.RebootStatusRequest{}) + statusReq := &spb.RebootStatusRequest{Subcomponents: []*tpb.Path{}} + if !*deviations.GNOIStatusWithEmptySubcomponent { + supervisors := components.FindComponentsByType(t, dut, telemetry.PlatformTypes_OPENCONFIG_HARDWARE_COMPONENT_CONTROLLER_CARD) + // the test reboots the chasis, so any subcomponent should be ok to check the status + statusReq = &spb.RebootStatusRequest{ + Subcomponents: []*tpb.Path{ + components.GetSubcomponentPath(supervisors[0]), + }, + } + } + rebootStatus, err := gnoiClient.System().RebootStatus(context.Background(), statusReq) t.Logf("DUT rebootStatus: %v, err: %v", rebootStatus, err) if err != nil { t.Fatalf("Failed to get reboot status with unexpected err: %v", err) @@ -166,7 +189,7 @@ func TestCancelReboot(t *testing.T) { t.Fatalf("Failed to cancel reboot with unexpected err: %v", err) } - rebootStatus, err = gnoiClient.System().RebootStatus(context.Background(), &spb.RebootStatusRequest{}) + rebootStatus, err = gnoiClient.System().RebootStatus(context.Background(), statusReq) t.Logf("DUT rebootStatus: %v, err: %v", rebootStatus, err) if err != nil { t.Fatalf("Failed to get reboot status with unexpected err: %v", err) diff --git a/internal/components/components.go b/internal/components/components.go index 381a52acffe..82f03ac3f0e 100644 --- a/internal/components/components.go +++ b/internal/components/components.go @@ -19,6 +19,8 @@ import ( "regexp" "testing" + "github.com/openconfig/featureprofiles/internal/deviations" + tpb "github.com/openconfig/gnoi/types" "github.com/openconfig/ondatra" "github.com/openconfig/ondatra/telemetry" ) @@ -57,3 +59,19 @@ func FindMatchingStrings(components []string, r *regexp.Regexp) []string { } return s } + +// GetSubcomponentPath creates a gNMI path based on the componnent name. +func GetSubcomponentPath(name string) *tpb.Path { + if *deviations.GNOISubcomponentPath { + return &tpb.Path{ + Elem: []*tpb.PathElem{{Name: name}}, + } + } + return &tpb.Path{ + Origin: "openconfig", + Elem: []*tpb.PathElem{ + {Name: "components"}, + {Name: "component", Key: map[string]string{"name": name}}, + }, + } +} diff --git a/internal/deviations/deviations.go b/internal/deviations/deviations.go index b0c6af8b3c0..6ca802481f9 100644 --- a/internal/deviations/deviations.go +++ b/internal/deviations/deviations.go @@ -101,5 +101,9 @@ var ( StaticProtocolName = flag.String("deviation_static_protocol_name", "DEFAULT", "The name used for the static routing protocol. The default name in OpenConfig is \"DEFAULT\" but some devices use other names.") + GNOISubcomponentPath = flag.Bool("deviation_gnoi_subcomponent_path", false, "Device currently uses component name instead of a full openconfig path, so suppress creating a full oc compliant path for subcomponent.") + + GNOIStatusWithEmptySubcomponent = flag.Bool("deviation_gnoi_status_empty_subcomponent", false, "The response of gNOI reboot status is a single value (not a list), so the device requires explict component path to account for a situation when there is more than one active reboot requests.") + DeprecatedVlanID = flag.Bool("deviation_deprecated_vlan_id", false, "Device requires using the deprecated openconfig-vlan:vlan/config/vlan-id or openconfig-vlan:vlan/state/vlan-id leaves.") )