@@ -13,9 +13,10 @@ import (
13
13
"sort"
14
14
"testing"
15
15
16
+ mpi "github.com/nginx/agent/v3/api/grpc/mpi/v1"
17
+ "github.com/nginx/agent/v3/internal/model"
16
18
"github.com/nginx/agent/v3/test/integration/utils"
17
19
18
- mpi "github.com/nginx/agent/v3/api/grpc/mpi/v1"
19
20
"github.com/stretchr/testify/suite"
20
21
)
21
22
@@ -26,9 +27,10 @@ const (
26
27
27
28
type ConfigApplyTestSuite struct {
28
29
suite.Suite
29
- ctx context.Context
30
- teardownTest func (testing.TB )
31
- nginxInstanceID string
30
+ ctx context.Context
31
+ teardownTest func (testing.TB )
32
+ nginxInstanceID string
33
+ mockManagementConfigDir string
32
34
}
33
35
34
36
type ConfigApplyChunkingTestSuite struct {
@@ -44,6 +46,9 @@ func (s *ConfigApplyTestSuite) SetupSuite() {
44
46
s .teardownTest = utils .SetupConnectionTest (s .T (), false , false , false ,
45
47
"../../config/agent/nginx-config-with-grpc-client.conf" )
46
48
s .nginxInstanceID = utils .VerifyConnection (s .T (), 2 , utils .MockManagementPlaneAPIAddress )
49
+
50
+ s .mockManagementConfigDir = "/mock-management-plane-grpc/config/" + s .nginxInstanceID
51
+
47
52
responses := utils .ManagementPlaneResponses (s .T (), 1 , utils .MockManagementPlaneAPIAddress )
48
53
s .Require ().Equal (mpi .CommandResponse_COMMAND_STATUS_OK , responses [0 ].GetCommandResponse ().GetStatus ())
49
54
s .Require ().Equal ("Successfully updated all files" , responses [0 ].GetCommandResponse ().GetMessage ())
@@ -58,30 +63,67 @@ func (s *ConfigApplyTestSuite) TearDownTest() {
58
63
utils .ClearManagementPlaneResponses (s .T (), utils .MockManagementPlaneAPIAddress )
59
64
}
60
65
66
+ // Config Apply with no changes to config
61
67
func (s * ConfigApplyTestSuite ) TestConfigApply_Test1_TestNoConfigChanges () {
62
68
slog .Info ("starting config apply no config changes test" )
63
69
utils .PerformConfigApply (s .T (), s .nginxInstanceID , utils .MockManagementPlaneAPIAddress )
64
70
responses := utils .ManagementPlaneResponses (s .T (), 2 , utils .MockManagementPlaneAPIAddress )
65
71
s .T ().Logf ("Config apply responses: %v" , responses )
66
72
73
+ manifestFiles := map [string ]* model.ManifestFile {
74
+ "/etc/nginx/mime.types" : {
75
+ ManifestFileMeta : & model.ManifestFileMeta {
76
+ Name : "/etc/nginx/mime.types" ,
77
+ Hash : "b5XR19dePAcpB9hFYipp0jEQ0SZsFv8SKzEJuLIfOuk=" ,
78
+ Size : 5349 ,
79
+ Referenced : true ,
80
+ },
81
+ },
82
+ "/etc/nginx/nginx.conf" : {
83
+ ManifestFileMeta : & model.ManifestFileMeta {
84
+ Name : "/etc/nginx/nginx.conf" ,
85
+ Hash : "gJ1slpIAUmHAiSo5ZIalKvE40b1hJCgaXasQOMab6kc=" ,
86
+ Size : 1172 ,
87
+ Referenced : true ,
88
+ },
89
+ },
90
+ }
91
+
92
+ if os .Getenv ("IMAGE_PATH" ) == "/nginx-plus/agent" {
93
+ manifestFiles ["/etc/nginx/nginx.conf" ].ManifestFileMeta .Hash = "/SWXYYenb2EcJNg6fiuzlkdj91nBdsMdF1vLm7Wybvc="
94
+ manifestFiles ["/etc/nginx/nginx.conf" ].ManifestFileMeta .Size = 1218
95
+ }
96
+
97
+ utils .CheckManifestFile (s .T (), utils .Container , manifestFiles )
98
+
67
99
s .Equal (mpi .CommandResponse_COMMAND_STATUS_OK , responses [0 ].GetCommandResponse ().GetStatus ())
68
100
s .Equal ("Successfully updated all files" , responses [0 ].GetCommandResponse ().GetMessage ())
69
101
s .Equal (mpi .CommandResponse_COMMAND_STATUS_OK , responses [1 ].GetCommandResponse ().GetStatus ())
70
102
s .Equal ("Config apply successful, no files to change" , responses [1 ].GetCommandResponse ().GetMessage ())
71
103
slog .Info ("finished config apply no config changes test" )
72
104
}
73
105
106
+ // Config apply - Add, Update and Delete Referenced file from Management Plane
74
107
func (s * ConfigApplyTestSuite ) TestConfigApply_Test2_TestValidConfig () {
75
108
slog .Info ("starting config apply valid config test" )
76
- newConfigFile := "../../config/nginx/nginx-with-test-location.conf"
109
+ // Update nginx.conf
110
+ utils .WriteConfigFileMock (s .T (), s .nginxInstanceID , "/etc/nginx/test/test.conf" ,
111
+ "/etc/nginx/test/test.conf" , "/etc/nginx/test/test.conf" )
112
+
113
+ // Delete mime.types
114
+ code , _ , removeErr := utils .MockManagementPlaneGrpcContainer .Exec (context .Background (), []string {
115
+ "rm" ,
116
+ s .mockManagementConfigDir + "/etc/nginx/mime.types" ,
117
+ })
77
118
78
- if os .Getenv ("IMAGE_PATH" ) == "/nginx-plus/agent" {
79
- newConfigFile = "../../config/nginx/nginx-plus-with-test-location.conf"
80
- }
119
+ s .Require ().NoError (removeErr )
120
+ s .Equal (0 , code )
121
+
122
+ // Add test.conf
81
123
err := utils .MockManagementPlaneGrpcContainer .CopyFileToContainer (
82
124
s .ctx ,
83
- newConfigFile ,
84
- fmt . Sprintf ( "/mock-management-plane-grpc/config/%s/ etc/nginx/nginx .conf", s . nginxInstanceID ) ,
125
+ "configs/test.conf" ,
126
+ s . mockManagementConfigDir + "/ etc/nginx/test/test .conf" ,
85
127
0o666 ,
86
128
)
87
129
s .Require ().NoError (err )
@@ -90,6 +132,27 @@ func (s *ConfigApplyTestSuite) TestConfigApply_Test2_TestValidConfig() {
90
132
responses := utils .ManagementPlaneResponses (s .T (), 2 , utils .MockManagementPlaneAPIAddress )
91
133
s .T ().Logf ("Config apply responses: %v" , responses )
92
134
135
+ manifestFiles := map [string ]* model.ManifestFile {
136
+ "/etc/nginx/test/test.conf" : {
137
+ ManifestFileMeta : & model.ManifestFileMeta {
138
+ Name : "/etc/nginx/test/test.conf" ,
139
+ Hash : "BF1ztX59kP/N81XcIv3JlPp82j7gzTsVIk2RGxdAta8=" ,
140
+ Size : 175 ,
141
+ Referenced : true ,
142
+ },
143
+ },
144
+ "/etc/nginx/nginx.conf" : {
145
+ ManifestFileMeta : & model.ManifestFileMeta {
146
+ Name : "/etc/nginx/nginx.conf" ,
147
+ Hash : "/SsQwpZTdJVRa1+bex7OdZoogvVT0tnTOwwO59vpsoM=" ,
148
+ Size : 1360 ,
149
+ Referenced : true ,
150
+ },
151
+ },
152
+ }
153
+
154
+ utils .CheckManifestFile (s .T (), utils .Container , manifestFiles )
155
+
93
156
sort .Slice (responses , func (i , j int ) bool {
94
157
return responses [i ].GetCommandResponse ().GetMessage () < responses [j ].GetCommandResponse ().GetMessage ()
95
158
})
@@ -101,7 +164,60 @@ func (s *ConfigApplyTestSuite) TestConfigApply_Test2_TestValidConfig() {
101
164
slog .Info ("finished config apply valid config test" )
102
165
}
103
166
104
- func (s * ConfigApplyTestSuite ) TestConfigApply_Test3_TestInvalidConfig () {
167
+ // Add, Update and Delete file on DataPlane - Trigger update file overview
168
+ func (s * ConfigApplyTestSuite ) TestConfigApply_Test3_DataPlaneUpdate () {
169
+ slog .Info ("starting config apply data plane update test" )
170
+ // Add test2.conf to dataplane
171
+ err := utils .Container .CopyFileToContainer (
172
+ s .ctx ,
173
+ "configs/test2.conf" ,
174
+ "/etc/nginx/test/test2.conf" ,
175
+ 0o666 ,
176
+ )
177
+ s .Require ().NoError (err )
178
+
179
+ // Delete test.conf from dataplane
180
+ code , _ , removeErr := utils .Container .Exec (context .Background (), []string {
181
+ "rm" ,
182
+ "/etc/nginx/test/test.conf" ,
183
+ })
184
+
185
+ s .Require ().NoError (removeErr )
186
+ s .Equal (0 , code )
187
+
188
+ // Update nginx.conf to reference new file
189
+ utils .WriteConfigFileDataplane (s .T (), "/etc/nginx/test/test2.conf" ,
190
+ "/etc/nginx/test/test2.conf" , "/etc/nginx/test/test2.conf" )
191
+
192
+ manifestFiles := map [string ]* model.ManifestFile {
193
+ "/etc/nginx/test/test2.conf" : {
194
+ ManifestFileMeta : & model.ManifestFileMeta {
195
+ Name : "/etc/nginx/test/test2.conf" ,
196
+ Hash : "mV4nVTx8BObqxSwcJprkJesiCJH+oTO89RgZxFuFEJo=" ,
197
+ Size : 136 ,
198
+ Referenced : true ,
199
+ },
200
+ },
201
+ "/etc/nginx/nginx.conf" : {
202
+ ManifestFileMeta : & model.ManifestFileMeta {
203
+ Name : "/etc/nginx/nginx.conf" ,
204
+ Hash : "q8Zf3Cv5UOAVyfigx5Mr4mwJpLIxApN1H0UzYKKTAiU=" ,
205
+ Size : 1363 ,
206
+ Referenced : true ,
207
+ },
208
+ },
209
+ }
210
+
211
+ responses := utils .ManagementPlaneResponses (s .T (), 1 , utils .MockManagementPlaneAPIAddress )
212
+
213
+ utils .CheckManifestFile (s .T (), utils .Container , manifestFiles )
214
+
215
+ s .Equal (mpi .CommandResponse_COMMAND_STATUS_OK , responses [0 ].GetCommandResponse ().GetStatus ())
216
+ s .Equal ("Successfully updated all files" , responses [0 ].GetCommandResponse ().GetMessage ())
217
+ slog .Info ("finished config apply data plane update test" )
218
+ }
219
+
220
+ func (s * ConfigApplyTestSuite ) TestConfigApply_Test4_TestInvalidConfig () {
105
221
slog .Info ("starting config apply invalid config test" )
106
222
err := utils .MockManagementPlaneGrpcContainer .CopyFileToContainer (
107
223
s .ctx ,
@@ -116,6 +232,27 @@ func (s *ConfigApplyTestSuite) TestConfigApply_Test3_TestInvalidConfig() {
116
232
responses := utils .ManagementPlaneResponses (s .T (), 2 , utils .MockManagementPlaneAPIAddress )
117
233
s .T ().Logf ("Config apply responses: %v" , responses )
118
234
235
+ manifestFiles := map [string ]* model.ManifestFile {
236
+ "/etc/nginx/test/test2.conf" : {
237
+ ManifestFileMeta : & model.ManifestFileMeta {
238
+ Name : "/etc/nginx/test/test2.conf" ,
239
+ Hash : "mV4nVTx8BObqxSwcJprkJesiCJH+oTO89RgZxFuFEJo=" ,
240
+ Size : 136 ,
241
+ Referenced : true ,
242
+ },
243
+ },
244
+ "/etc/nginx/nginx.conf" : {
245
+ ManifestFileMeta : & model.ManifestFileMeta {
246
+ Name : "/etc/nginx/nginx.conf" ,
247
+ Hash : "q8Zf3Cv5UOAVyfigx5Mr4mwJpLIxApN1H0UzYKKTAiU=" ,
248
+ Size : 1363 ,
249
+ Referenced : true ,
250
+ },
251
+ },
252
+ }
253
+
254
+ utils .CheckManifestFile (s .T (), utils .Container , manifestFiles )
255
+
119
256
s .Equal (mpi .CommandResponse_COMMAND_STATUS_ERROR , responses [0 ].GetCommandResponse ().GetStatus ())
120
257
s .Equal ("Config apply failed, rolling back config" , responses [0 ].GetCommandResponse ().GetMessage ())
121
258
s .Equal (configApplyErrorMessage , responses [0 ].GetCommandResponse ().GetError ())
@@ -125,13 +262,33 @@ func (s *ConfigApplyTestSuite) TestConfigApply_Test3_TestInvalidConfig() {
125
262
slog .Info ("finished config apply invalid config test" )
126
263
}
127
264
128
- func (s * ConfigApplyTestSuite ) TestConfigApply_Test4_TestFileNotInAllowedDirectory () {
265
+ func (s * ConfigApplyTestSuite ) TestConfigApply_Test5_TestFileNotInAllowedDirectory () {
129
266
slog .Info ("starting config apply file not in allowed directory test" )
130
267
utils .PerformInvalidConfigApply (s .T (), s .nginxInstanceID )
131
268
132
269
responses := utils .ManagementPlaneResponses (s .T (), 1 , utils .MockManagementPlaneAPIAddress )
133
270
s .T ().Logf ("Config apply responses: %v" , responses )
134
271
272
+ manifestFiles := map [string ]* model.ManifestFile {
273
+ "/etc/nginx/test/test2.conf" : {
274
+ ManifestFileMeta : & model.ManifestFileMeta {
275
+ Name : "/etc/nginx/test/test2.conf" ,
276
+ Hash : "mV4nVTx8BObqxSwcJprkJesiCJH+oTO89RgZxFuFEJo=" ,
277
+ Size : 136 ,
278
+ Referenced : true ,
279
+ },
280
+ },
281
+ "/etc/nginx/nginx.conf" : {
282
+ ManifestFileMeta : & model.ManifestFileMeta {
283
+ Name : "/etc/nginx/nginx.conf" ,
284
+ Hash : "q8Zf3Cv5UOAVyfigx5Mr4mwJpLIxApN1H0UzYKKTAiU=" ,
285
+ Size : 1363 ,
286
+ Referenced : true ,
287
+ },
288
+ },
289
+ }
290
+ utils .CheckManifestFile (s .T (), utils .Container , manifestFiles )
291
+
135
292
s .Equal (mpi .CommandResponse_COMMAND_STATUS_FAILURE , responses [0 ].GetCommandResponse ().GetStatus ())
136
293
s .Equal ("Config apply failed" , responses [0 ].GetCommandResponse ().GetMessage ())
137
294
s .Equal (
@@ -179,6 +336,27 @@ func (s *ConfigApplyChunkingTestSuite) TestConfigApplyChunking() {
179
336
return responses [i ].GetCommandResponse ().GetMessage () < responses [j ].GetCommandResponse ().GetMessage ()
180
337
})
181
338
339
+ manifestFiles := map [string ]* model.ManifestFile {
340
+ "/etc/nginx/mime.types" : {
341
+ ManifestFileMeta : & model.ManifestFileMeta {
342
+ Name : "/etc/nginx/mime.types" ,
343
+ Hash : "b5XR19dePAcpB9hFYipp0jEQ0SZsFv8SKzEJuLIfOuk=" ,
344
+ Size : 5349 ,
345
+ Referenced : true ,
346
+ },
347
+ },
348
+ "/etc/nginx/nginx.conf" : {
349
+ ManifestFileMeta : & model.ManifestFileMeta {
350
+ Name : "/etc/nginx/nginx.conf" ,
351
+ Hash : "dfDpjGOjOhWWhX43y/d+zBulXCisx+BVYj2eEEud6ac=" ,
352
+ Size : 886910 ,
353
+ Referenced : true ,
354
+ },
355
+ },
356
+ }
357
+
358
+ utils .CheckManifestFile (s .T (), utils .Container , manifestFiles )
359
+
182
360
s .Equal (mpi .CommandResponse_COMMAND_STATUS_OK , responses [0 ].GetCommandResponse ().GetStatus ())
183
361
s .Equal ("Config apply successful" , responses [0 ].GetCommandResponse ().GetMessage ())
184
362
s .Equal (mpi .CommandResponse_COMMAND_STATUS_OK , responses [1 ].GetCommandResponse ().GetStatus ())
0 commit comments