Skip to content

Commit

Permalink
state, filter: Always interpret interfaces names as strings
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
EdDev committed Mar 2, 2021
1 parent 739949e commit 98bc857
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion pkg/state/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/state/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ interfaces:
filteredState = nmstate.NewState(`
interfaces:
- name: eth0
- name: 1101010
- name: "1101010"
`)
interfacesFilterGlob = glob.MustCompile("0*")
})
Expand All @@ -366,8 +366,8 @@ interfaces:
filteredState = nmstate.NewState(`
interfaces:
- name: eth0
- name: 0
- name: 254
- name: "0"
- name: "254"
`)
interfacesFilterGlob = glob.MustCompile("1*")
})
Expand Down

0 comments on commit 98bc857

Please sign in to comment.