Skip to content

Commit 93b1811

Browse files
Yun Chenmdlayher
Yun Chen
authored andcommitted
ovs: check if list bridge/ports output is empty (#54)
1 parent cbff56f commit 93b1811

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

ovs/vswitch.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ func (v *VSwitchService) ListPorts(bridge string) ([]string, error) {
7777
return nil, err
7878
}
7979

80+
if string(output) == "" {
81+
return nil, nil
82+
}
8083
ports := strings.Split(strings.TrimSpace(string(output)), "\n")
8184
return ports, err
8285
}
@@ -88,6 +91,9 @@ func (v *VSwitchService) ListBridges() ([]string, error) {
8891
return nil, err
8992
}
9093

94+
if string(output) == "" {
95+
return nil, nil
96+
}
9197
bridges := strings.Split(strings.TrimSpace(string(output)), "\n")
9298
return bridges, err
9399
}

ovs/vswitch_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,15 @@ func TestClientVSwitchListPorts(t *testing.T) {
205205
err error
206206
c *Client
207207
}{
208+
{
209+
name: "test br0 bonded with no interface",
210+
input: "br0",
211+
want: nil,
212+
err: nil,
213+
c: testClient(nil, func(cmd string, args ...string) ([]byte, error) {
214+
return []byte(""), nil
215+
}),
216+
},
208217
{
209218
name: "test br0 bonded",
210219
input: "br0",
@@ -260,6 +269,14 @@ func TestClientVSwitchListBridges(t *testing.T) {
260269
err error
261270
c *Client
262271
}{
272+
{
273+
name: "test no bridge",
274+
want: nil,
275+
err: nil,
276+
c: testClient(nil, func(cmd string, args ...string) ([]byte, error) {
277+
return []byte(""), nil
278+
}),
279+
},
263280
{
264281
name: "test single bridge",
265282
want: []string{"br0"},

0 commit comments

Comments
 (0)