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:
parent
7535e068b9
commit
26095062c8
10 changed files with 200 additions and 3 deletions
|
|
@ -39,10 +39,12 @@ times:
|
||||||
# Bridge interface used when the requested iface_type is not found in interfaces
|
# Bridge interface used when the requested iface_type is not found in interfaces
|
||||||
default_interface: br-000000
|
default_interface: br-000000
|
||||||
|
|
||||||
# Map of logical interface types to physical bridge names on this host
|
# Map of logical interface types to physical bridge names on this host.
|
||||||
|
# internet: public bridge, carrying vxlan-public (deploy.sh --public_vni); every VPC
|
||||||
|
# plugs its vp-<id>-e veth into it. br-public when absent, never default_interface.
|
||||||
interfaces:
|
interfaces:
|
||||||
vms: br-000000
|
vms: br-000000
|
||||||
internet: br-000000
|
internet: br-public
|
||||||
admin: br-000000
|
admin: br-000000
|
||||||
|
|
||||||
# MTU, identical on every hypervisor.
|
# MTU, identical on every hypervisor.
|
||||||
|
|
|
||||||
|
|
@ -145,4 +145,21 @@ func TestLoadConfig_ExempleFourniEstValide(t *testing.T) {
|
||||||
if cfg.QEMU.QMPDir == "" {
|
if cfg.QEMU.QMPDir == "" {
|
||||||
t.Error("config.exemple.yml devrait définir qemu.qmp_dir")
|
t.Error("config.exemple.yml devrait définir qemu.qmp_dir")
|
||||||
}
|
}
|
||||||
|
if got := cfg.PublicBridge(); got != "br-public" {
|
||||||
|
t.Errorf("config.exemple.yml : bridge public %q, br-public attendu", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLoadConfig_PublicBridgeWithoutInternetKey(t *testing.T) {
|
||||||
|
path := filepath.Join(t.TempDir(), "agent.yml")
|
||||||
|
if err := os.WriteFile(path, []byte("default_interface: br-000000\ninterfaces:\n lan: br-lan\n"), 0o600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
cfg, err := LoadConfig(path)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("LoadConfig : %v", err)
|
||||||
|
}
|
||||||
|
if got := cfg.PublicBridge(); got != "br-public" {
|
||||||
|
t.Errorf("bridge public %q, br-public attendu (jamais default_interface)", got)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
13
internal/config/agent/interfaces.go
Normal file
13
internal/config/agent/interfaces.go
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
package configuration
|
||||||
|
|
||||||
|
const (
|
||||||
|
InternetInterface = "internet"
|
||||||
|
DefaultPublicBridge = "br-public"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c Config) PublicBridge() string {
|
||||||
|
if bridge := c.Interfaces[InternetInterface]; bridge != "" {
|
||||||
|
return bridge
|
||||||
|
}
|
||||||
|
return DefaultPublicBridge
|
||||||
|
}
|
||||||
20
internal/config/agent/interfaces_test.go
Normal file
20
internal/config/agent/interfaces_test.go
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
package configuration
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestPublicBridge(t *testing.T) {
|
||||||
|
cases := map[string]struct {
|
||||||
|
cfg Config
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
"clé absente": {Config{DefaultInterface: "br-000000"}, "br-public"},
|
||||||
|
"clé vide": {Config{DefaultInterface: "br-000000", Interfaces: map[string]string{"internet": ""}}, "br-public"},
|
||||||
|
"clé posée": {Config{Interfaces: map[string]string{"internet": "br-wan"}}, "br-wan"},
|
||||||
|
"autres types, sans default_interface en repli": {Config{DefaultInterface: "br-000000", Interfaces: map[string]string{"lan": "br-lan"}}, "br-public"},
|
||||||
|
}
|
||||||
|
for name, c := range cases {
|
||||||
|
if got := c.cfg.PublicBridge(); got != c.want {
|
||||||
|
t.Errorf("%s : %q, %q attendu", name, got, c.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -46,3 +46,21 @@ func LinkMTU(name string) (int, error) {
|
||||||
}
|
}
|
||||||
return link.Attrs().MTU, nil
|
return link.Attrs().MTU, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BridgeVxlanPorts(bridge string) ([]string, error) {
|
||||||
|
br, err := netlink.LinkByName(bridge)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
links, err := netlink.LinkList()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var ports []string
|
||||||
|
for _, l := range links {
|
||||||
|
if l.Attrs().MasterIndex == br.Attrs().Index && l.Type() == "vxlan" {
|
||||||
|
ports = append(ports, l.Attrs().Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ports, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ func CreateVPC(db *badger.DB, name string, cfg *configuration.Config) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := netif.BridgeSetMaster("vp-"+vpcID+"-e", "br-public"); err != nil {
|
if err := netif.BridgeSetMaster("vp-"+vpcID+"-e", cfg.PublicBridge()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
39
internal/watchdog/check_public.go
Normal file
39
internal/watchdog/check_public.go
Normal 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")
|
||||||
|
}
|
||||||
|
}
|
||||||
77
internal/watchdog/check_public_test.go
Normal file
77
internal/watchdog/check_public_test.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -23,6 +23,7 @@ type Watchdog struct {
|
||||||
interval time.Duration
|
interval time.Duration
|
||||||
dbusDown bool
|
dbusDown bool
|
||||||
l3 l3Probe
|
l3 l3Probe
|
||||||
|
public publicProbe
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(db *badger.DB, cfg *configuration.Config, n notify.Notifier, logger *slog.Logger, interval time.Duration) *Watchdog {
|
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,
|
logger: logger,
|
||||||
interval: interval,
|
interval: interval,
|
||||||
l3: systemProbe{frr: frr.NewClient()},
|
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 {
|
if err := CheckVMs(w.db, w.cfg, u, w.notifier); err != nil {
|
||||||
w.logger.Error("watchdog: vm check failed", "err", err)
|
w.logger.Error("watchdog: vm check failed", "err", err)
|
||||||
}
|
}
|
||||||
|
CheckPublicSegment(w.cfg, w.public, w.notifier)
|
||||||
CheckBGP(w.cfg, w.l3, w.notifier)
|
CheckBGP(w.cfg, w.l3, w.notifier)
|
||||||
if err := CheckL3VPCs(w.db, w.cfg, w.l3, w.notifier); err != nil {
|
if err := CheckL3VPCs(w.db, w.cfg, w.l3, w.notifier); err != nil {
|
||||||
w.logger.Error("watchdog: l3 vpc check failed", "err", err)
|
w.logger.Error("watchdog: l3 vpc check failed", "err", err)
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
func TestNew_LoggerNil(t *testing.T) {
|
||||||
w := New(newTestDB(t), testCfg(t), &recorder{}, nil, time.Second)
|
w := New(newTestDB(t), testCfg(t), &recorder{}, nil, time.Second)
|
||||||
if w.logger == nil {
|
if w.logger == nil {
|
||||||
|
|
@ -141,6 +148,7 @@ func TestRun_ErreurDeBaseLogueeEtBoucleContinue(t *testing.T) {
|
||||||
n := newChanNotifier()
|
n := newChanNotifier()
|
||||||
l, buf := testLogger()
|
l, buf := testLogger()
|
||||||
w := New(db, testCfg(t), n, l, 10*time.Millisecond)
|
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)
|
ctx, cancel := context.WithTimeout(context.Background(), 300*time.Millisecond)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue