labctl: segments sur des bridges de l'hôte, routeurs et passerelle VRRP #2
All checks were successful
Tests / test (push) Successful in 3m46s

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-10-13 09:57:09 +02:00
commit e9a0c19b72
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
24 changed files with 1766 additions and 578 deletions

View file

@ -107,7 +107,10 @@ func (l Lab) Up(ctx context.Context, fetcher provision.Fetcher, timeout time.Dur
if err != nil {
return err
}
for _, n := range switchesFirst(l.Plan, nodes) {
if err := l.NetworkUp(ctx); err != nil {
return err
}
for _, n := range routersFirst(l.Plan, nodes) {
if err := os.Remove(l.pidFile(n.Name)); err != nil && !errors.Is(err, os.ErrNotExist) {
return err
}
@ -134,10 +137,10 @@ func (l Lab) Up(ctx context.Context, fetcher provision.Fetcher, timeout time.Dur
return errors.Join(errs...)
}
func switchesFirst(p *topology.Plan, nodes []render.Node) []render.Node {
func routersFirst(p *topology.Plan, nodes []render.Node) []render.Node {
var first, rest []render.Node
for i, n := range nodes {
if p.Nodes[i].Role == topology.RoleSwitch {
if p.Nodes[i].Role == topology.RoleRouter {
first = append(first, n)
} else {
rest = append(rest, n)
@ -167,16 +170,16 @@ func (l Lab) waitReady(ctx context.Context, n topology.NodePlan) error {
}
}
func services(n topology.NodePlan) []string {
func services(p *topology.Plan, n topology.NodePlan) []string {
units := append([]string(nil), n.Services...)
if n.FRR != "" {
if render.NeedsFRR(p, n) {
units = append(units, "frr.service")
}
return units
}
func (l Lab) checkServices(ctx context.Context, n topology.NodePlan) error {
for _, unit := range services(n) {
for _, unit := range services(l.Plan, n) {
if err := l.Runner.Run(ctx, "ssh", l.sshArgs(n, true, []string{"systemctl", "is-active", "--quiet", unit})...); err != nil {
return fmt.Errorf("%s is not active: %w", unit, err)
}
@ -235,7 +238,10 @@ func (l Lab) Status(w io.Writer) error {
}
fmt.Fprintf(tw, "%s\t%s\t%s\t%s\t127.0.0.1:%d\n", n.Name, n.Role, state, shown, n.SSHPort)
}
return tw.Flush()
if err := tw.Flush(); err != nil {
return err
}
return l.networkStatus(w)
}
func (l Lab) Down(ctx context.Context) error {
@ -259,7 +265,10 @@ func (l Lab) Down(ctx context.Context) error {
}
fmt.Fprintf(l.Out, "%s: stopped\n", n.Name)
}
return errors.Join(errs...)
if len(errs) > 0 {
return errors.Join(errs...)
}
return l.NetworkDown(ctx)
}
func (l Lab) stop(ctx context.Context, name string, pid int) error {