-
Notifications
You must be signed in to change notification settings - Fork 4
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 { | ||
|
@@ -124,6 +124,18 @@ func (w *Provisioning) getNM() (gnm.NetworkManager, error) { | |
return nil, nmErr | ||
} | ||
|
||
flags, err := nm.GetPropertyRadioFlags() | ||
if err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
|
||
|
@@ -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 | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} | ||
} |
There was a problem hiding this comment.
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()