-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
E2E: add test for the unnumbered BGP peering
The test requires point-to-point connection so we cannot use any existing infra peer. Therefore a new peer (docker container) runs, and point-to-point connections are created using `sudo ip` commands. There are two tests: 1. one for the native frrconfiguration 2. one for the raw frrconfig, which is used to check the new infra setup part Signed-off-by: karampok <karampok@gmail.com>
- Loading branch information
Showing
7 changed files
with
289 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
// SPDX-License-Identifier:Apache-2.0 | ||
|
||
package tests | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"os" | ||
"time" | ||
|
||
frrk8sv1beta1 "github.com/metallb/frr-k8s/api/v1beta1" | ||
"github.com/metallb/frrk8stests/pkg/config" | ||
"github.com/metallb/frrk8stests/pkg/dump" | ||
"github.com/metallb/frrk8stests/pkg/infra" | ||
"github.com/metallb/frrk8stests/pkg/k8s" | ||
"github.com/metallb/frrk8stests/pkg/k8sclient" | ||
"github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"go.universe.tf/e2etest/pkg/frr" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
||
frrcontainer "go.universe.tf/e2etest/pkg/frr/container" | ||
) | ||
|
||
var FRRImage string | ||
|
||
// The Unnumbered test can on IPv4, IPv6 or Dual it only needs the IPv6 LLA | ||
// addresses in the interface. | ||
var _ = ginkgo.Describe("Unnumbered configure BGP peering", func() { | ||
var ( | ||
node corev1.Node | ||
updater *config.Updater | ||
peer *frrcontainer.FRR | ||
) | ||
|
||
ginkgo.BeforeEach(func() { | ||
if _, found := os.LookupEnv("RUN_FRR_CONTAINER_ON_HOST_NETWORK"); found { | ||
ginkgo.Skip("Skipping this test because RUN_FRR_CONTAINER_ON_HOST_NETWORK is set to true") | ||
} | ||
var err error | ||
updater, err = config.NewUpdater() | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
nodes, err := k8s.Nodes(k8sclient.New()) | ||
Expect(err).NotTo(HaveOccurred()) | ||
node = nodes[0] | ||
|
||
peer, err = frrcontainer.SetupP2PPeer(FRRImage, node) | ||
Expect(err).NotTo(HaveOccurred()) | ||
ginkgo.DeferCleanup(func() { | ||
err := frrcontainer.Delete([]*frrcontainer.FRR{peer}) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
err = updater.Clean() | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
}) | ||
|
||
ginkgo.AfterEach(func() { | ||
if ginkgo.CurrentSpecReport().Failed() { | ||
reporter := dump.NewK8sReporter(k8s.FRRK8sNamespace) | ||
testName := ginkgo.CurrentSpecReport().FullText() | ||
dump.K8sInfo(testName, reporter) | ||
dump.BGPInfo(testName, []*frrcontainer.FRR{peer}, k8sclient.New()) | ||
} | ||
}) | ||
|
||
ginkgo.Context("with native neighbor config", func() { | ||
ginkgo.It("session should be established and routes to be validated", func() { | ||
cr := frrk8sv1beta1.FRRConfiguration{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "native-for-" + peer.Name, | ||
Namespace: k8s.FRRK8sNamespace, | ||
}, | ||
Spec: frrk8sv1beta1.FRRConfigurationSpec{ | ||
BGP: frrk8sv1beta1.BGPConfig{ | ||
Routers: []frrk8sv1beta1.Router{ | ||
{ | ||
ASN: infra.FRRK8sASN, | ||
Neighbors: []frrk8sv1beta1.Neighbor{ | ||
{ | ||
DynamicASN: frrk8sv1beta1.ExternalASNMode, | ||
Interface: "net0", | ||
ToAdvertise: frrk8sv1beta1.Advertise{ | ||
Allowed: frrk8sv1beta1.AllowedOutPrefixes{ | ||
Mode: frrk8sv1beta1.AllowAll, | ||
}, | ||
}, | ||
}, | ||
}, | ||
Prefixes: []string{"5.5.5.5/32", "fc00:f888:ccd:e793::1/128"}, | ||
}, | ||
}, | ||
}, | ||
NodeSelector: metav1.LabelSelector{ | ||
MatchLabels: map[string]string{ | ||
"kubernetes.io/hostname": node.GetLabels()["kubernetes.io/hostname"], | ||
}, | ||
}, | ||
}, | ||
} | ||
ginkgo.DeferCleanup(func() { | ||
err := updater.CleanFRRConfiguration(cr) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
err := updater.Update([]corev1.Secret{}, cr) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
validate(peer, []string{"5.5.5.5", "fc00:f888:ccd:e793::1"}) | ||
}) | ||
}) | ||
|
||
// This spec is added to verify that the point-to-point setup works | ||
ginkgo.Context("with raw config", func() { | ||
ginkgo.It("session should be established and routes to be validated", func() { | ||
raw := ` | ||
frr defaults traditional | ||
no ipv6 forwarding | ||
router bgp 65000 | ||
no bgp ebgp-requires-policy | ||
no bgp network import-check | ||
neighbor net0 interface remote-as external | ||
address-family ipv6 unicast | ||
network fc00:f888:ccd:e793::1/128 | ||
neighbor net0 activate | ||
exit-address-family | ||
address-family ipv4 unicast | ||
network 5.5.5.5/32 | ||
neighbor net0 activate | ||
exit-address-family | ||
exit | ||
end | ||
` | ||
|
||
cr := frrk8sv1beta1.FRRConfiguration{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "raw-for-" + peer.Name, | ||
Namespace: k8s.FRRK8sNamespace, | ||
}, | ||
Spec: frrk8sv1beta1.FRRConfigurationSpec{ | ||
NodeSelector: metav1.LabelSelector{ | ||
MatchLabels: map[string]string{ | ||
"kubernetes.io/hostname": node.GetLabels()["kubernetes.io/hostname"], | ||
}, | ||
}, | ||
Raw: frrk8sv1beta1.RawConfig{ | ||
Config: raw, | ||
Priority: 5, | ||
}, | ||
}, | ||
} | ||
ginkgo.DeferCleanup(func() { | ||
err := updater.CleanFRRConfiguration(cr) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
err := updater.Update([]corev1.Secret{}, cr) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
validate(peer, []string{"5.5.5.5", "fc00:f888:ccd:e793::1"}) | ||
}) | ||
}) | ||
}) | ||
|
||
func validate(peer *frrcontainer.FRR, prefixes []string) { | ||
Eventually(func() error { | ||
neighbors, err := frr.NeighborsInfo(peer) | ||
Expect(err).NotTo(HaveOccurred()) | ||
for _, n := range neighbors { | ||
if !n.Connected { | ||
return fmt.Errorf("node %v BGP session not established", n) | ||
} | ||
} | ||
return nil | ||
}, 2*time.Minute, 10*time.Second).ShouldNot(HaveOccurred(), | ||
"timed out waiting to validate nodes peered with the frr instance") | ||
|
||
// NOTE: we define the MAC address of net0, and therefore we can define the LLA | ||
nextHops := []net.IP{net.ParseIP("fe80::dcad:beff:feff:1160")} // net.ParseIP("fe80::dcad:beff:feff:1161"), | ||
|
||
Eventually(func() error { | ||
v4, v6, err := frr.Routes(peer) | ||
if err != nil { | ||
return err | ||
} | ||
allRoutes := frr.RoutesJoin(v4, v6) | ||
for _, p := range prefixes { | ||
v, exist := allRoutes[p] | ||
if !exist { | ||
return fmt.Errorf("%s is missing", p) | ||
} | ||
Expect(v.NextHops).To(ConsistOf(nextHops)) | ||
} | ||
return nil | ||
}, 2*time.Minute, 1*time.Second).ShouldNot(HaveOccurred(), fmt.Sprintf("peer should have the routes %s", prefixes)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters