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
e8c45c74b3
commit
0841b6de90
10 changed files with 200 additions and 3 deletions
|
|
@ -145,4 +145,21 @@ func TestLoadConfig_ExempleFourniEstValide(t *testing.T) {
|
|||
if cfg.QEMU.QMPDir == "" {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue