f-41: l3vni: suppression d'une VPC routée sans section bgp #41
All checks were successful
Documentation / publish (push) Successful in 1m28s
Release Pipeline / set-release-target (push) Successful in 2s
Release Pipeline / upload-assets (agent.service, systemd/agent.service) (push) Successful in 7s
Release Pipeline / upload-assets (dhcp@.service, systemd/dhcp@.service) (push) Successful in 7s
Release Pipeline / upload-assets (dnsmasq@.service, systemd/dnsmasq@.service) (push) Successful in 7s
Release Pipeline / upload-assets (metadata@.service, systemd/metadata@.service) (push) Successful in 7s
Release Pipeline / upload-assets (run-dhcp-in-netns.sh, scripts/run-dhcp-in-netns.sh) (push) Successful in 7s
Release Pipeline / upload-assets (run-dnsmasq-in-netns.sh, scripts/run-dnsmasq-in-netns.sh) (push) Successful in 7s
Release Pipeline / build (agent, amd64, linux) (push) Successful in 0s
Release Pipeline / build (dhcp, amd64, linux) (push) Successful in 0s
Release Pipeline / build (metadata, amd64, linux) (push) Successful in 0s
Release Pipeline / checksums (push) Successful in 8s
Release Pipeline / build (push) Successful in 2m21s
Release Pipeline / release (push) Successful in 31s
Release Pipeline / publish (push) Successful in 0s

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-10-12 13:05:24 +02:00
commit eb89a2220c
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
9 changed files with 56 additions and 28 deletions

View file

@ -83,8 +83,8 @@ func (c *Client) RemoveVRF(v VRF) error {
}
func (c *Client) teardown(v VRF, plan func(VRF, string) []step) error {
if err := v.validateName(); err != nil {
return err
if v.ID == "" {
return fmt.Errorf("frr: vrf id must not be empty")
}
running, err := c.runningConfig()
if err != nil {

View file

@ -172,10 +172,10 @@ func TestRemoveVRFFailsWhenRoutingConfigurationIsStillThere(t *testing.T) {
}
}
func TestTeardownNeedsOnlyTheASNAndTheID(t *testing.T) {
func TestTeardownNeedsOnlyTheID(t *testing.T) {
f := &fakeVtysh{running: []string{"", ""}}
if err := f.client().WithdrawVRF(VRF{ASN: 64600, ID: "a1b2"}); err != nil {
t.Errorf("démontage refusé : %v", err)
if err := f.client().WithdrawVRF(VRF{ID: "a1b2"}); err != nil {
t.Errorf("démontage sans asn refusé : %v", err)
}
f = &fakeVtysh{}
if err := f.client().WithdrawVRF(VRF{ASN: 64600}); err == nil || len(f.calls) != 0 {

View file

@ -2,6 +2,7 @@ package frr
import (
"fmt"
"strconv"
"strings"
)
@ -9,16 +10,17 @@ type step []string
func routingTeardown(v VRF, running string) []step {
lines := strings.Split(running, "\n")
bgp := hasLine(lines, v.bgpInstance())
instance := vrfInstance(lines, v.Name())
bgp := instance != ""
var steps []step
if bgp {
steps = append(steps, step{v.bgpInstance(), "address-family ipv4 unicast", "no redistribute kernel"})
steps = append(steps, step{instance, "address-family ipv4 unicast", "no redistribute kernel"})
}
if vni := vrfVNI(lines, v.Name()); vni != "" {
steps = append(steps, step{"vrf " + v.Name(), "no vni " + vni})
}
if bgp {
steps = append(steps, step{"no " + v.bgpInstance()})
steps = append(steps, step{"no " + instance})
}
if hasPrefix(lines, "route-map "+v.routeMap()+" ") {
steps = append(steps, step{"no route-map " + v.routeMap()})
@ -36,6 +38,19 @@ func vrfTeardown(v VRF, running string) []step {
return nil
}
func vrfInstance(lines []string, name string) string {
for _, l := range lines {
f := strings.Fields(l)
if len(f) != 5 || f[0] != "router" || f[1] != "bgp" || f[3] != "vrf" || f[4] != name {
continue
}
if _, err := strconv.ParseUint(f[2], 10, 32); err == nil {
return strings.Join(f, " ")
}
}
return ""
}
func hasLine(lines []string, want string) bool {
for _, l := range lines {
if strings.TrimRight(l, " \r") == want {

View file

@ -97,6 +97,23 @@ func TestRoutingTeardownFollowsTheOrderFRRRequires(t *testing.T) {
}
}
func TestRoutingTeardownTakesTheASNOfTheInstanceFromFRR(t *testing.T) {
want := []step{
{"router bgp 64600 vrf vrf-a1b2", "address-family ipv4 unicast", "no redistribute kernel"},
{"vrf vrf-a1b2", "no vni 4001"},
{"no router bgp 64600 vrf vrf-a1b2"},
{"no route-map EXPORT-a1b2"},
{"no ip prefix-list PL-a1b2"},
}
for _, asn := range []uint32{0, 64601} {
v := labVRF(t)
v.ASN = asn
if got := routingTeardown(v, fullRunning); !reflect.DeepEqual(got, want) {
t.Errorf("asn %d :\n%q\nattendu :\n%q", asn, got, want)
}
}
}
func TestRoutingTeardownIgnoresAVRFWhoseNameExtendsOurs(t *testing.T) {
if got := routingTeardown(labVRF(t), otherOnlyRunning); got != nil {
t.Errorf("étapes visant vrf-a1b2c : %q", got)