Skip to content

Commit

Permalink
ovs: check if list bridge/ports output is empty (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yun Chen authored and mdlayher committed Jun 4, 2018
1 parent cbff56f commit 93b1811
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ovs/vswitch.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ func (v *VSwitchService) ListPorts(bridge string) ([]string, error) {
return nil, err
}

if string(output) == "" {
return nil, nil
}
ports := strings.Split(strings.TrimSpace(string(output)), "\n")
return ports, err
}
Expand All @@ -88,6 +91,9 @@ func (v *VSwitchService) ListBridges() ([]string, error) {
return nil, err
}

if string(output) == "" {
return nil, nil
}
bridges := strings.Split(strings.TrimSpace(string(output)), "\n")
return bridges, err
}
Expand Down
17 changes: 17 additions & 0 deletions ovs/vswitch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,15 @@ func TestClientVSwitchListPorts(t *testing.T) {
err error
c *Client
}{
{
name: "test br0 bonded with no interface",
input: "br0",
want: nil,
err: nil,
c: testClient(nil, func(cmd string, args ...string) ([]byte, error) {
return []byte(""), nil
}),
},
{
name: "test br0 bonded",
input: "br0",
Expand Down Expand Up @@ -260,6 +269,14 @@ func TestClientVSwitchListBridges(t *testing.T) {
err error
c *Client
}{
{
name: "test no bridge",
want: nil,
err: nil,
c: testClient(nil, func(cmd string, args ...string) ([]byte, error) {
return []byte(""), nil
}),
},
{
name: "test single bridge",
want: []string{"br0"},
Expand Down

0 comments on commit 93b1811

Please sign in to comment.