Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 1 | package hst |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 2 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 3 | import ( |
| 4 | "reflect" |
| 5 | "runtime" |
| 6 | "strings" |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 7 | |
| 8 | . "github.com/onsi/ginkgo/v2" |
| 9 | ) |
| 10 | |
adrianvillin | 28bd8f0 | 2024-02-13 06:00:02 -0500 | [diff] [blame] | 11 | // These correspond to names used in yaml config |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 12 | const ( |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 13 | VppProxyContainerName = "vpp-proxy" |
| 14 | NginxProxyContainerName = "nginx-proxy" |
| 15 | NginxServerContainerName = "nginx-server" |
| 16 | MirroringClientInterfaceName = "hstcln" |
| 17 | MirroringServerInterfaceName = "hstsrv" |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 18 | ) |
| 19 | |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 20 | var nginxTests = map[string][]func(s *NginxSuite){} |
| 21 | var nginxSoloTests = map[string][]func(s *NginxSuite){} |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 22 | |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 23 | type NginxSuite struct { |
| 24 | HstSuite |
| 25 | } |
| 26 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 27 | func RegisterNginxTests(tests ...func(s *NginxSuite)) { |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 28 | nginxTests[getTestFilename()] = tests |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 29 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 30 | func RegisterNginxSoloTests(tests ...func(s *NginxSuite)) { |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 31 | nginxSoloTests[getTestFilename()] = tests |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 32 | } |
| 33 | |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 34 | func (s *NginxSuite) SetupSuite() { |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 35 | s.HstSuite.SetupSuite() |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 36 | s.LoadNetworkTopology("2taps") |
| 37 | s.LoadContainerTopology("nginxProxyAndServer") |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | func (s *NginxSuite) SetupTest() { |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 41 | s.HstSuite.SetupTest() |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 42 | |
| 43 | // Setup test conditions |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 44 | var sessionConfig Stanza |
| 45 | sessionConfig. |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 46 | NewStanza("session"). |
| 47 | Append("enable"). |
Adrian Villin | 1fde999 | 2024-06-24 08:14:05 -0400 | [diff] [blame] | 48 | 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 Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 56 | |
| 57 | // ... for proxy |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 58 | vppProxyContainer := s.GetContainerByName(VppProxyContainerName) |
| 59 | proxyVpp, _ := vppProxyContainer.newVppInstance(vppProxyContainer.AllocatedCpus, sessionConfig) |
| 60 | s.AssertNil(proxyVpp.Start()) |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 61 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 62 | clientInterface := s.GetInterfaceByName(MirroringClientInterfaceName) |
| 63 | s.AssertNil(proxyVpp.createTap(clientInterface, 1)) |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 64 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 65 | serverInterface := s.GetInterfaceByName(MirroringServerInterfaceName) |
| 66 | s.AssertNil(proxyVpp.createTap(serverInterface, 2)) |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 67 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 68 | nginxContainer := s.GetTransientContainerByName(NginxProxyContainerName) |
Adrian Villin | 2514001 | 2024-07-09 15:31:36 +0200 | [diff] [blame] | 69 | s.AssertNil(nginxContainer.Create()) |
Maros Ondrejicka | 85396a5 | 2023-02-28 12:49:43 +0100 | [diff] [blame] | 70 | |
| 71 | values := struct { |
| 72 | Proxy string |
| 73 | Server string |
| 74 | }{ |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 75 | Proxy: clientInterface.Peer.Ip4AddressString(), |
| 76 | Server: serverInterface.Ip4AddressString(), |
Maros Ondrejicka | 85396a5 | 2023-02-28 12:49:43 +0100 | [diff] [blame] | 77 | } |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 78 | nginxContainer.CreateConfig( |
Maros Ondrejicka | 85396a5 | 2023-02-28 12:49:43 +0100 | [diff] [blame] | 79 | "/nginx.conf", |
| 80 | "./resources/nginx/nginx_proxy_mirroring.conf", |
| 81 | values, |
| 82 | ) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 83 | s.AssertNil(nginxContainer.Start()) |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 84 | |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 85 | proxyVpp.WaitForApp("nginx-", 5) |
Maros Ondrejicka | c2f76f4 | 2023-02-27 13:22:45 +0100 | [diff] [blame] | 86 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 87 | |
| 88 | var _ = 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 Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 102 | |
| 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 Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 110 | s.Log(testName + ": BEGIN") |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 111 | test(&s) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 112 | }, SpecTimeout(SuiteTimeout)) |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 113 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 114 | } |
| 115 | }) |
| 116 | |
| 117 | var _ = 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 Villin | 637edda | 2024-05-06 06:55:34 -0400 | [diff] [blame] | 131 | |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 132 | 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 Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 139 | s.Log(testName + ": BEGIN") |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 140 | test(&s) |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 141 | }, SpecTimeout(SuiteTimeout)) |
Adrian Villin | 681ff3a | 2024-06-07 06:45:48 -0400 | [diff] [blame] | 142 | } |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 143 | } |
| 144 | }) |