Skip to content
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
16 changes: 11 additions & 5 deletions mr/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ func plan(c *Config) (*Plan, error) {
return nil, err
}
files = append(files, appliedFiles(c)...)
want := map[string]bool{}
for _, s := range enabledServices(c) {
want[s] = true
}
// a service mr owns that this config does not run is disabled, never restarted: e.g. mr-hostapd on
// a machine without radios, whose generated files are new on the first apply like all others
off := map[string]bool{}
for _, s := range managedServices(c) {
off[s] = !want[s]
}
p := &Plan{}
svc := map[string]bool{}
for _, f := range files {
Expand All @@ -174,7 +184,7 @@ func plan(c *Config) (*Plan, error) {
continue
}
p.Changed = append(p.Changed, f)
if s := serviceFor(f.Path); s != "" {
if s := serviceFor(f.Path); s != "" && !off[s] {
svc[s] = true
}
}
Expand All @@ -186,10 +196,6 @@ func plan(c *Config) (*Plan, error) {
cur, _ := os.ReadFile(GenDir + "/nftables.nft")
p.Firewall = string(cur) != renderNft(c, netdevExists)

want := map[string]bool{}
for _, s := range enabledServices(c) {
want[s] = true
}
have := map[string]bool{}
if ents, err := os.ReadDir(runlevelDir); err == nil {
for _, e := range ents {
Expand Down
32 changes: 32 additions & 0 deletions mr/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/fs"
"os"
"path/filepath"
"slices"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -607,3 +608,34 @@ func TestRenderOutputIncludesAppliedConfigBookkeeping(t *testing.T) {
t.Fatalf("render output missing bookkeeping: %v", seen)
}
}

// A machine without WiFi (a VM, most x86 boxes): the first apply writes wifi-post.sh like every other
// generated file, but the config runs no mr-hostapd. Restarting it failed ("no hostapd config for an
// existing radio") and rolled back install.sh on every such machine.
func TestPlanDoesNotRestartServicesTheConfigDoesNotRun(t *testing.T) {
confirmEnv(t)
c := testConfig(t)
if len(c.WiFi.Radios) == 0 {
t.Fatal("the home config has no radios")
}
p, err := plan(c)
if err != nil {
t.Fatal(err)
}
if !slices.Contains(p.Services, "mr-hostapd") {
t.Fatalf("with radios, a new hostapd config restarts mr-hostapd: %v", p.Services)
}
c.WiFi.Radios = nil
if p, err = plan(c); err != nil {
t.Fatal(err)
}
if slices.Contains(p.Services, "mr-hostapd") {
t.Fatalf("without radios mr-hostapd must not be restarted: %v", p.Services)
}
if !slices.ContainsFunc(p.Changed, func(f File) bool { return f.Path == GenDir+"/wifi-post.sh" }) {
t.Fatal("wifi-post.sh is still written")
}
if !slices.Contains(p.Services, "mr-network") {
t.Fatalf("the other services still restart: %v", p.Services)
}
}
Loading