One capability per manager — uplink-networkmanager, uplink-systemd-networkd, uplink-dhcpcd — from systemctl is-active, so the uplink seat's holder for a manager this machine does not run is refused the way any missing capability is, naming it (issue 138). The apply that reports detects the profile again and sends it, the same shape enrolment sends, so a machine that switched managers reaches the mesh at its next push.
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package profile
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
// The uplink seat's holder must be the dialect the machine runs (novox/hq ADR 0161): the profile
|
|
// names the network manager found active, one capability per manager, and nothing for one that is
|
|
// merely installed.
|
|
func TestTheProfileNamesTheNetworkManagerThatIsRunning(t *testing.T) {
|
|
runner := func(_ context.Context, name string, args ...string) (string, error) {
|
|
if name == "systemctl" && len(args) == 2 && args[0] == "is-active" {
|
|
if args[1] == "NetworkManager.service" {
|
|
return "active\n", nil
|
|
}
|
|
return "inactive\n", errors.New("exit status 3")
|
|
}
|
|
return "", errors.New("not here")
|
|
}
|
|
var have []Detector
|
|
for _, d := range Default(Runner(runner)) {
|
|
switch d.Name() {
|
|
case CapUplinkNetworkManager, CapUplinkSystemdNetworkd, CapUplinkDhcpcd:
|
|
have = append(have, d)
|
|
}
|
|
}
|
|
if len(have) != 3 {
|
|
t.Fatalf("expected a detector per manager, found %d", len(have))
|
|
}
|
|
for _, d := range have {
|
|
v := d.Detect(context.Background())
|
|
want := d.Name() == CapUplinkNetworkManager
|
|
if v.Present != want {
|
|
t.Errorf("%s: present=%v, want %v (%s)", d.Name(), v.Present, want, v.Detail)
|
|
}
|
|
}
|
|
}
|