-
Notifications
You must be signed in to change notification settings - Fork 9
/
target_test.go
98 lines (83 loc) · 3.94 KB
/
target_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
Copyright (c) 2021 Nordix Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package e2e_test
import (
"context"
"github.com/nordix/meridio/test/e2e/utils"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/sirupsen/logrus"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
var _ = Describe("Target", func() {
var (
targetPod *v1.Pod
)
BeforeEach(func() {
clientset, err := utils.GetClientSet()
if err != nil {
logrus.Errorf("Unable to create clientset: %v", err)
}
listOptions := metav1.ListOptions{
LabelSelector: "app=target-a",
}
pods, err := clientset.CoreV1().Pods("red").List(context.Background(), listOptions)
if err != nil || len(pods.Items) <= 0 {
logrus.Errorf("Unable list target-a pods: %v", err)
}
targetPod = &pods.Items[0]
})
Context("With one trench (trench-a) deployed in namespace red containing 2 VIP addresses (20.0.0.1:5000, [2000::1]:5000) and 4 target pods running ctraffic", func() {
It("should be possible for a target to close a stream and request it again", func() {
By("Closing the stream in a target")
_, err := utils.PodExec(targetPod, "ctraffic", []string{"./target-client", "close", "-ns", "load-balancer", "-t", "trench-a"})
Expect(err).NotTo(HaveOccurred())
lastingConn, lostConn, err := utils.SendTraffic(trafficGeneratorCMD, "trench-a", "red", "20.0.0.1:5000", 400, 100)
Expect(err).NotTo(HaveOccurred())
Expect(len(lostConn)).To(Equal(0))
Expect(len(lastingConn)).To(Equal(3))
By("Reopening the stream in the target")
_, err = utils.PodExec(targetPod, "ctraffic", []string{"./target-client", "request", "-ns", "load-balancer", "-t", "trench-a"})
Expect(err).NotTo(HaveOccurred())
lastingConn, lostConn, err = utils.SendTraffic(trafficGeneratorCMD, "trench-a", "red", "20.0.0.1:5000", 400, 100)
Expect(err).NotTo(HaveOccurred())
Expect(len(lostConn)).To(Equal(0))
Expect(len(lastingConn)).To(Equal(4))
})
It("should be possible for a target to disconnect from a trench and connect to it again", func() {
By("Closing the stream in a target")
_, err := utils.PodExec(targetPod, "ctraffic", []string{"./target-client", "disconnect", "-ns", "load-balancer", "-t", "trench-a"})
Expect(err).NotTo(HaveOccurred())
lastingConn, lostConn, err := utils.SendTraffic(trafficGeneratorCMD, "trench-a", "red", "20.0.0.1:5000", 400, 100)
Expect(err).NotTo(HaveOccurred())
Expect(len(lostConn)).To(Equal(0))
Expect(len(lastingConn)).To(Equal(3))
targetHasNetworkInterface, err := utils.PodHasNetworkInterface(targetPod, "ctraffic", "nsc")
Expect(err).NotTo(HaveOccurred())
Expect(targetHasNetworkInterface).To(BeFalse())
By("Reconnecting to the trench and reopening the stream in the target")
_, err = utils.PodExec(targetPod, "ctraffic", []string{"./target-client", "connect", "-ns", "load-balancer", "-t", "trench-a"})
Expect(err).NotTo(HaveOccurred())
_, err = utils.PodExec(targetPod, "ctraffic", []string{"./target-client", "request", "-ns", "load-balancer", "-t", "trench-a"})
Expect(err).NotTo(HaveOccurred())
lastingConn, lostConn, err = utils.SendTraffic(trafficGeneratorCMD, "trench-a", "red", "20.0.0.1:5000", 400, 100)
Expect(err).NotTo(HaveOccurred())
Expect(len(lostConn)).To(Equal(0))
Expect(len(lastingConn)).To(Equal(4))
targetHasNetworkInterface, err = utils.PodHasNetworkInterface(targetPod, "ctraffic", "nsc")
Expect(err).NotTo(HaveOccurred())
Expect(targetHasNetworkInterface).To(BeTrue())
})
})
})