Skip to content

Commit

Permalink
e2e route validation check: propagate the error
Browse files Browse the repository at this point in the history
Instead of relying on the flag, we propagate the error and we assert on
the error routes not found when we know the routes shouldn't be there.
This makes triaging easier as the error is more descriptive than a flag.

Signed-off-by: Federico Paolinelli <[email protected]>
  • Loading branch information
fedepaol committed Jun 26, 2024
1 parent 268e184 commit f0635db
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
17 changes: 6 additions & 11 deletions e2etests/pkg/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package routes

import (
"bytes"
"errors"
"fmt"
"net"

Expand All @@ -31,32 +30,28 @@ func PodHasPrefixFromContainer(pod *v1.Pod, frr frrcontainer.FRR, prefix string)

// CheckNeighborHasPrefix tells if the given frr container has a route toward the given prefix
// via the set of node passed to this function.
func CheckNeighborHasPrefix(neighbor frrcontainer.FRR, prefix string, nodes []v1.Node) (bool, error) {
func CheckNeighborHasPrefix(neighbor frrcontainer.FRR, prefix string, nodes []v1.Node) error {
routesV4, routesV6, err := frr.Routes(neighbor)
if err != nil {
return false, err
return err
}

_, cidr, err := net.ParseCIDR(prefix)
if err != nil {
return false, err
return err
}

route, err := routeForCIDR(cidr, routesV4, routesV6)
var notFound RouteNotFoundError
if errors.As(err, &notFound) {
return false, nil
}
if err != nil {
return false, err
return err
}

cidrFamily := ipfamily.ForCIDR(cidr)
err = frr.RoutesMatchNodes(nodes, route, cidrFamily, neighbor.RouterConfig.VRF)
if err != nil {
return false, nil
return nil
}
return true, nil
return nil
}

func cidrsAreEqual(a, b *net.IPNet) bool {
Expand Down
16 changes: 7 additions & 9 deletions e2etests/tests/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ func ValidatePrefixesForNeighbor(neigh frrcontainer.FRR, nodes []v1.Node, prefix
ginkgo.By(fmt.Sprintf("checking prefixes %v for %s", prefixes, neigh.Name))
Eventually(func() error {
for _, prefix := range prefixes {
found, err := routes.CheckNeighborHasPrefix(neigh, prefix, nodes)
Expect(err).NotTo(HaveOccurred())
if !found {
return fmt.Errorf("Neigh %s does not have prefix %s", neigh.Name, prefix)
err := routes.CheckNeighborHasPrefix(neigh, prefix, nodes)
if err != nil {
return fmt.Errorf("Neigh %s does not have prefix %s: %w", neigh.Name, prefix, err)
}
}
return nil
Expand All @@ -61,14 +60,13 @@ func ValidateNeighborNoPrefixes(neigh frrcontainer.FRR, nodes []v1.Node, prefixe
ginkgo.By(fmt.Sprintf("checking prefixes %v not announced to %s", prefixes, neigh.Name))
Eventually(func() error {
for _, prefix := range prefixes {
found, err := routes.CheckNeighborHasPrefix(neigh, prefix, nodes)
Expect(err).NotTo(HaveOccurred())
if found {
return fmt.Errorf("Neigh %s has prefix %s", neigh.Name, prefix)
err := routes.CheckNeighborHasPrefix(neigh, prefix, nodes)
if err != nil {
return fmt.Errorf("Neigh %s does not have prefix %s: %w", neigh.Name, prefix, err)
}
}
return nil
}, 5*time.Second, time.Second).ShouldNot(HaveOccurred())
}, 5*time.Second, time.Second).Should(MatchError(routes.RouteNotFoundError("")))
}

func ValidateNeighborCommunityPrefixes(neigh frrcontainer.FRR, community string, prefixes []string, ipfam ipfamily.Family) {
Expand Down

0 comments on commit f0635db

Please sign in to comment.