Files
seaweedfs/seaweed-block/internal/testops/blockvolume_systemd_test.go
T

62 lines
1.8 KiB
Go

package testops
import (
"strings"
"testing"
)
// M2 restart: the shipped supervisor bounds retries after exit 75.
func TestBlockvolumeUnitsBoundStartupRetries(t *testing.T) {
for _, name := range []string{"sw-blockvolume.service", "sw-blockvolume@.service", "sw-blockvolume-ublk.service"} {
t.Run(name, func(t *testing.T) {
body := readRepoFile(t, "deploy", "systemd", name)
section := ""
seen := map[string]bool{}
for _, line := range strings.Split(body, "\n") {
line = strings.TrimSpace(line)
if strings.HasPrefix(line, "[") {
section = line
continue
}
key, value, ok := strings.Cut(line, "=")
if !ok {
continue
}
want, checked := map[string]string{"StartLimitIntervalSec": "600", "StartLimitBurst": "10"}[key]
if !checked {
continue
}
if seen[key] || section != "[Unit]" || value != want {
t.Errorf("%s: %s=%s in %s (duplicate=%t), want %s=%s once in [Unit]", name, key, value, section, seen[key], key, want)
}
seen[key] = true
}
for _, key := range []string{"StartLimitIntervalSec", "StartLimitBurst"} {
if !seen[key] {
t.Errorf("%s: missing [Unit] %s", name, key)
}
}
})
}
}
func TestBlockvolumeUnitsPreventRestartAfterRecordedRevocation(t *testing.T) {
for _, name := range []string{"sw-blockvolume.service", "sw-blockvolume@.service", "sw-blockvolume-ublk.service"} {
body := readRepoFile(t, "deploy", "systemd", name)
found := false
for _, line := range strings.Split(body, "\n") {
key, value, ok := strings.Cut(strings.TrimSpace(line), "=")
if ok && key == "RestartPreventExitStatus" {
for _, code := range strings.Fields(value) {
if code == "79" {
found = true
}
}
}
}
if !found {
t.Errorf("%s: recorded revocation exit 79 must prevent restart", name)
}
}
}