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

incusd/network/ovs: Wait for bridge interface to appear #518

Merged
merged 1 commit into from
Feb 22, 2024
Merged
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
21 changes: 16 additions & 5 deletions internal/server/network/ovs/ovs_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os/exec"
"strings"
"sync"
"time"

ovsdbClient "github.com/ovn-org/libovsdb/client"
ovsdbModel "github.com/ovn-org/libovsdb/model"
Expand All @@ -15,6 +16,7 @@ import (
"github.com/lxc/incus/internal/server/ip"
ovsSwitch "github.com/lxc/incus/internal/server/network/ovs/schema/ovs"
"github.com/lxc/incus/shared/subprocess"
"github.com/lxc/incus/shared/util"
)

// ovnBridgeMappingMutex locks access to read/write external-ids:ovn-bridge-mappings.
Expand Down Expand Up @@ -47,7 +49,7 @@ func (o *VSwitch) BridgeExists(bridgeName string) (bool, error) {
func (o *VSwitch) BridgeAdd(bridgeName string, mayExist bool, hwaddr net.HardwareAddr, mtu uint32) error {
ctx := context.TODO()

// Interface
// Create interface.
iface := ovsSwitch.Interface{
UUID: "interface",
Name: bridgeName,
Expand All @@ -63,7 +65,7 @@ func (o *VSwitch) BridgeAdd(bridgeName string, mayExist bool, hwaddr net.Hardwar
return err
}

// Port
// Create port.
port := ovsSwitch.Port{
UUID: "port",
Name: bridgeName,
Expand All @@ -75,7 +77,7 @@ func (o *VSwitch) BridgeAdd(bridgeName string, mayExist bool, hwaddr net.Hardwar
return err
}

// Bridge
// Create bridge.
bridge := ovsSwitch.Bridge{
UUID: "bridge",
Name: bridgeName,
Expand Down Expand Up @@ -103,7 +105,7 @@ func (o *VSwitch) BridgeAdd(bridgeName string, mayExist bool, hwaddr net.Hardwar
}
}

// Switch entry
// Create switch entry.
ovsRow := ovsSwitch.OpenvSwitch{
UUID: o.rootUUID,
}
Expand Down Expand Up @@ -131,7 +133,16 @@ func (o *VSwitch) BridgeAdd(bridgeName string, mayExist bool, hwaddr net.Hardwar
return err
}

return nil
// Wait for kernel interface to appear.
for i := 0; i < 50; i++ {
time.Sleep(100 * time.Millisecond)

if util.PathExists(fmt.Sprintf("/sys/class/net/%s", bridgeName)) {
return nil
}
}

return fmt.Errorf("Bridge interface failed to appear")
}

// BridgeDelete deletes a bridge.
Expand Down
Loading