From 98bc857bf4731062a50073832b8266f3ab173ee6 Mon Sep 17 00:00:00 2001 From: Edward Haas Date: Tue, 2 Mar 2021 10:32:46 +0200 Subject: [PATCH] state, filter: Always interpret interfaces names as strings When an interface name can be interpreted as a numeric value (e.g. 123, 1.0, 0xfe), the generic nature of the yaml unmarshal is resulting with float64 values. Such values are wrongly represented back with the original text (e.g. 0xfe is represented back as 254). This has been fixed in a previous change for the filtering matching. This change is using the same to mark the interface name as a string, so it will also be correctly represented. Signed-off-by: Edward Haas --- pkg/state/filter.go | 4 +++- pkg/state/filter_test.go | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/state/filter.go b/pkg/state/filter.go index 381a01ffc..8b85e19da 100644 --- a/pkg/state/filter.go +++ b/pkg/state/filter.go @@ -78,7 +78,9 @@ func filterOutInterfaces(ifaces []interface{}, ifacesNames []Interface, interfac for i, iface := range ifaces { name := ifacesNames[i].Name if !interfacesFilterGlob.Match(name) { - filterOutDynamicAttributes(iface.(map[string]interface{})) + ifaceState := iface.(map[string]interface{}) + ifaceState["name"] = name + filterOutDynamicAttributes(ifaceState) filteredInterfaces = append(filteredInterfaces, iface) } } diff --git a/pkg/state/filter_test.go b/pkg/state/filter_test.go index 0e2050578..0f5913b3b 100644 --- a/pkg/state/filter_test.go +++ b/pkg/state/filter_test.go @@ -342,7 +342,7 @@ interfaces: filteredState = nmstate.NewState(` interfaces: - name: eth0 -- name: 1101010 +- name: "1101010" `) interfacesFilterGlob = glob.MustCompile("0*") }) @@ -366,8 +366,8 @@ interfaces: filteredState = nmstate.NewState(` interfaces: - name: eth0 -- name: 0 -- name: 254 +- name: "0" +- name: "254" `) interfacesFilterGlob = glob.MustCompile("1*") })