Skip to content

Commit

Permalink
handler: Remove iface name normalization (#1204)
Browse files Browse the repository at this point in the history
nmstate 2.y.z renders correctly the interface name and add a single
quotes if the name is not an string so marshaling it always result as an
string. This change remove the code that normalize interface names for
those scenarios since it's not longer needed.

Signed-off-by: Enrique Llorente <[email protected]>
  • Loading branch information
qinqon authored Sep 15, 2023
1 parent 7614c91 commit 8ef22d3
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 127 deletions.
27 changes: 0 additions & 27 deletions pkg/state/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/nmstate/kubernetes-nmstate/api/shared"
"github.com/nmstate/kubernetes-nmstate/pkg/environment"

goyaml "gopkg.in/yaml.v2"
yaml "sigs.k8s.io/yaml"
)

Expand Down Expand Up @@ -116,9 +115,6 @@ func filterOut(currentState shared.State) (shared.State, error) {
if err := yaml.Unmarshal(currentState.Raw, &state); err != nil {
return currentState, err
}
if err := normalizeInterfacesNames(currentState.Raw, &state); err != nil {
return currentState, err
}

state.Interfaces = filterOutInterfaces(state.Interfaces)
if state.Routes != nil {
Expand All @@ -133,26 +129,3 @@ func filterOut(currentState shared.State) (shared.State, error) {

return shared.NewState(string(filteredState)), nil
}

// normalizeInterfacesNames fixes the unmarshal of numeric values in the interfaces names
// Numeric values, including the ones with a base prefix (e.g. 0x123) should be stringify.
func normalizeInterfacesNames(rawState []byte, state *rootState) error {
var stateForNormalization rootState
if err := goyaml.Unmarshal(rawState, &stateForNormalization); err != nil {
return err
}

for i, iface := range stateForNormalization.Interfaces {
state.Interfaces[i].Name = iface.Name
}

if stateForNormalization.Routes != nil {
for i, route := range stateForNormalization.Routes.Config {
state.Routes.Config[i].NextHopInterface = route.NextHopInterface
}
for i, route := range stateForNormalization.Routes.Running {
state.Routes.Running[i].NextHopInterface = route.NextHopInterface
}
}
return nil
}
100 changes: 0 additions & 100 deletions pkg/state/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,104 +325,4 @@ dns-resolver:
Expect(returnedState).To(MatchYAML(state))
})
})

Context("when the interfaces have numeric characters", func() {
BeforeEach(func() {
state = nmstate.NewState(`interfaces:
- name: eth0
type: ethernet
- name: '0'
type: veth
veth:
peer: eth2
state: ignore
- name: '1101010'
type: veth
state: ignore
veth:
peer: eth2
- name: '0.0'
type: veth
veth:
peer: eth2
state: ignore
- name: '1.0'
type: veth
veth:
peer: eth2
state: ignore
- name: '0xfe'
type: veth
veth:
peer: eth2
state: ignore
- name: '60.e+02'
type: veth
veth:
peer: eth2
state: ignore
- name: 10e+02
type: veth
veth:
peer: eth2
state: ignore
- name: 70e+02
type: veth
veth:
peer: eth2
state: ignore
- name: 94475496822e234
type: veth
veth:
peer: eth2
state: ignore
routes:
config: []
running:
- destination: fd10:244::8c40/128
metric: 1024
next-hop-address: 10.21.21.10
next-hop-interface: eth0
table-id: 254
- destination: fd10:244::8c40/128
metric: 1024
next-hop-address: 10.21.21.10
next-hop-interface: 94475496822e234
table-id: 254
- destination: fd10:244::8c40/128
metric: 1024
next-hop-address: 10.21.21.10
next-hop-interface: '94475496822e234'
table-id: 254
- destination: fd10:244::8c40/128
metric: 1024
next-hop-address: 10.21.21.10
next-hop-interface: 70e+02
table-id: 254
- destination: fd10:244::8c40/128
metric: 1024
next-hop-address: 10.21.21.10
next-hop-interface: 60.e+02
table-id: 254
`)
filteredState = nmstate.NewState(`interfaces:
- name: eth0
type: ethernet
routes:
config: []
running:
- destination: fd10:244::8c40/128
metric: 1024
next-hop-address: 10.21.21.10
next-hop-interface: eth0
table-id: 254
`)
})

It("should filter out interfaces correctly", func() {
returnedState, err := filterOut(state)
Expect(err).NotTo(HaveOccurred())
Expect(returnedState).To(MatchYAML(filteredState))
})
})
})

0 comments on commit 8ef22d3

Please sign in to comment.