Skip to content

Commit 67faafd

Browse files
author
Dave Tucker
committed
Improve Error Handling in AddInternalPort
Signed-off-by: Dave Tucker <[email protected]>
1 parent c0ffb09 commit 67faafd

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

daemon/network.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ func CreateNetwork(id string, subnet *net.IPNet) (*Network, error) {
7575
// Interface does not exist, use the generated subnet
7676
gateway = ipam.Request(*subnet)
7777
network = &Network{id, subnet.String(), gateway.String(), vlan}
78-
AddInternalPort(ovs, defaultBridgeName, network.ID, vlan)
78+
if err = AddInternalPort(ovs, defaultBridgeName, network.ID, vlan); err != nil {
79+
return network, err
80+
}
7981
// TODO : Lame. Remove the sleep. This is required now to keep netlink happy
8082
// in the next step to find the created interface.
8183
time.Sleep(time.Second * 1)

daemon/ovs_driver.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func UpdatePortContext(ovs *libovsdb.OvsdbClient, portName string, key string, c
289289
return nil
290290
}
291291

292-
func AddInternalPort(ovs *libovsdb.OvsdbClient, bridgeName string, portName string, tag uint) {
292+
func AddInternalPort(ovs *libovsdb.OvsdbClient, bridgeName string, portName string, tag uint) error {
293293
namedPortUuid := "port"
294294
namedIntfUuid := "intf"
295295

@@ -339,14 +339,18 @@ func AddInternalPort(ovs *libovsdb.OvsdbClient, bridgeName string, portName stri
339339
reply, _ := ovs.Transact("Open_vSwitch", operations...)
340340
if len(reply) < len(operations) {
341341
log.Error("Number of Replies should be atleast equal to number of Operations")
342+
return errors.New("Number of Replies should be atleast equal to number of Operations")
342343
}
343344
for i, o := range reply {
344345
if o.Error != "" && i < len(operations) {
345-
log.Errorf("Transaction Failed due to an error : %v details: %v in %v", o.Error, o.Details, operations[i])
346+
msg := fmt.Sprintf("Transaction Failed due to an error : %v details: %v in %v", o.Error, o.Details, operations[i])
347+
return errors.New(msg)
346348
} else if o.Error != "" {
347-
log.Errorf("Transaction Failed due to an error : %v", o.Error)
349+
msg := fmt.Sprintf("Transaction Failed due to an error : %v", o.Error)
350+
return errors.New(msg)
348351
}
349352
}
353+
return nil
350354
}
351355

352356
func populateCache(updates libovsdb.TableUpdates) {

0 commit comments

Comments
 (0)