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

[APP-7026] Handle rfkill, no-wifi-device cases #44

Merged
merged 1 commit into from
Nov 20, 2024
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.23.1

require (
github.com/Masterminds/semver/v3 v3.3.0
github.com/Otterverse/gonetworkmanager/v2 v2.2.0
github.com/Otterverse/gonetworkmanager/v2 v2.2.1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small patch over there to add GetPropertyRadioFlags()

github.com/google/uuid v1.6.0
github.com/jessevdk/go-flags v1.6.1
github.com/nightlyone/lockfile v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ github.com/Masterminds/sprig v2.15.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuN
github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/OpenPeeDeeP/depguard v1.0.1/go.mod h1:xsIw86fROiiwelg+jB2uM9PiKihMMmUx/1V+TNhjQvM=
github.com/Otterverse/gonetworkmanager/v2 v2.2.0 h1:aYEOjBO2I+OMORNpCBXqvVgzHcGks5MWmKv0JmrT5po=
github.com/Otterverse/gonetworkmanager/v2 v2.2.0/go.mod h1:Bc8kOugBgzCBC0R8oLa3wHnGet7k2ZpMHUobZtxlwhU=
github.com/Otterverse/gonetworkmanager/v2 v2.2.1 h1:yNov3VIkatRprIhCkoshWEeUG4pyNPJQMLHSFXqi09g=
github.com/Otterverse/gonetworkmanager/v2 v2.2.1/go.mod h1:Bc8kOugBgzCBC0R8oLa3wHnGet7k2ZpMHUobZtxlwhU=
github.com/PuerkitoBio/goquery v1.6.0/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
Expand Down
18 changes: 17 additions & 1 deletion subsystems/provisioning/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ type Provisioning struct {
monitorWorkers sync.WaitGroup

// blocks start/stop/etc operations
// holders of this lock must use HealthySleep to respond to HealthChecks from the parent agent during long operations
opMu sync.Mutex
running bool
disabled bool
Expand Down Expand Up @@ -95,6 +94,7 @@ func NewProvisioning(ctx context.Context, logger logging.Logger, updateConf *age
func (w *Provisioning) getNM() (gnm.NetworkManager, error) {
nmErr := errw.New("NetworkManager does not appear to be responding as expected. " +
"Please ensure NetworkManger >= v1.42 is installed and enabled. Disabling agent-provisioning until next restart.")
wifiErr := errw.New("No WiFi devices available. Disabling agent-provisioning until next restart.")

nm, err := gnm.NewNetworkManager()
if err != nil {
Expand Down Expand Up @@ -124,6 +124,18 @@ func (w *Provisioning) getNM() (gnm.NetworkManager, error) {
return nil, nmErr
}

flags, err := nm.GetPropertyRadioFlags()
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

w.noNM = true
w.logger.Error(err)
return nil, wifiErr
}

if flags&gnm.NmRadioFlagsWlanAvailable != gnm.NmRadioFlagsWlanAvailable {
w.noNM = true
return nil, wifiErr
}

return nm, nil
}

Expand Down Expand Up @@ -159,6 +171,10 @@ func (w *Provisioning) init(ctx context.Context) error {
return err
}

if err := w.enableWifi(ctx); err != nil {
return err
}

if err := w.initDevices(); err != nil {
return err
}
Expand Down
23 changes: 23 additions & 0 deletions subsystems/provisioning/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ package provisioning

import (
"bytes"
"context"
"errors"
"io/fs"
"os"
"time"

gnm "github.com/Otterverse/gonetworkmanager/v2"
errw "github.com/pkg/errors"
Expand Down Expand Up @@ -139,3 +141,24 @@ func (w *Provisioning) initDevices() error {

return nil
}

func (w *Provisioning) enableWifi(ctx context.Context) error {
if err := w.nm.SetPropertyWirelessEnabled(true); err != nil {
return err
}

timeoutCtx, cancel := context.WithTimeout(ctx, time.Second*10)
defer cancel()
for {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this loop the first scan fails and throws an error, as it takes a couple seconds for the radio to power on.

if !w.mainLoopHealth.Sleep(timeoutCtx, time.Second) {
return errw.Wrap(timeoutCtx.Err(), "enabling wifi")
}
enabled, err := w.nm.GetPropertyWirelessEnabled()
if err != nil {
return err
}
if enabled {
return nil
}
}
}
9 changes: 0 additions & 9 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,3 @@ func ConvertAttributes[T any](attributes *structpb.Struct) (*T, error) {

return newConfig, nil
}

func Sleep(ctx context.Context, timeout time.Duration) bool {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just drive-by cleanup. Nothing uses this anymore.

select {
case <-ctx.Done():
return false
case <-time.After(timeout):
return true
}
}