f-41: l3vni: suppression d'une VPC routée sans section bgp #41
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
7ec298fcc1
commit
0679639b95
9 changed files with 56 additions and 28 deletions
|
|
@ -50,7 +50,8 @@ Avec une section ``bgp`` dans la configuration, il contrôle aussi le plan de co
|
||||||
le propriétaire n'existe plus — ni ``running``, ni en ``creating``, ``deleting`` ou ``error`` —
|
le propriétaire n'existe plus — ni ``running``, ni en ``creating``, ``deleting`` ou ``error`` —
|
||||||
est signalée comme un **trou noir** : l'annonce attire du trafic que plus rien ne reçoit.
|
est signalée comme un **trou noir** : l'annonce attire du trafic que plus rien ne reçoit.
|
||||||
|
|
||||||
Un VPC routé alors que la section ``bgp`` a disparu de la configuration est signalé lui aussi.
|
Un VPC routé alors que la section ``bgp`` a disparu de la configuration est signalé lui aussi. Il
|
||||||
|
reste supprimable : le démontage lit l'AS de son instance dans la configuration courante de FRR.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ func (c DeleteVPCCommand) Execute(db *badger.DB, cfg *configuration.Config) erro
|
||||||
case <-time.After(time.Duration(cfg.Dispatcher.PollSeconds) * time.Second):
|
case <-time.After(time.Duration(cfg.Dispatcher.PollSeconds) * time.Second):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := vpc.DeleteVPC(db, c.Name, cfg); err != nil {
|
if err := vpc.DeleteVPC(db, c.Name); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
current, err := state.Get(db, c.Key())
|
current, err := state.Get(db, c.Key())
|
||||||
|
|
|
||||||
|
|
@ -83,8 +83,8 @@ func (c *Client) RemoveVRF(v VRF) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) teardown(v VRF, plan func(VRF, string) []step) error {
|
func (c *Client) teardown(v VRF, plan func(VRF, string) []step) error {
|
||||||
if err := v.validateName(); err != nil {
|
if v.ID == "" {
|
||||||
return err
|
return fmt.Errorf("frr: vrf id must not be empty")
|
||||||
}
|
}
|
||||||
running, err := c.runningConfig()
|
running, err := c.runningConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -172,10 +172,10 @@ func TestRemoveVRFFailsWhenRoutingConfigurationIsStillThere(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTeardownNeedsOnlyTheASNAndTheID(t *testing.T) {
|
func TestTeardownNeedsOnlyTheID(t *testing.T) {
|
||||||
f := &fakeVtysh{running: []string{"", ""}}
|
f := &fakeVtysh{running: []string{"", ""}}
|
||||||
if err := f.client().WithdrawVRF(VRF{ASN: 64600, ID: "a1b2"}); err != nil {
|
if err := f.client().WithdrawVRF(VRF{ID: "a1b2"}); err != nil {
|
||||||
t.Errorf("démontage refusé : %v", err)
|
t.Errorf("démontage sans asn refusé : %v", err)
|
||||||
}
|
}
|
||||||
f = &fakeVtysh{}
|
f = &fakeVtysh{}
|
||||||
if err := f.client().WithdrawVRF(VRF{ASN: 64600}); err == nil || len(f.calls) != 0 {
|
if err := f.client().WithdrawVRF(VRF{ASN: 64600}); err == nil || len(f.calls) != 0 {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package frr
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -9,16 +10,17 @@ type step []string
|
||||||
|
|
||||||
func routingTeardown(v VRF, running string) []step {
|
func routingTeardown(v VRF, running string) []step {
|
||||||
lines := strings.Split(running, "\n")
|
lines := strings.Split(running, "\n")
|
||||||
bgp := hasLine(lines, v.bgpInstance())
|
instance := vrfInstance(lines, v.Name())
|
||||||
|
bgp := instance != ""
|
||||||
var steps []step
|
var steps []step
|
||||||
if bgp {
|
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 != "" {
|
if vni := vrfVNI(lines, v.Name()); vni != "" {
|
||||||
steps = append(steps, step{"vrf " + v.Name(), "no vni " + vni})
|
steps = append(steps, step{"vrf " + v.Name(), "no vni " + vni})
|
||||||
}
|
}
|
||||||
if bgp {
|
if bgp {
|
||||||
steps = append(steps, step{"no " + v.bgpInstance()})
|
steps = append(steps, step{"no " + instance})
|
||||||
}
|
}
|
||||||
if hasPrefix(lines, "route-map "+v.routeMap()+" ") {
|
if hasPrefix(lines, "route-map "+v.routeMap()+" ") {
|
||||||
steps = append(steps, step{"no 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
|
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 {
|
func hasLine(lines []string, want string) bool {
|
||||||
for _, l := range lines {
|
for _, l := range lines {
|
||||||
if strings.TrimRight(l, " \r") == want {
|
if strings.TrimRight(l, " \r") == want {
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
func TestRoutingTeardownIgnoresAVRFWhoseNameExtendsOurs(t *testing.T) {
|
||||||
if got := routingTeardown(labVRF(t), otherOnlyRunning); got != nil {
|
if got := routingTeardown(labVRF(t), otherOnlyRunning); got != nil {
|
||||||
t.Errorf("étapes visant vrf-a1b2c : %q", got)
|
t.Errorf("étapes visant vrf-a1b2c : %q", got)
|
||||||
|
|
|
||||||
|
|
@ -115,12 +115,8 @@ func createL3(h host, cfg *configuration.Config, v l3VPC) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteL3(h host, cfg *configuration.Config, v l3VPC) error {
|
func deleteL3(h host, v l3VPC) error {
|
||||||
asn, err := bgpASN(cfg)
|
frrVRF := frr.VRF{ID: v.id}
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
frrVRF := frr.VRF{ASN: asn, ID: v.id}
|
|
||||||
if err := h.WithdrawVRF(frrVRF); err != nil {
|
if err := h.WithdrawVRF(frrVRF); err != nil {
|
||||||
return fmt.Errorf("l3vni %d: withdraw frr: %w", v.vni, err)
|
return fmt.Errorf("l3vni %d: withdraw frr: %w", v.vni, err)
|
||||||
}
|
}
|
||||||
|
|
@ -143,12 +139,12 @@ func Create(db *badger.DB, vpcName string, cfg *configuration.Config) error {
|
||||||
return createL3(newSystem(), cfg, v)
|
return createL3(newSystem(), cfg, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Delete(db *badger.DB, vpcName string, cfg *configuration.Config) error {
|
func Delete(db *badger.DB, vpcName string) error {
|
||||||
v, ok, err := loadRouted(db, vpcName)
|
v, ok, err := loadRouted(db, vpcName)
|
||||||
if err != nil || !ok {
|
if err != nil || !ok {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return deleteL3(newSystem(), cfg, v)
|
return deleteL3(newSystem(), v)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Routing struct {
|
type Routing struct {
|
||||||
|
|
|
||||||
|
|
@ -173,16 +173,16 @@ func TestCreateL3StopsAtTheFirstFailure(t *testing.T) {
|
||||||
|
|
||||||
func TestDeleteL3WithdrawsFRRThenTheKernelThenTheVRF(t *testing.T) {
|
func TestDeleteL3WithdrawsFRRThenTheKernelThenTheVRF(t *testing.T) {
|
||||||
f := &fakeHost{}
|
f := &fakeHost{}
|
||||||
if err := deleteL3(f, bgpConfig(), labL3(t)); err != nil {
|
if err := deleteL3(f, labL3(t)); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
want := []string{
|
want := []string{
|
||||||
"frr withdraw asn=64600 id=s7 vni=0",
|
"frr withdraw asn=0 id=s7 vni=0",
|
||||||
"del l3-s7-o",
|
"del l3-s7-o",
|
||||||
"del vxl3-s7",
|
"del vxl3-s7",
|
||||||
"del brl3-s7",
|
"del brl3-s7",
|
||||||
"del vrf-s7",
|
"del vrf-s7",
|
||||||
"frr remove asn=64600 id=s7 vni=0",
|
"frr remove asn=0 id=s7 vni=0",
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(f.calls, want) {
|
if !reflect.DeepEqual(f.calls, want) {
|
||||||
t.Errorf("appels :\n%s\nattendu :\n%s", strings.Join(f.calls, "\n"), strings.Join(want, "\n"))
|
t.Errorf("appels :\n%s\nattendu :\n%s", strings.Join(f.calls, "\n"), strings.Join(want, "\n"))
|
||||||
|
|
@ -191,7 +191,7 @@ func TestDeleteL3WithdrawsFRRThenTheKernelThenTheVRF(t *testing.T) {
|
||||||
|
|
||||||
func TestDeleteL3KeepsTheKernelWhenFRRRefusesTheWithdrawal(t *testing.T) {
|
func TestDeleteL3KeepsTheKernelWhenFRRRefusesTheWithdrawal(t *testing.T) {
|
||||||
f := &fakeHost{fail: map[string]error{"frr withdraw": errors.New("% Please unconfigure l3vni 2700")}}
|
f := &fakeHost{fail: map[string]error{"frr withdraw": errors.New("% Please unconfigure l3vni 2700")}}
|
||||||
err := deleteL3(f, bgpConfig(), labL3(t))
|
err := deleteL3(f, labL3(t))
|
||||||
if err == nil || !strings.Contains(err.Error(), "withdraw frr") {
|
if err == nil || !strings.Contains(err.Error(), "withdraw frr") {
|
||||||
t.Errorf("erreur %v", err)
|
t.Errorf("erreur %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -202,7 +202,7 @@ func TestDeleteL3KeepsTheKernelWhenFRRRefusesTheWithdrawal(t *testing.T) {
|
||||||
|
|
||||||
func TestDeleteL3KeepsTheFRRVRFWhenAKernelLinkCannotBeDeleted(t *testing.T) {
|
func TestDeleteL3KeepsTheFRRVRFWhenAKernelLinkCannotBeDeleted(t *testing.T) {
|
||||||
f := &fakeHost{fail: map[string]error{"del brl3-s7": errors.New("device busy")}}
|
f := &fakeHost{fail: map[string]error{"del brl3-s7": errors.New("device busy")}}
|
||||||
if err := deleteL3(f, bgpConfig(), labL3(t)); err == nil || !strings.Contains(err.Error(), "delete brl3-s7") {
|
if err := deleteL3(f, labL3(t)); err == nil || !strings.Contains(err.Error(), "delete brl3-s7") {
|
||||||
t.Errorf("erreur %v", err)
|
t.Errorf("erreur %v", err)
|
||||||
}
|
}
|
||||||
for _, c := range f.calls {
|
for _, c := range f.calls {
|
||||||
|
|
@ -212,9 +212,9 @@ func TestDeleteL3KeepsTheFRRVRFWhenAKernelLinkCannotBeDeleted(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeleteL3RequiresTheBGPSection(t *testing.T) {
|
func TestDeleteL3DoesNotDependOnTheAgentBGPSection(t *testing.T) {
|
||||||
f := &fakeHost{}
|
f := &fakeHost{}
|
||||||
if err := deleteL3(f, &configuration.Config{}, labL3(t)); err == nil || len(f.calls) != 0 {
|
if err := deleteL3(f, labL3(t)); err != nil || len(f.calls) != 6 {
|
||||||
t.Errorf("erreur %v, appels %q", err, f.calls)
|
t.Errorf("erreur %v, appels %q", err, f.calls)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package vpc
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
configuration "git.g3e.fr/syonad/two/internal/config/agent"
|
|
||||||
"git.g3e.fr/syonad/two/internal/l3vni"
|
"git.g3e.fr/syonad/two/internal/l3vni"
|
||||||
"git.g3e.fr/syonad/two/internal/netif"
|
"git.g3e.fr/syonad/two/internal/netif"
|
||||||
"git.g3e.fr/syonad/two/internal/netns"
|
"git.g3e.fr/syonad/two/internal/netns"
|
||||||
|
|
@ -12,13 +11,13 @@ import (
|
||||||
"github.com/dgraph-io/badger/v4"
|
"github.com/dgraph-io/badger/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeleteVPC(db *badger.DB, name string, cfg *configuration.Config) error {
|
func DeleteVPC(db *badger.DB, name string) error {
|
||||||
if current, err := state.Get(db, "vpc/"+name); err != nil {
|
if current, err := state.Get(db, "vpc/"+name); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if current == state.Deleting {
|
} else if current == state.Deleting {
|
||||||
vpcID := strings.SplitN(name, "-", 2)[1]
|
vpcID := strings.SplitN(name, "-", 2)[1]
|
||||||
|
|
||||||
if err := l3vni.Delete(db, name, cfg); err != nil {
|
if err := l3vni.Delete(db, name); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue