f-62: vm: MAC fournie à la création par interface, fin de la table préchargée, migration #62
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
c26606787e
commit
077141443e
20 changed files with 338 additions and 171 deletions
|
|
@ -17,35 +17,6 @@ func parseNet(t *testing.T, cidr string) *net.IPNet {
|
|||
return network
|
||||
}
|
||||
|
||||
// --- cloneIP ---
|
||||
|
||||
func TestCloneIP_IsIndependent(t *testing.T) {
|
||||
ip := net.ParseIP("10.0.0.1").To4()
|
||||
clone := cloneIP(ip)
|
||||
clone[3] = 99
|
||||
if ip[3] == 99 {
|
||||
t.Error("cloneIP devrait retourner une copie indépendante")
|
||||
}
|
||||
}
|
||||
|
||||
// --- incrementIP ---
|
||||
|
||||
func TestIncrementIP_Simple(t *testing.T) {
|
||||
ip := net.ParseIP("10.0.0.1").To4()
|
||||
incrementIP(ip)
|
||||
if ip.String() != "10.0.0.2" {
|
||||
t.Errorf("attendu 10.0.0.2, obtenu %s", ip)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIncrementIP_Carry(t *testing.T) {
|
||||
ip := net.ParseIP("10.0.0.255").To4()
|
||||
incrementIP(ip)
|
||||
if ip.String() != "10.0.1.0" {
|
||||
t.Errorf("attendu 10.0.1.0, obtenu %s", ip)
|
||||
}
|
||||
}
|
||||
|
||||
// --- GenerateConfig ---
|
||||
|
||||
func newConf(t *testing.T, cidr string) Config {
|
||||
|
|
@ -65,7 +36,7 @@ func newConf(t *testing.T, cidr string) Config {
|
|||
|
||||
func TestGenerateConfig_CreatesFile(t *testing.T) {
|
||||
conf := newConf(t, "192.168.1.0/29") // 6 hôtes
|
||||
path, _, err := GenerateConfig(conf)
|
||||
path, err := GenerateConfig(conf)
|
||||
if err != nil {
|
||||
t.Fatalf("GenerateConfig a échoué : %v", err)
|
||||
}
|
||||
|
|
@ -77,7 +48,7 @@ func TestGenerateConfig_CreatesFile(t *testing.T) {
|
|||
|
||||
func TestGenerateConfig_FilenameMatchesName(t *testing.T) {
|
||||
conf := newConf(t, "192.168.1.0/29")
|
||||
path, _, err := GenerateConfig(conf)
|
||||
path, err := GenerateConfig(conf)
|
||||
if err != nil {
|
||||
t.Fatalf("GenerateConfig a échoué : %v", err)
|
||||
}
|
||||
|
|
@ -90,7 +61,7 @@ func TestGenerateConfig_FilenameMatchesName(t *testing.T) {
|
|||
|
||||
func TestGenerateConfig_ContainsDefaultGateway(t *testing.T) {
|
||||
conf := newConf(t, "192.168.1.0/29")
|
||||
path, _, _ := GenerateConfig(conf)
|
||||
path, _ := GenerateConfig(conf)
|
||||
content, _ := os.ReadFile(path)
|
||||
|
||||
if !strings.Contains(string(content), "dhcp-option=3,192.168.1.1") {
|
||||
|
|
@ -101,7 +72,7 @@ func TestGenerateConfig_ContainsDefaultGateway(t *testing.T) {
|
|||
func TestGenerateConfig_NoDefaultGateway(t *testing.T) {
|
||||
conf := newConf(t, "192.168.1.0/29")
|
||||
conf.DefaultGateway = nil
|
||||
path, _, _ := GenerateConfig(conf)
|
||||
path, _ := GenerateConfig(conf)
|
||||
content, _ := os.ReadFile(path)
|
||||
|
||||
if strings.Contains(string(content), "dhcp-option=3,") {
|
||||
|
|
@ -112,7 +83,7 @@ func TestGenerateConfig_NoDefaultGateway(t *testing.T) {
|
|||
func TestGenerateConfig_NoDefaultGatewaySuppressesRouterOption(t *testing.T) {
|
||||
conf := newConf(t, "192.168.1.0/29")
|
||||
conf.DefaultGateway = nil
|
||||
path, _, _ := GenerateConfig(conf)
|
||||
path, _ := GenerateConfig(conf)
|
||||
content, _ := os.ReadFile(path)
|
||||
|
||||
if !strings.Contains(string(content), "\ndhcp-option=3\n") {
|
||||
|
|
@ -127,7 +98,7 @@ func TestGenerateConfig_NilDefaultGatewayEmitsNoRoute(t *testing.T) {
|
|||
conf := newConf(t, "192.168.1.0/29")
|
||||
conf.DefaultGateway = nil
|
||||
|
||||
path, _, _ := GenerateConfig(conf)
|
||||
path, _ := GenerateConfig(conf)
|
||||
content, _ := os.ReadFile(path)
|
||||
|
||||
if !strings.Contains(string(content), "dhcp-option=121,") {
|
||||
|
|
@ -163,7 +134,7 @@ func TestGenerateConfig_ContainsDhcpRange(t *testing.T) {
|
|||
Name: "vpc1",
|
||||
ConfDir: t.TempDir(),
|
||||
}
|
||||
path, _, _ := GenerateConfig(conf)
|
||||
path, _ := GenerateConfig(conf)
|
||||
content, _ := os.ReadFile(path)
|
||||
|
||||
if !strings.Contains(string(content), "dhcp-range=10.10.0.0,static,255.255.255.0,12h") {
|
||||
|
|
@ -171,18 +142,6 @@ func TestGenerateConfig_ContainsDhcpRange(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGenerateConfig_OneEntryPerIP(t *testing.T) {
|
||||
// /29 = 8 adresses. Les entrées ne vont plus dans le fichier dnsmasq mais
|
||||
// dans la map retournée, que StoreDHCPEntries écrit en base pour GetMACForIP.
|
||||
_, entries, err := GenerateConfig(newConf(t, "10.0.0.0/29"))
|
||||
if err != nil {
|
||||
t.Fatalf("GenerateConfig : %v", err)
|
||||
}
|
||||
if len(entries) != 8 {
|
||||
t.Errorf("attendu 8 entrées ip->mac, obtenu %d", len(entries))
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateConfig_NoPreGeneratedHosts(t *testing.T) {
|
||||
// Une entrée dhcp-host pré-générée fait rejeter celle du dhcp-hostsdir
|
||||
// (« duplicate dhcp-host IP address »), sans erreur : la VM reçoit alors
|
||||
|
|
@ -212,18 +171,6 @@ func TestGenerateConfig_PointsToDirs(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGenerateConfig_MACPrefix(t *testing.T) {
|
||||
_, entries, err := GenerateConfig(newConf(t, "10.0.0.0/30"))
|
||||
if err != nil {
|
||||
t.Fatalf("GenerateConfig : %v", err)
|
||||
}
|
||||
for ip, mac := range entries {
|
||||
if !strings.HasPrefix(mac, "00:22:33:") {
|
||||
t.Errorf("mac de %s sans le préfixe 00:22:33: : %s", ip, mac)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateConfig_CreatesConfDir(t *testing.T) {
|
||||
dir := filepath.Join(t.TempDir(), "sous", "dossier")
|
||||
_, network, _ := net.ParseCIDR("10.0.0.0/30")
|
||||
|
|
@ -233,7 +180,7 @@ func TestGenerateConfig_CreatesConfDir(t *testing.T) {
|
|||
Name: "net",
|
||||
ConfDir: dir,
|
||||
}
|
||||
if _, _, err := GenerateConfig(conf); err != nil {
|
||||
if _, err := GenerateConfig(conf); err != nil {
|
||||
t.Fatalf("GenerateConfig devrait créer les répertoires manquants : %v", err)
|
||||
}
|
||||
if _, err := os.Stat(dir); os.IsNotExist(err) {
|
||||
|
|
@ -245,7 +192,7 @@ func TestGenerateConfig_CreatesConfDir(t *testing.T) {
|
|||
|
||||
func confLines(t *testing.T, c Config) string {
|
||||
t.Helper()
|
||||
path, _, err := GenerateConfig(c)
|
||||
path, err := GenerateConfig(c)
|
||||
if err != nil {
|
||||
t.Fatalf("GenerateConfig : %v", err)
|
||||
}
|
||||
|
|
@ -312,7 +259,7 @@ func TestGenerateConfig_MissingInterfaceIPIsAnError(t *testing.T) {
|
|||
conf := newConf(t, "192.168.1.0/29")
|
||||
conf.InterfaceIP = nil
|
||||
|
||||
if _, _, err := GenerateConfig(conf); err == nil {
|
||||
if _, err := GenerateConfig(conf); err == nil {
|
||||
t.Error("sans interface_ip aucune route metadata n'est possible : il faut échouer, pas écrire une conf muette")
|
||||
}
|
||||
}
|
||||
|
|
@ -321,7 +268,7 @@ func TestGenerateConfig_ListensOnTheAnycastGateway(t *testing.T) {
|
|||
conf := newConf(t, "192.168.1.0/29")
|
||||
conf.Listen = "gw-s9r1"
|
||||
conf.Except = "br-s9r1"
|
||||
path, _, _ := GenerateConfig(conf)
|
||||
path, _ := GenerateConfig(conf)
|
||||
content, _ := os.ReadFile(path)
|
||||
|
||||
for _, line := range []string{"\ninterface=gw-s9r1\n", "\nexcept-interface=br-s9r1\n"} {
|
||||
|
|
@ -333,7 +280,7 @@ func TestGenerateConfig_ListensOnTheAnycastGateway(t *testing.T) {
|
|||
|
||||
func TestGenerateConfig_NoInterfaceLinesByDefault(t *testing.T) {
|
||||
conf := newConf(t, "192.168.1.0/29")
|
||||
path, _, _ := GenerateConfig(conf)
|
||||
path, _ := GenerateConfig(conf)
|
||||
content, _ := os.ReadFile(path)
|
||||
|
||||
if strings.Contains(string(content), "interface=") {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue