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

Fix OVS/OVN transaction handling #342

Merged
merged 4 commits into from
Dec 29, 2023
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
32 changes: 20 additions & 12 deletions internal/server/network/ovn/ovn_nb_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1452,18 +1452,21 @@ func (o *NB) ChassisGroupChassisAdd(haChassisGroupName OVNChassisGroup, chassisI
operations := []ovsdb.Operation{}

// Get the chassis group.
haGroup := &ovnNB.HAChassisGroup{Name: string(haChassisGroupName)}
err := o.client.Get(ctx, haGroup)
haGroup := ovnNB.HAChassisGroup{
Name: string(haChassisGroupName),
}

err := o.client.Get(ctx, &haGroup)
if err != nil {
return err
}

// Look for the chassis in the group.
var haChassis *ovnNB.HAChassis
var haChassis ovnNB.HAChassis

for _, entry := range haGroup.HaChassis {
chassis := &ovnNB.HAChassis{UUID: entry}
err = o.client.Get(ctx, chassis)
chassis := ovnNB.HAChassis{UUID: entry}
err = o.client.Get(ctx, &chassis)
if err != nil {
return err
}
Expand All @@ -1474,24 +1477,24 @@ func (o *NB) ChassisGroupChassisAdd(haChassisGroupName OVNChassisGroup, chassisI
}
}

if haChassis == nil {
if haChassis.UUID == "" {
// No entry found, add a new one.
haChassis = &ovnNB.HAChassis{
haChassis = ovnNB.HAChassis{
UUID: "chassis",
ChassisName: chassisID,
Priority: int(priority),
}

createOps, err := o.client.Create(haChassis)
createOps, err := o.client.Create(&haChassis)
if err != nil {
return err
}

operations = append(operations, createOps...)

// Add the HA Chassis to the group.
updateOps, err := o.client.Where(haGroup).Mutate(haGroup, ovsModel.Mutation{
Field: haGroup.HaChassis,
updateOps, err := o.client.Where(&haGroup).Mutate(&haGroup, ovsModel.Mutation{
Field: &haGroup.HaChassis,
Mutator: ovsdb.MutateOperationInsert,
Value: []string{haChassis.UUID},
})
Expand All @@ -1503,7 +1506,7 @@ func (o *NB) ChassisGroupChassisAdd(haChassisGroupName OVNChassisGroup, chassisI
} else if haChassis.Priority != int(priority) {
// Found but wrong priority, correct it.
haChassis.Priority = int(priority)
updateOps, err := o.client.Where(haChassis).Update(haChassis)
updateOps, err := o.client.Where(&haChassis).Update(&haChassis)
if err != nil {
return err
}
Expand All @@ -1513,7 +1516,12 @@ func (o *NB) ChassisGroupChassisAdd(haChassisGroupName OVNChassisGroup, chassisI

// Apply the changes.
if len(operations) > 0 {
_, err := o.client.Transact(ctx, operations...)
resp, err := o.client.Transact(ctx, operations...)
if err != nil {
return err
}

_, err = ovsdb.CheckOperationResults(resp, operations)
if err != nil {
return err
}
Expand Down
25 changes: 20 additions & 5 deletions internal/server/network/ovs/ovs_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (o *VSwitch) BridgeAdd(bridgeName string, mayExist bool, hwaddr net.Hardwar
port := ovsSwitch.Port{
UUID: "port",
Name: bridgeName,
Interfaces: []string{"interface"},
Interfaces: []string{iface.UUID},
}

portOps, err := o.client.Create(&port)
Expand Down Expand Up @@ -97,7 +97,7 @@ func (o *VSwitch) BridgeAdd(bridgeName string, mayExist bool, hwaddr net.Hardwar
return err
}

if bridge.UUID != "" {
if bridge.UUID != "bridge" {
// Bridge already exists.
return nil
}
Expand All @@ -121,7 +121,12 @@ func (o *VSwitch) BridgeAdd(bridgeName string, mayExist bool, hwaddr net.Hardwar
operations = append(operations, bridgeOps...)
operations = append(operations, mutateOps...)

_, err = o.client.Transact(ctx, operations...)
resp, err := o.client.Transact(ctx, operations...)
if err != nil {
return err
}

_, err = ovsdb.CheckOperationResults(resp, operations)
if err != nil {
return err
}
Expand Down Expand Up @@ -155,7 +160,12 @@ func (o *VSwitch) BridgeDelete(bridgeName string) error {
return err
}

_, err = o.client.Transact(ctx, operations...)
resp, err := o.client.Transact(ctx, operations...)
if err != nil {
return err
}

_, err = ovsdb.CheckOperationResults(resp, operations)
if err != nil {
return err
}
Expand Down Expand Up @@ -227,7 +237,12 @@ func (o *VSwitch) BridgePortAdd(bridgeName string, portName string, mayExist boo
operations := append(interfaceOps, portOps...)
operations = append(operations, mutateOps...)

_, err = o.client.Transact(ctx, operations...)
resp, err := o.client.Transact(ctx, operations...)
if err != nil {
return err
}

_, err = ovsdb.CheckOperationResults(resp, operations)
if err != nil {
return err
}
Expand Down
Loading