Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip linux-bridge filtering if no "bridge" section #690

Merged
merged 1 commit into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions pkg/state/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ func FilterOut(currentState shared.State) (shared.State, error) {
}

func filterOutRoutes(kind string, state map[string]interface{}, interfacesFilterGlob glob.Glob) {
routes := state["routes"].(map[string]interface{})
routesRaw, hasRoutes := state["routes"]
if !hasRoutes {
return
}

routes, ok := routesRaw.(map[string]interface{})
if !ok {
return
}

routesByKind := routes[kind].([]interface{})

if routesByKind == nil {
Expand Down Expand Up @@ -58,9 +67,24 @@ func filterOutDynamicAttributes(iface map[string]interface{}) {
return
}

bridge := iface["bridge"].(map[string]interface{})
bridgeRaw, hasBridge := iface["bridge"]
if !hasBridge {
return
}
bridge, ok := bridgeRaw.(map[string]interface{})
if !ok {
return
}

optionsRaw, hasOptions := bridge["options"]
if !hasOptions {
return
}
options, ok := optionsRaw.(map[string]interface{})
if !ok {
return
}

options := bridge["options"].(map[string]interface{})
delete(options, "gc-timer")
delete(options, "hello-timer")
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/state/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,28 @@ routes:
Expect(returnedState).To(MatchYAML(filteredState))
})
})
Context("when there is a linux bridge without 'bridge' options because is down", func() {
BeforeEach(func() {
state = nmstate.NewState(`
interfaces:
- name: br1
type: linux-bridge
state: down
`)

filteredState = nmstate.NewState(`
interfaces:
- name: br1
type: linux-bridge
state: down
`)
interfacesFilterGlob = glob.MustCompile("")
})
It("should keep the bridge as it is", func() {
returnedState, err := filterOut(state, interfacesFilterGlob)
Expect(err).ToNot(HaveOccurred())
Expect(returnedState).To(MatchYAML(filteredState))
})
})

})