blob: bb1bdb0f42bad1ffe8e22c0625240aa6f198bc26 [file] [log] [blame]
Adrian Villin4677d922024-06-14 09:32:39 +02001package hst
Maros Ondrejickac2f76f42023-02-27 13:22:45 +01002
Adrian Villincee15aa2024-03-14 11:42:55 -04003import (
4 "reflect"
5 "runtime"
6 "strings"
Adrian Villincee15aa2024-03-14 11:42:55 -04007
8 . "github.com/onsi/ginkgo/v2"
9)
10
adrianvillin28bd8f02024-02-13 06:00:02 -050011// These correspond to names used in yaml config
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010012const (
Adrian Villin4677d922024-06-14 09:32:39 +020013 VppProxyContainerName = "vpp-proxy"
14 NginxProxyContainerName = "nginx-proxy"
15 NginxServerContainerName = "nginx-server"
16 MirroringClientInterfaceName = "hstcln"
17 MirroringServerInterfaceName = "hstsrv"
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010018)
19
Adrian Villin681ff3a2024-06-07 06:45:48 -040020var nginxTests = map[string][]func(s *NginxSuite){}
21var nginxSoloTests = map[string][]func(s *NginxSuite){}
Adrian Villincee15aa2024-03-14 11:42:55 -040022
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010023type NginxSuite struct {
24 HstSuite
25}
26
Adrian Villin4677d922024-06-14 09:32:39 +020027func RegisterNginxTests(tests ...func(s *NginxSuite)) {
Adrian Villin681ff3a2024-06-07 06:45:48 -040028 nginxTests[getTestFilename()] = tests
Adrian Villincee15aa2024-03-14 11:42:55 -040029}
Adrian Villin4677d922024-06-14 09:32:39 +020030func RegisterNginxSoloTests(tests ...func(s *NginxSuite)) {
Adrian Villin681ff3a2024-06-07 06:45:48 -040031 nginxSoloTests[getTestFilename()] = tests
Adrian Villincee15aa2024-03-14 11:42:55 -040032}
33
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010034func (s *NginxSuite) SetupSuite() {
Filip Tehlar608d0062023-04-28 10:29:47 +020035 s.HstSuite.SetupSuite()
Adrian Villin4677d922024-06-14 09:32:39 +020036 s.LoadNetworkTopology("2taps")
37 s.LoadContainerTopology("nginxProxyAndServer")
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010038}
39
40func (s *NginxSuite) SetupTest() {
Filip Tehlar608d0062023-04-28 10:29:47 +020041 s.HstSuite.SetupTest()
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010042
43 // Setup test conditions
Filip Tehlar608d0062023-04-28 10:29:47 +020044 var sessionConfig Stanza
45 sessionConfig.
Adrian Villin4677d922024-06-14 09:32:39 +020046 NewStanza("session").
47 Append("enable").
Adrian Villin1fde9992024-06-24 08:14:05 -040048 Append("use-app-socket-api")
49
50 if strings.Contains(CurrentSpecReport().LeafNodeText, "InterruptMode") {
51 sessionConfig.Append("use-private-rx-mqs").Close()
52 s.Log("**********************INTERRUPT MODE**********************")
53 } else {
54 sessionConfig.Close()
55 }
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010056
57 // ... for proxy
Adrian Villin4677d922024-06-14 09:32:39 +020058 vppProxyContainer := s.GetContainerByName(VppProxyContainerName)
59 proxyVpp, _ := vppProxyContainer.newVppInstance(vppProxyContainer.AllocatedCpus, sessionConfig)
60 s.AssertNil(proxyVpp.Start())
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010061
Adrian Villin4677d922024-06-14 09:32:39 +020062 clientInterface := s.GetInterfaceByName(MirroringClientInterfaceName)
63 s.AssertNil(proxyVpp.createTap(clientInterface, 1))
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010064
Adrian Villin4677d922024-06-14 09:32:39 +020065 serverInterface := s.GetInterfaceByName(MirroringServerInterfaceName)
66 s.AssertNil(proxyVpp.createTap(serverInterface, 2))
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010067
Adrian Villin4677d922024-06-14 09:32:39 +020068 nginxContainer := s.GetTransientContainerByName(NginxProxyContainerName)
69 nginxContainer.Create()
Maros Ondrejicka85396a52023-02-28 12:49:43 +010070
71 values := struct {
72 Proxy string
73 Server string
74 }{
Adrian Villin4677d922024-06-14 09:32:39 +020075 Proxy: clientInterface.Peer.Ip4AddressString(),
76 Server: serverInterface.Ip4AddressString(),
Maros Ondrejicka85396a52023-02-28 12:49:43 +010077 }
Adrian Villin4677d922024-06-14 09:32:39 +020078 nginxContainer.CreateConfig(
Maros Ondrejicka85396a52023-02-28 12:49:43 +010079 "/nginx.conf",
80 "./resources/nginx/nginx_proxy_mirroring.conf",
81 values,
82 )
Adrian Villin4677d922024-06-14 09:32:39 +020083 s.AssertNil(nginxContainer.Start())
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010084
Adrian Villin4677d922024-06-14 09:32:39 +020085 proxyVpp.WaitForApp("nginx-", 5)
Maros Ondrejickac2f76f42023-02-27 13:22:45 +010086}
Adrian Villincee15aa2024-03-14 11:42:55 -040087
88var _ = Describe("NginxSuite", Ordered, ContinueOnFailure, func() {
89 var s NginxSuite
90 BeforeAll(func() {
91 s.SetupSuite()
92 })
93 BeforeEach(func() {
94 s.SetupTest()
95 })
96 AfterAll(func() {
97 s.TearDownSuite()
98 })
99 AfterEach(func() {
100 s.TearDownTest()
101 })
Adrian Villin681ff3a2024-06-07 06:45:48 -0400102
103 for filename, tests := range nginxTests {
104 for _, test := range tests {
105 test := test
106 pc := reflect.ValueOf(test).Pointer()
107 funcValue := runtime.FuncForPC(pc)
108 testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
109 It(testName, func(ctx SpecContext) {
Adrian Villin4677d922024-06-14 09:32:39 +0200110 s.Log(testName + ": BEGIN")
Adrian Villin681ff3a2024-06-07 06:45:48 -0400111 test(&s)
Adrian Villin4677d922024-06-14 09:32:39 +0200112 }, SpecTimeout(SuiteTimeout))
Adrian Villin681ff3a2024-06-07 06:45:48 -0400113 }
Adrian Villincee15aa2024-03-14 11:42:55 -0400114 }
115})
116
117var _ = Describe("NginxSuiteSolo", Ordered, ContinueOnFailure, Serial, func() {
118 var s NginxSuite
119 BeforeAll(func() {
120 s.SetupSuite()
121 })
122 BeforeEach(func() {
123 s.SetupTest()
124 })
125 AfterAll(func() {
126 s.TearDownSuite()
127 })
128 AfterEach(func() {
129 s.TearDownTest()
130 })
Adrian Villin637edda2024-05-06 06:55:34 -0400131
Adrian Villin681ff3a2024-06-07 06:45:48 -0400132 for filename, tests := range nginxSoloTests {
133 for _, test := range tests {
134 test := test
135 pc := reflect.ValueOf(test).Pointer()
136 funcValue := runtime.FuncForPC(pc)
137 testName := filename + "/" + strings.Split(funcValue.Name(), ".")[2]
138 It(testName, Label("SOLO"), func(ctx SpecContext) {
Adrian Villin4677d922024-06-14 09:32:39 +0200139 s.Log(testName + ": BEGIN")
Adrian Villin681ff3a2024-06-07 06:45:48 -0400140 test(&s)
Adrian Villin4677d922024-06-14 09:32:39 +0200141 }, SpecTimeout(SuiteTimeout))
Adrian Villin681ff3a2024-06-07 06:45:48 -0400142 }
Adrian Villincee15aa2024-03-14 11:42:55 -0400143 }
144})