Skip to content

Commit

Permalink
Update gNMI-1.4 to validate subcomponents paths. (openconfig#3132)
Browse files Browse the repository at this point in the history
* Add subcomponents/ to README.

* Check that subcomponent exists in telemetry_inventory_test.

* Update README - validate sucomponent name for any component type.

* Fix iteration over subcomponents.

* Rename variable.

* Add else for empty subcomponent.

* Access subcomponent directly.

* Rename function and update comment
  • Loading branch information
SydneyCaulfeild authored and bkreddy143 committed Jul 17, 2024
1 parent 390b398 commit 8242400
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions feature/platform/tests/telemetry_inventory_test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ paths:
platform_type: ["SENSOR"]
/components/component/state/temperature/max-time:
platform_type: ["SENSOR"]
/components/component/subcomponents/subcomponent/name:
platform_type: ["CHASSIS", "CONTROLLER_CARD", "CPU", "FABRIC", "FAN", "FAN_TRAY", "INTEGRATED_CIRCUIT", "LINECARD", "POWER_SUPPLY", "SENSOR", "STORAGE", "TRANSCEIVER"]
/components/component/subcomponents/subcomponent/state/name:
platform_type: ["CHASSIS", "CONTROLLER_CARD", "CPU", "FABRIC", "FAN", "FAN_TRAY", "INTEGRATED_CIRCUIT", "LINECARD", "POWER_SUPPLY", "SENSOR", "STORAGE", "TRANSCEIVER"]
/components/component/integrated-circuit/backplane-facing-capacity/state/available-pct:
platform_type: ["INTEGRATED_CIRCUIT"]
/components/component/integrated-circuit/backplane-facing-capacity/state/consumed-capacity:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ func TestMain(m *testing.M) {
// - integrated-circuit/backplane-facing-capacity/state/consumed-capacity
// - integrated-circuit/backplane-facing-capacity/state/total
// - integrated-circuit/backplane-facing-capacity/state/total-operational-capacity
// - components/component/subcomponents/subcomponent/name
// - components/component/subcomponents/subcomponent/state/name
// - Transceiver
// - Storage
// - Validate telemetry /components/component/storage exists.
Expand Down Expand Up @@ -577,6 +579,26 @@ func TestControllerCardEmpty(t *testing.T) {
}
}

// validateSubcomponentsExistAsComponents checks that if the given component has subcomponents, that
// those subcomponents exist as components on the device (i.e. the leafref is valid).
func validateSubcomponentsExistAsComponents(c *oc.Component, components []*oc.Component, t *testing.T) {
// Note that this will get the subcomponents regardless of whether they are stored in
// subcomponent/name or subcomponent/state/name.
for _, s := range c.Subcomponent {
sName := s.GetName()
if sName != "" {
for _, component := range components {
if component.GetName() == sName {
continue
}
}
t.Errorf("Subcomponent %s not found in list of components", sName)
} else {
t.Errorf("Component %s has empty subcomponent name", c.GetName())
}
}
}

func ValidateComponentState(t *testing.T, dut *ondatra.DUTDevice, cards []*oc.Component, p properties) {
var validCards []*oc.Component
switch p.pType {
Expand All @@ -601,6 +623,7 @@ func ValidateComponentState(t *testing.T, dut *ondatra.DUTDevice, cards []*oc.Co
}
cName := card.GetName()
t.Run(cName, func(t *testing.T) {
validateSubcomponentsExistAsComponents(card, validCards, t)
if p.descriptionValidation {
t.Logf("Component %s Description: %s", cName, card.GetDescription())
if card.GetDescription() == "" {
Expand Down

0 comments on commit 8242400

Please sign in to comment.