f-87: agent: bridge public = interfaces.internet, watchdog du segment #87

Le veth vp-<id>-e rejoint cfg.PublicBridge() (interfaces.internet, br-public
par défaut, jamais default_interface). Le watchdog signale un bridge public
absent, éteint ou sans port VXLAN. config.exemple.yml : internet: br-public.

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-10-25 23:36:14 +01:00
commit 26095062c8
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
10 changed files with 200 additions and 3 deletions

View file

@ -0,0 +1,39 @@
package watchdog
import (
"fmt"
configuration "git.g3e.fr/syonad/two/internal/config/agent"
"git.g3e.fr/syonad/two/internal/netif"
"git.g3e.fr/syonad/two/internal/watchdog/notify"
)
const kindPublic = "public"
type publicProbe interface {
LinkProblem(name string) string
VxlanPorts(bridge string) ([]string, error)
}
type systemPublicProbe struct{}
func (systemPublicProbe) LinkProblem(name string) string { return linkProblem(name) }
func (systemPublicProbe) VxlanPorts(bridge string) ([]string, error) {
return netif.BridgeVxlanPorts(bridge)
}
func CheckPublicSegment(cfg *configuration.Config, p publicProbe, n notify.Notifier) {
bridge := cfg.PublicBridge()
if problem := p.LinkProblem(bridge); problem != "" {
n.Notify(kindPublic, bridge, problem+" (public bridge, interfaces.internet): the vpcs of this host have no public segment")
return
}
ports, err := p.VxlanPorts(bridge)
switch {
case err != nil:
n.Notify(kindPublic, bridge, fmt.Sprintf("vxlan ports unreadable: %v", err))
case len(ports) == 0:
n.Notify(kindPublic, bridge, "no vxlan port: the public segment is unreachable from this host")
}
}

View file

@ -0,0 +1,77 @@
package watchdog
import (
"errors"
"testing"
configuration "git.g3e.fr/syonad/two/internal/config/agent"
)
type fakePublicProbe struct {
problems map[string]string
ports []string
err error
asked []string
}
func (f *fakePublicProbe) LinkProblem(name string) string {
f.asked = append(f.asked, name)
return f.problems[name]
}
func (f *fakePublicProbe) VxlanPorts(bridge string) ([]string, error) {
f.asked = append(f.asked, "ports:"+bridge)
return f.ports, f.err
}
func TestCheckPublicSegment_SilentWithAVxlanPort(t *testing.T) {
r := &recorder{}
p := &fakePublicProbe{ports: []string{"vxlan-public"}}
CheckPublicSegment(&configuration.Config{}, p, r)
if len(r.calls) != 0 {
t.Errorf("notifications = %+v, aucune attendue", r.calls)
}
if len(p.asked) != 2 || p.asked[0] != "br-public" || p.asked[1] != "ports:br-public" {
t.Errorf("sondes = %q, br-public attendu par défaut", p.asked)
}
}
func TestCheckPublicSegment_FollowsInterfacesInternet(t *testing.T) {
r := &recorder{}
p := &fakePublicProbe{ports: []string{"vxlan-public"}}
CheckPublicSegment(&configuration.Config{DefaultInterface: "br-000000", Interfaces: map[string]string{"internet": "br-wan"}}, p, r)
if len(p.asked) != 2 || p.asked[0] != "br-wan" || p.asked[1] != "ports:br-wan" {
t.Errorf("sondes = %q, br-wan attendu", p.asked)
}
}
func TestCheckPublicSegment_ReportsAMissingBridgeWithoutReadingPorts(t *testing.T) {
r := &recorder{}
p := &fakePublicProbe{problems: map[string]string{"br-public": "interface br-public not found: Link not found"}}
CheckPublicSegment(&configuration.Config{}, p, r)
got := r.forName("br-public")
want := "interface br-public not found: Link not found (public bridge, interfaces.internet): the vpcs of this host have no public segment"
if len(got) != 1 || got[0].kind != "public" || got[0].problem != want {
t.Fatalf("notifications = %+v, une attendue : %q", r.calls, want)
}
if len(p.asked) != 1 {
t.Errorf("ports lus alors que le bridge manque : %q", p.asked)
}
}
func TestCheckPublicSegment_ReportsABridgeWithoutVxlan(t *testing.T) {
r := &recorder{}
CheckPublicSegment(&configuration.Config{}, &fakePublicProbe{}, r)
got := r.forName("br-public")
if len(got) != 1 || got[0].problem != "no vxlan port: the public segment is unreachable from this host" {
t.Errorf("notifications = %+v", r.calls)
}
}
func TestCheckPublicSegment_ReportsUnreadablePorts(t *testing.T) {
r := &recorder{}
CheckPublicSegment(&configuration.Config{}, &fakePublicProbe{err: errors.New("netlink: permission denied")}, r)
if !r.hasProblemContaining("vxlan ports unreadable: netlink: permission denied") {
t.Errorf("notifications = %+v", r.calls)
}
}

View file

@ -23,6 +23,7 @@ type Watchdog struct {
interval time.Duration
dbusDown bool
l3 l3Probe
public publicProbe
}
func New(db *badger.DB, cfg *configuration.Config, n notify.Notifier, logger *slog.Logger, interval time.Duration) *Watchdog {
@ -41,6 +42,7 @@ func New(db *badger.DB, cfg *configuration.Config, n notify.Notifier, logger *sl
logger: logger,
interval: interval,
l3: systemProbe{frr: frr.NewClient()},
public: systemPublicProbe{},
}
}
@ -74,6 +76,7 @@ func (w *Watchdog) tick() {
if err := CheckVMs(w.db, w.cfg, u, w.notifier); err != nil {
w.logger.Error("watchdog: vm check failed", "err", err)
}
CheckPublicSegment(w.cfg, w.public, w.notifier)
CheckBGP(w.cfg, w.l3, w.notifier)
if err := CheckL3VPCs(w.db, w.cfg, w.l3, w.notifier); err != nil {
w.logger.Error("watchdog: l3 vpc check failed", "err", err)

View file

@ -74,6 +74,13 @@ func TestNew_IntervalleValideConserve(t *testing.T) {
}
}
func TestNew_ChecksThePublicSegmentOnTheSystem(t *testing.T) {
w := New(newTestDB(t), testCfg(t), &recorder{}, nil, time.Second)
if _, ok := w.public.(systemPublicProbe); !ok {
t.Errorf("sonde du segment public = %T, systemPublicProbe attendue", w.public)
}
}
func TestNew_LoggerNil(t *testing.T) {
w := New(newTestDB(t), testCfg(t), &recorder{}, nil, time.Second)
if w.logger == nil {
@ -141,6 +148,7 @@ func TestRun_ErreurDeBaseLogueeEtBoucleContinue(t *testing.T) {
n := newChanNotifier()
l, buf := testLogger()
w := New(db, testCfg(t), n, l, 10*time.Millisecond)
w.public = &fakePublicProbe{ports: []string{"vxlan-public"}}
ctx, cancel := context.WithTimeout(context.Background(), 300*time.Millisecond)
defer cancel()