Skip to content

Commit

Permalink
Merge pull request #15057 from danwinship/more-ovs-errors
Browse files Browse the repository at this point in the history
Get more error info if OVS ofport allocation fails
  • Loading branch information
smarterclayton authored Jul 5, 2017
2 parents d036fba + 7459b28 commit 03c8cb2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/util/ovs/ovs.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,19 @@ func (ovsif *ovsExec) DeleteBridge() error {
func (ovsif *ovsExec) GetOFPort(port string) (int, error) {
ofportStr, err := ovsif.exec(OVS_VSCTL, "get", "Interface", port, "ofport")
if err != nil {
return -1, err
return -1, fmt.Errorf("failed to get OVS port for %s: %v", port, err)
}
ofport, err := strconv.Atoi(ofportStr)
if err != nil {
return -1, fmt.Errorf("could not parse allocated ofport %q: %v", ofportStr, err)
}
if ofport == -1 {
errStr, err := ovsif.exec(OVS_VSCTL, "get", "Interface", port, "error")
if err != nil || errStr == "" {
errStr = "unknown error"
}
return -1, fmt.Errorf("error on port %s: %s", port, errStr)
}
return ofport, nil
}

Expand All @@ -199,7 +206,7 @@ func (ovsif *ovsExec) AddPort(port string, ofportRequest int, properties ...stri
}
ofport, err := ovsif.GetOFPort(port)
if err != nil {
return -1, fmt.Errorf("failed to get %q OVS port: %v", port, err)
return -1, err
}
if ofportRequest > 0 && ofportRequest != ofport {
return -1, fmt.Errorf("allocated ofport (%d) did not match request (%d)", ofport, ofportRequest)
Expand Down
12 changes: 12 additions & 0 deletions pkg/util/ovs/ovs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,18 @@ func TestAddPort(t *testing.T) {
t.Fatalf("Got wrong error: %v", err)
}
ensureTestResults(t, fexec)

addTestResult(t, fexec, "ovs-vsctl --may-exist add-port br0 veth0 -- set Interface veth0 ofport_request=5", "", nil)
addTestResult(t, fexec, "ovs-vsctl get Interface veth0 ofport", "-1\n", nil)
addTestResult(t, fexec, "ovs-vsctl get Interface veth0 error", "could not open network device veth0 (No such device)\n", nil)
_, err = ovsif.AddPort("veth0", 5)
if err == nil {
t.Fatalf("Unexpectedly failed to get error")
}
if err.Error() != "error on port veth0: could not open network device veth0 (No such device)" {
t.Fatalf("Got wrong error: %v", err)
}
ensureTestResults(t, fexec)
}

func TestOVSVersion(t *testing.T) {
Expand Down

0 comments on commit 03c8cb2

Please sign in to comment.