From d06757fe56b24fea7a0a36adc94b03fb0dd5cbcb Mon Sep 17 00:00:00 2001 From: Milan Lenco Date: Fri, 17 May 2019 11:02:25 +0200 Subject: [PATCH] Pluralize also key for all rx-modes of an interface Signed-off-by: Milan Lenco --- api/models/vpp/interfaces/keys.go | 21 +++--- api/models/vpp/interfaces/keys_test.go | 76 ++++++++++---------- plugins/vpp/ifplugin/descriptor/interface.go | 2 +- plugins/vpp/ifplugin/descriptor/rx_mode.go | 2 +- 4 files changed, 49 insertions(+), 52 deletions(-) diff --git a/api/models/vpp/interfaces/keys.go b/api/models/vpp/interfaces/keys.go index a659fbc197..e13ac15520 100644 --- a/api/models/vpp/interfaces/keys.go +++ b/api/models/vpp/interfaces/keys.go @@ -128,11 +128,11 @@ const ( rxPlacementKeyTemplate = "vpp/interface/{iface}/rx-placement/queue/{queue}" ) -/* Interface Rx-mode (derived) */ +/* Interface Rx-modes (derived) */ const ( // rxModeKeyTemplate is a template for (derived) key representing // rx-mode configuration for all queues of a given interface. - rxModeKeyTemplate = "vpp/interface/{iface}/rx-mode" + rxModesKeyTemplate = "vpp/interface/{iface}/rx-modes" ) const ( @@ -527,24 +527,23 @@ func ParseRxPlacementKey(key string) (ifaceName string, queue uint32, isRxPlacem return } -/* Rx mode (derived) */ +/* Rx modes (derived) */ -// RxModeKey returns a key representing rx-mode configuration for all queues +// RxModesKey returns a key representing rx-mode configuration for all queues // of a given interface. -func RxModeKey(ifaceName string) string { +func RxModesKey(ifaceName string) string { if ifaceName == "" { ifaceName = InvalidKeyPart } - return strings.Replace(rxModeKeyTemplate, "{iface}", ifaceName, 1) + return strings.Replace(rxModesKeyTemplate, "{iface}", ifaceName, 1) } -// ParseRxModeKey parses key representing rx-mode configuration for all queues +// ParseRxModesKey parses key representing rx-mode configuration for all queues // of a given interface. -func ParseRxModeKey(key string) (ifaceName string, isRxModeKey bool) { +func ParseRxModesKey(key string) (ifaceName string, isRxModesKey bool) { if suffix := strings.TrimPrefix(key, "vpp/interface/"); suffix != key { parts := strings.Split(suffix, "/") - if len(parts) == 0 || parts[len(parts)-1] != "rx-mode" { - isRxModeKey = false + if len(parts) == 0 || parts[len(parts)-1] != "rx-modes" { return } @@ -555,7 +554,7 @@ func ParseRxModeKey(key string) (ifaceName string, isRxModeKey bool) { return } - isRxModeKey = true + isRxModesKey = true } return } diff --git a/api/models/vpp/interfaces/keys_test.go b/api/models/vpp/interfaces/keys_test.go index 92239d1e42..e166f65aad 100644 --- a/api/models/vpp/interfaces/keys_test.go +++ b/api/models/vpp/interfaces/keys_test.go @@ -889,11 +889,11 @@ func TestLinkStateKey(t *testing.T) { func TestParseLinkStateKey(t *testing.T) { tests := []struct { - name string - key string - expectedIface string - expectedIsLinkUp bool - expectedIsLinkStateKey bool + name string + key string + expectedIface string + expectedIsLinkUp bool + expectedIsLinkStateKey bool }{ { name: "link is UP", @@ -936,7 +936,6 @@ func TestParseLinkStateKey(t *testing.T) { key: "vpp/interface/unnumbered/GigabitEthernet0/8/0", expectedIsLinkStateKey: false, }, - } for _, test := range tests { t.Run(test.name, func(t *testing.T) { @@ -1032,7 +1031,7 @@ func TestParseRxPlacementKey(t *testing.T) { expectedIsRxPlacementKey: false, }, { - name: "missing queue", + name: "missing queue", key: "vpp/interface/memif0/rx-placement/", expectedIsRxPlacementKey: false, }, @@ -1053,7 +1052,6 @@ func TestParseRxPlacementKey(t *testing.T) { key: "vpp/interface/memif0/link-state/DOWN", expectedIsRxPlacementKey: false, }, - } for _, test := range tests { t.Run(test.name, func(t *testing.T) { @@ -1072,7 +1070,7 @@ func TestParseRxPlacementKey(t *testing.T) { } } -func TestRxModeKey(t *testing.T) { +func TestRxModesKey(t *testing.T) { tests := []struct { name string iface string @@ -1081,22 +1079,22 @@ func TestRxModeKey(t *testing.T) { { name: "memif", iface: "memif0", - expectedKey: "vpp/interface/memif0/rx-mode", + expectedKey: "vpp/interface/memif0/rx-modes", }, { name: "Gbe", iface: "GigabitEthernet0/8/0", - expectedKey: "vpp/interface/GigabitEthernet0/8/0/rx-mode", + expectedKey: "vpp/interface/GigabitEthernet0/8/0/rx-modes", }, { name: "invalid interface name", iface: "", - expectedKey: "vpp/interface//rx-mode", + expectedKey: "vpp/interface//rx-modes", }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - key := RxModeKey(test.iface) + key := RxModesKey(test.iface) if key != test.expectedKey { t.Errorf("failed for: iface=%s\n"+ "expected key:\n\t%q\ngot key:\n\t%q", @@ -1106,47 +1104,47 @@ func TestRxModeKey(t *testing.T) { } } -func TestParseRxModeKey(t *testing.T) { +func TestParseRxModesKey(t *testing.T) { tests := []struct { - name string - key string - expectedIface string - expectedIsRxModeKey bool + name string + key string + expectedIface string + expectedIsRxModesKey bool }{ { - name: "memif", - key: "vpp/interface/memif0/rx-mode", - expectedIface: "memif0", - expectedIsRxModeKey: true, + name: "memif", + key: "vpp/interface/memif0/rx-modes", + expectedIface: "memif0", + expectedIsRxModesKey: true, }, { - name: "Gbe", - key: "vpp/interface/GigabitEthernet0/8/0/rx-mode", - expectedIface: "GigabitEthernet0/8/0", - expectedIsRxModeKey: true, + name: "Gbe", + key: "vpp/interface/GigabitEthernet0/8/0/rx-modes", + expectedIface: "GigabitEthernet0/8/0", + expectedIsRxModesKey: true, }, { - name: "invalid interface name", - key: "vpp/interface//rx-mode", - expectedIsRxModeKey: false, + name: "invalid interface name", + key: "vpp/interface//rx-modes", + expectedIsRxModesKey: false, }, { - name: "missing rx-mode suffix", - key: "vpp/interface/", - expectedIsRxModeKey: false, + name: "missing rx-mode suffix", + key: "vpp/interface/", + expectedIsRxModesKey: false, }, { - name: "not rx-mode key", - key: "vpp/interface/memif0/address/192.168.1.12/24", - expectedIsRxModeKey: false, + name: "not rx-mode key", + key: "vpp/interface/memif0/address/192.168.1.12/24", + expectedIsRxModesKey: false, }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - iface, isRxModeKey := ParseRxModeKey(test.key) - if isRxModeKey != test.expectedIsRxModeKey { - t.Errorf("expected isRxModeKey: %v\tgot: %v", - test.expectedIsRxModeKey, isRxModeKey) + iface, isRxModesKey := ParseRxModesKey(test.key) + if isRxModesKey != test.expectedIsRxModesKey { + t.Errorf("expected isRxModesKey: %v\tgot: %v", + test.expectedIsRxModesKey, isRxModesKey) } if iface != test.expectedIface { t.Errorf("expected iface: %s\tgot: %s", test.expectedIface, iface) diff --git a/plugins/vpp/ifplugin/descriptor/interface.go b/plugins/vpp/ifplugin/descriptor/interface.go index cbc5059b08..7e7978a5d9 100644 --- a/plugins/vpp/ifplugin/descriptor/interface.go +++ b/plugins/vpp/ifplugin/descriptor/interface.go @@ -605,7 +605,7 @@ func (d *InterfaceDescriptor) DerivedValues(key string, intf *interfaces.Interfa // Rx mode if len(intf.GetRxModes()) > 0 { derValues = append(derValues, kvs.KeyValuePair{ - Key: interfaces.RxModeKey(intf.GetName()), + Key: interfaces.RxModesKey(intf.GetName()), Value: &interfaces.Interface{ Name: intf.GetName(), Type: intf.GetType(), diff --git a/plugins/vpp/ifplugin/descriptor/rx_mode.go b/plugins/vpp/ifplugin/descriptor/rx_mode.go index f50d5a09eb..59130aafc5 100644 --- a/plugins/vpp/ifplugin/descriptor/rx_mode.go +++ b/plugins/vpp/ifplugin/descriptor/rx_mode.go @@ -85,7 +85,7 @@ func NewRxModeDescriptor(ifHandler vppcalls.InterfaceVppAPI, ifIndex ifaceidx.If // IsInterfaceRxModeKey returns true if the key is identifying RxMode configuration. func (d *RxModeDescriptor) IsInterfaceRxModeKey(key string) bool { - _, isValid := interfaces.ParseRxModeKey(key) + _, isValid := interfaces.ParseRxModesKey(key) return isValid }