f-41: config, frr: base BGP pilotée par l'agent au démarrage #41

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-10-11 19:52:46 +02:00
commit bf0e83862f
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
12 changed files with 331 additions and 18 deletions

View file

@ -13,7 +13,9 @@ import (
agentapi "git.g3e.fr/syonad/two/internal/api/agent"
configuration "git.g3e.fr/syonad/two/internal/config/agent"
dispatcher "git.g3e.fr/syonad/two/internal/dispatcher/agent"
"git.g3e.fr/syonad/two/internal/frr"
"git.g3e.fr/syonad/two/internal/migration"
"git.g3e.fr/syonad/two/internal/netif"
agentmetrics "git.g3e.fr/syonad/two/internal/prometheus/agent"
"git.g3e.fr/syonad/two/internal/watchdog"
"git.g3e.fr/syonad/two/internal/watchdog/notify"
@ -58,6 +60,14 @@ func main() {
return
}
if cfg.BGP.Enabled() {
if err := applyBGPBase(cfg, frr.NewClient()); err != nil {
log.Error("failed to apply the bgp base configuration", "error", err)
return
}
log.Info("bgp base configuration applied", "asn", cfg.BGP.ASN, "route_reflectors", cfg.BGP.RouteReflectors)
}
q := worker.New(cfg.Worker.BufferSize)
q.Start(cfg.Worker.Count)
@ -110,6 +120,22 @@ func main() {
closeDB = shutdown(log, q, servers, shutdownTimeout)
}
type baseApplier interface {
ApplyBase(frr.Base) error
}
func applyBGPBase(cfg *configuration.Config, frrClient baseApplier) error {
reflectors, err := cfg.BGP.Reflectors()
if err != nil {
return err
}
vtep, err := netif.VTEPAddress(cfg.DefaultInterface)
if err != nil {
return err
}
return frrClient.ApplyBase(frr.Base{ASN: cfg.BGP.ASN, RouterID: vtep, RouteReflectors: reflectors})
}
type httpShutdowner interface {
Shutdown(context.Context) error
}

View file

@ -10,6 +10,8 @@ import (
"testing"
"time"
configuration "git.g3e.fr/syonad/two/internal/config/agent"
"git.g3e.fr/syonad/two/internal/frr"
"git.g3e.fr/syonad/two/pkg/worker"
)
@ -96,3 +98,22 @@ func TestShutdown_SansServeur(t *testing.T) {
t.Fatal("l'absence de serveur ne doit pas empêcher un arrêt propre")
}
}
type fakeBase struct{ called bool }
func (f *fakeBase) ApplyBase(frr.Base) error {
f.called = true
return nil
}
func TestApplyBGPBase_RefusesAnInvalidSectionBeforeTouchingFRR(t *testing.T) {
cfg := &configuration.Config{}
cfg.BGP.RouteReflectors = []string{"10.255.255.1"}
f := &fakeBase{}
if err := applyBGPBase(cfg, f); err == nil || !strings.Contains(err.Error(), "bgp.asn must be set") {
t.Errorf("erreur %v", err)
}
if f.called {
t.Error("ApplyBase appelé avec une section bgp invalide")
}
}