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
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:
parent
b530428de2
commit
eb89a2220c
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`` —
|
||||
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::
|
||||
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
}
|
||||
}
|
||||
if err := vpc.DeleteVPC(db, c.Name, cfg); err != nil {
|
||||
if err := vpc.DeleteVPC(db, c.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
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 {
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -115,12 +115,8 @@ func createL3(h host, cfg *configuration.Config, v l3VPC) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func deleteL3(h host, cfg *configuration.Config, v l3VPC) error {
|
||||
asn, err := bgpASN(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
frrVRF := frr.VRF{ASN: asn, ID: v.id}
|
||||
func deleteL3(h host, v l3VPC) error {
|
||||
frrVRF := frr.VRF{ID: v.id}
|
||||
if err := h.WithdrawVRF(frrVRF); err != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
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)
|
||||
if err != nil || !ok {
|
||||
return err
|
||||
}
|
||||
return deleteL3(newSystem(), cfg, v)
|
||||
return deleteL3(newSystem(), v)
|
||||
}
|
||||
|
||||
type Routing struct {
|
||||
|
|
|
|||
|
|
@ -173,16 +173,16 @@ func TestCreateL3StopsAtTheFirstFailure(t *testing.T) {
|
|||
|
||||
func TestDeleteL3WithdrawsFRRThenTheKernelThenTheVRF(t *testing.T) {
|
||||
f := &fakeHost{}
|
||||
if err := deleteL3(f, bgpConfig(), labL3(t)); err != nil {
|
||||
if err := deleteL3(f, labL3(t)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := []string{
|
||||
"frr withdraw asn=64600 id=s7 vni=0",
|
||||
"frr withdraw asn=0 id=s7 vni=0",
|
||||
"del l3-s7-o",
|
||||
"del vxl3-s7",
|
||||
"del brl3-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) {
|
||||
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) {
|
||||
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") {
|
||||
t.Errorf("erreur %v", err)
|
||||
}
|
||||
|
|
@ -202,7 +202,7 @@ func TestDeleteL3KeepsTheKernelWhenFRRRefusesTheWithdrawal(t *testing.T) {
|
|||
|
||||
func TestDeleteL3KeepsTheFRRVRFWhenAKernelLinkCannotBeDeleted(t *testing.T) {
|
||||
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)
|
||||
}
|
||||
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{}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package vpc
|
|||
import (
|
||||
"strings"
|
||||
|
||||
configuration "git.g3e.fr/syonad/two/internal/config/agent"
|
||||
"git.g3e.fr/syonad/two/internal/l3vni"
|
||||
"git.g3e.fr/syonad/two/internal/netif"
|
||||
"git.g3e.fr/syonad/two/internal/netns"
|
||||
|
|
@ -12,13 +11,13 @@ import (
|
|||
"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 {
|
||||
return err
|
||||
} else if current == state.Deleting {
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue