f-41: frr: remarques de vtysh acceptées, l3vni libérée de façon asynchrone par bgpd #41
All checks were successful
Documentation / publish (push) Successful in 1m24s
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 / release (push) Successful in 29s
Release Pipeline / publish (push) Successful in 0s
Release Pipeline / build (push) Successful in 2m25s
All checks were successful
Documentation / publish (push) Successful in 1m24s
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 / release (push) Successful in 29s
Release Pipeline / publish (push) Successful in 0s
Release Pipeline / build (push) Successful in 2m25s
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
9477dc91d2
commit
1b80b1c7b6
2 changed files with 106 additions and 14 deletions
|
|
@ -4,18 +4,30 @@ import (
|
|||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
appliedWithNotes = "% Configuration applied with notes:"
|
||||
l3vniStillBound = "% Please unconfigure l3vni"
|
||||
l3vniRetries = 20
|
||||
l3vniRetryDelay = 250 * time.Millisecond
|
||||
)
|
||||
|
||||
type runner func(args ...string) ([]byte, error)
|
||||
|
||||
type Client struct {
|
||||
run runner
|
||||
run runner
|
||||
sleep func(time.Duration)
|
||||
}
|
||||
|
||||
func NewClient() *Client {
|
||||
return &Client{run: func(args ...string) ([]byte, error) {
|
||||
return exec.Command("vtysh", args...).CombinedOutput()
|
||||
}}
|
||||
return &Client{
|
||||
run: func(args ...string) ([]byte, error) {
|
||||
return exec.Command("vtysh", args...).CombinedOutput()
|
||||
},
|
||||
sleep: time.Sleep,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) ApplyBase(b Base) error {
|
||||
|
|
@ -79,7 +91,7 @@ func (c *Client) teardown(v VRF, plan func(VRF, string) []step) error {
|
|||
return err
|
||||
}
|
||||
for _, s := range plan(v, running) {
|
||||
if err := c.configure(s...); err != nil {
|
||||
if err := c.configureStep(s); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
@ -92,6 +104,15 @@ func (c *Client) teardown(v VRF, plan func(VRF, string) []step) error {
|
|||
return remaining(plan(v, running))
|
||||
}
|
||||
|
||||
func (c *Client) configureStep(s step) error {
|
||||
err := c.configure(s...)
|
||||
for i := 0; i < l3vniRetries && err != nil && strings.Contains(err.Error(), l3vniStillBound); i++ {
|
||||
c.sleep(l3vniRetryDelay)
|
||||
err = c.configure(s...)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Client) runningConfig() (string, error) {
|
||||
return c.exec("show running-config")
|
||||
}
|
||||
|
|
@ -116,8 +137,9 @@ func (c *Client) exec(cmds ...string) (string, error) {
|
|||
return "", fmt.Errorf("vtysh %q: %w: %s", cmds, err, strings.TrimSpace(string(out)))
|
||||
}
|
||||
for _, l := range strings.Split(string(out), "\n") {
|
||||
if strings.HasPrefix(strings.TrimSpace(l), "%") {
|
||||
return "", fmt.Errorf("vtysh %q: %s", cmds, strings.TrimSpace(l))
|
||||
l = strings.TrimSpace(l)
|
||||
if strings.HasPrefix(l, "%") && l != appliedWithNotes {
|
||||
return "", fmt.Errorf("vtysh %q: %s", cmds, l)
|
||||
}
|
||||
}
|
||||
return string(out), nil
|
||||
|
|
|
|||
|
|
@ -6,13 +6,16 @@ import (
|
|||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type fakeVtysh struct {
|
||||
calls [][]string
|
||||
running []string
|
||||
fail map[string]string
|
||||
status map[string]error
|
||||
calls [][]string
|
||||
running []string
|
||||
fail map[string]string
|
||||
status map[string]error
|
||||
failTimes map[string]int
|
||||
slept int
|
||||
}
|
||||
|
||||
func (f *fakeVtysh) run(args ...string) ([]byte, error) {
|
||||
|
|
@ -31,15 +34,23 @@ func (f *fakeVtysh) run(args ...string) ([]byte, error) {
|
|||
return []byte(out), nil
|
||||
}
|
||||
for _, c := range cmds {
|
||||
if out, ok := f.fail[c]; ok {
|
||||
return []byte(out), f.status[c]
|
||||
out, ok := f.fail[c]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if n, limited := f.failTimes[c]; limited {
|
||||
if n == 0 {
|
||||
continue
|
||||
}
|
||||
f.failTimes[c] = n - 1
|
||||
}
|
||||
return []byte(out), f.status[c]
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (f *fakeVtysh) client() *Client {
|
||||
return &Client{run: f.run}
|
||||
return &Client{run: f.run, sleep: func(time.Duration) { f.slept++ }}
|
||||
}
|
||||
|
||||
func (f *fakeVtysh) sent(cmd string) bool {
|
||||
|
|
@ -249,3 +260,62 @@ func TestApplyBaseStopsWhenTheRunningConfigIsUnreadable(t *testing.T) {
|
|||
t.Errorf("appels : %q", f.calls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExecAcceptsAConfigurationAppliedWithNotes(t *testing.T) {
|
||||
f := &fakeVtysh{fail: map[string]string{"vni 4001": "% Configuration applied with notes:\nNo changes found to be committed!\n"}}
|
||||
if err := f.client().ApplyVRF(labVRF(t)); err != nil {
|
||||
t.Errorf("remarques prises pour une erreur : %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExecStillReportsOtherPercentLines(t *testing.T) {
|
||||
f := &fakeVtysh{fail: map[string]string{"vni 4001": "% Configuration applied with notes:\n% Unknown command: vni 4001\n"}}
|
||||
if err := f.client().ApplyVRF(labVRF(t)); err == nil || !strings.Contains(err.Error(), "% Unknown command") {
|
||||
t.Errorf("erreur %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithdrawVRFWaitsForBGPToReleaseTheL3VNI(t *testing.T) {
|
||||
f := &fakeVtysh{
|
||||
running: []string{fullRunning, otherOnlyRunning},
|
||||
fail: map[string]string{"no router bgp 64600 vrf vrf-a1b2": "% Please unconfigure l3vni 4001\n"},
|
||||
status: map[string]error{"no router bgp 64600 vrf vrf-a1b2": errors.New("exit status 1")},
|
||||
failTimes: map[string]int{"no router bgp 64600 vrf vrf-a1b2": 3},
|
||||
}
|
||||
if err := f.client().WithdrawVRF(labVRF(t)); err != nil {
|
||||
t.Fatalf("refus transitoire non rattrapé : %v", err)
|
||||
}
|
||||
if f.slept != 3 {
|
||||
t.Errorf("%d attentes, attendu 3", f.slept)
|
||||
}
|
||||
if !f.sent("no route-map EXPORT-a1b2") {
|
||||
t.Errorf("démontage interrompu : %q", f.calls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithdrawVRFGivesUpOnAPersistentL3VNIRefusal(t *testing.T) {
|
||||
f := &fakeVtysh{
|
||||
running: []string{fullRunning},
|
||||
fail: map[string]string{"no router bgp 64600 vrf vrf-a1b2": "% Please unconfigure l3vni 4001\n"},
|
||||
}
|
||||
err := f.client().WithdrawVRF(labVRF(t))
|
||||
if err == nil || !strings.Contains(err.Error(), "Please unconfigure l3vni 4001") {
|
||||
t.Fatalf("erreur %v", err)
|
||||
}
|
||||
if f.slept != l3vniRetries {
|
||||
t.Errorf("%d attentes, attendu %d", f.slept, l3vniRetries)
|
||||
}
|
||||
if f.sent("no route-map EXPORT-a1b2") {
|
||||
t.Error("étape suivante exécutée après l'abandon")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOtherTeardownErrorsAreNotRetried(t *testing.T) {
|
||||
f := &fakeVtysh{
|
||||
running: []string{fullRunning},
|
||||
fail: map[string]string{"no router bgp 64600 vrf vrf-a1b2": "% Unknown command\n"},
|
||||
}
|
||||
if err := f.client().WithdrawVRF(labVRF(t)); err == nil || f.slept != 0 {
|
||||
t.Errorf("erreur %v, %d attentes", err, f.slept)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue