Skip to content

Commit 1d19d7b

Browse files
committed
check
1 parent 24c7b0f commit 1d19d7b

File tree

1 file changed

+16
-317
lines changed

1 file changed

+16
-317
lines changed

test/integration/grpc_management_plane_api_test.go

Lines changed: 16 additions & 317 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ import (
3030
)
3131

3232
const (
33-
configApplyErrorMessage = "failed validating config NGINX config test failed exit status 1:" +
34-
" nginx: [emerg] unexpected end of file, expecting \";\" or \"}\" in /etc/nginx/nginx.conf:2\nnginx: " +
35-
"configuration file /etc/nginx/nginx.conf test failed\n"
33+
// configApplyErrorMessage = "failed validating config NGINX config test failed exit status 1:" +
34+
// " nginx: [emerg] unexpected end of file, expecting \";\" or \"}\" in /etc/nginx/nginx.conf:2\nnginx: " +
35+
// "configuration file /etc/nginx/nginx.conf test failed\n"
3636

3737
retryCount = 5
3838
retryWaitTime = 2 * time.Second
@@ -189,90 +189,6 @@ func setupLocalEnvironment(tb testing.TB) {
189189
}(tb)
190190
}
191191

192-
//func TestGrpc_Reconnection(t *testing.T) {
193-
// ctx := context.Background()
194-
// teardownTest := setupConnectionTest(t, false, false)
195-
// defer teardownTest(t)
196-
//
197-
// timeout := 15 * time.Second
198-
//
199-
// originalID := verifyConnection(t, 2)
200-
//
201-
// stopErr := mockManagementPlaneGrpcContainer.Stop(ctx, &timeout)
202-
//
203-
// require.NoError(t, stopErr)
204-
//
205-
// startErr := mockManagementPlaneGrpcContainer.Start(ctx)
206-
// require.NoError(t, startErr)
207-
//
208-
// ipAddress, err := mockManagementPlaneGrpcContainer.Host(ctx)
209-
// require.NoError(t, err)
210-
// ports, err := mockManagementPlaneGrpcContainer.Ports(ctx)
211-
// require.NoError(t, err)
212-
// mockManagementPlaneAPIAddress = net.JoinHostPort(ipAddress, ports["9093/tcp"][0].HostPort)
213-
//
214-
// time.Sleep(5 * time.Second)
215-
//
216-
// currentID := verifyConnection(t, 2)
217-
// assert.Equal(t, originalID, currentID)
218-
//}
219-
220-
// Verify that the agent sends a connection request and an update data plane status request
221-
//func TestGrpc_StartUp(t *testing.T) {
222-
// teardownTest := setupConnectionTest(t, true, false)
223-
// defer teardownTest(t)
224-
//
225-
// verifyConnection(t, 2)
226-
// assert.False(t, t.Failed())
227-
// verifyUpdateDataPlaneHealth(t)
228-
//}
229-
230-
//func TestGrpc_ConfigUpload(t *testing.T) {
231-
// teardownTest := setupConnectionTest(t, true, false)
232-
// defer teardownTest(t)
233-
//
234-
// nginxInstanceID := verifyConnection(t, 2)
235-
// assert.False(t, t.Failed())
236-
//
237-
// responses := getManagementPlaneResponses(t, 1)
238-
//
239-
// assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_OK, responses[0].GetCommandResponse().GetStatus())
240-
// assert.Equal(t, "Successfully updated all files", responses[0].GetCommandResponse().GetMessage())
241-
//
242-
// request := fmt.Sprintf(`{
243-
// "message_meta": {
244-
// "message_id": "5d0fa83e-351c-4009-90cd-1f2acce2d184",
245-
// "correlation_id": "79794c1c-8e91-47c1-a92c-b9a0c3f1a263",
246-
// "timestamp": "2023-01-15T01:30:15.01Z"
247-
// },
248-
// "config_upload_request": {
249-
// "overview" : {
250-
// "config_version": {
251-
// "instance_id": "%s"
252-
// }
253-
// }
254-
// }
255-
//}`, nginxInstanceID)
256-
//
257-
// t.Logf("Sending config upload request: %s", request)
258-
//
259-
// client := resty.New()
260-
// client.SetRetryCount(retryCount).SetRetryWaitTime(retryWaitTime).SetRetryMaxWaitTime(retryMaxWaitTime)
261-
//
262-
// url := fmt.Sprintf("http://%s/api/v1/requests", mockManagementPlaneAPIAddress)
263-
// resp, err := client.R().EnableTrace().SetBody(request).Post(url)
264-
//
265-
// require.NoError(t, err)
266-
// assert.Equal(t, http.StatusOK, resp.StatusCode())
267-
//
268-
// responses = getManagementPlaneResponses(t, 2)
269-
//
270-
// assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_OK, responses[0].GetCommandResponse().GetStatus())
271-
// assert.Equal(t, "Successfully updated all files", responses[0].GetCommandResponse().GetMessage())
272-
// assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_OK, responses[1].GetCommandResponse().GetStatus())
273-
// assert.Equal(t, "Successfully updated all files", responses[1].GetCommandResponse().GetMessage())
274-
//}
275-
276192
func TestGrpc_ConfigApply(t *testing.T) {
277193
ctx := context.Background()
278194
teardownTest := setupConnectionTest(t, false, false)
@@ -321,7 +237,7 @@ func TestGrpc_ConfigApply(t *testing.T) {
321237
// NGINX Plus contains two extra Successfully updated all files responses as the NginxConfigContext
322238
// is updated, and the file overview is then updated
323239
time.Sleep(5 * time.Second)
324-
240+
325241
responses = getManagementPlaneResponses(t, 3)
326242
t.Logf("Config apply responses: %v", responses)
327243
assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_OK, responses[0].GetCommandResponse().GetStatus())
@@ -333,7 +249,7 @@ func TestGrpc_ConfigApply(t *testing.T) {
333249
}
334250
})
335251

336-
//t.Run("Test 3: Invalid config", func(t *testing.T) {
252+
// t.Run("Test 3: Invalid config", func(t *testing.T) {
337253
// clearManagementPlaneResponses(t)
338254
// err := mockManagementPlaneGrpcContainer.CopyFileToContainer(
339255
// ctx,
@@ -349,26 +265,26 @@ func TestGrpc_ConfigApply(t *testing.T) {
349265
// responses = getManagementPlaneResponses(t, 2)
350266
// t.Logf("Config apply responses: %v", responses)
351267
//
352-
// assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_ERROR, responses[0].GetCommandResponse().GetStatus())
353-
// assert.Equal(t, "Config apply failed, rolling back config", responses[0].GetCommandResponse().GetMessage())
354-
// assert.Equal(t, configApplyErrorMessage, responses[0].GetCommandResponse().GetError())
355-
// assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_FAILURE, responses[1].GetCommandResponse().GetStatus())
356-
// assert.Equal(t, "Config apply failed, rollback successful", responses[1].GetCommandResponse().GetMessage())
357-
// assert.Equal(t, configApplyErrorMessage, responses[1].GetCommandResponse().GetError())
268+
// assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_ERROR, responses[0].GetCommandResponse().GetStatus())
269+
// assert.Equal(t, "Config apply failed, rolling back config", responses[0].GetCommandResponse().GetMessage())
270+
// assert.Equal(t, configApplyErrorMessage, responses[0].GetCommandResponse().GetError())
271+
// assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_FAILURE, responses[1].GetCommandResponse().GetStatus())
272+
// assert.Equal(t, "Config apply failed, rollback successful", responses[1].GetCommandResponse().GetMessage())
273+
// assert.Equal(t, configApplyErrorMessage, responses[1].GetCommandResponse().GetError())
358274
// } else {
359275
// responses = getManagementPlaneResponses(t, 2)
360276
// t.Logf("Config apply responses: %v", len(responses))
361277
//
362278
// assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_ERROR, responses[0].GetCommandResponse().GetStatus())
363-
// assert.Equal(t, "Config apply failed, rolling back config", responses[0].GetCommandResponse().GetMessage())
279+
// assert.Equal(t, "Config apply failed, rolling back config", responses[0].GetCommandResponse().GetMessage())
364280
// assert.Equal(t, configApplyErrorMessage, responses[0].GetCommandResponse().GetError())
365281
// assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_FAILURE, responses[1].GetCommandResponse().GetStatus())
366-
// assert.Equal(t, "Config apply failed, rollback successful", responses[1].GetCommandResponse().GetMessage())
282+
// assert.Equal(t, "Config apply failed, rollback successful", responses[1].GetCommandResponse().GetMessage())
367283
// assert.Equal(t, configApplyErrorMessage, responses[1].GetCommandResponse().GetError())
368284
// }
369-
//})
285+
// })
370286
//
371-
//t.Run("Test 4: File not in allowed directory", func(t *testing.T) {
287+
// t.Run("Test 4: File not in allowed directory", func(t *testing.T) {
372288
// clearManagementPlaneResponses(t)
373289
// performInvalidConfigApply(t, nginxInstanceID)
374290
//
@@ -382,70 +298,9 @@ func TestGrpc_ConfigApply(t *testing.T) {
382298
// "file not in allowed directories /unknown/nginx.conf",
383299
// responses[0].GetCommandResponse().GetError(),
384300
// )
385-
//})
301+
// })
386302
}
387303

388-
//func TestGrpc_FileWatcher(t *testing.T) {
389-
// ctx := context.Background()
390-
// teardownTest := setupConnectionTest(t, true, false)
391-
// defer teardownTest(t)
392-
//
393-
// verifyConnection(t, 2)
394-
// assert.False(t, t.Failed())
395-
//
396-
// err := container.CopyFileToContainer(
397-
// ctx,
398-
// "../config/nginx/nginx-with-server-block-access-log.conf",
399-
// "/etc/nginx/nginx.conf",
400-
// 0o666,
401-
// )
402-
// require.NoError(t, err)
403-
//
404-
// responses := getManagementPlaneResponses(t, 2)
405-
// assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_OK, responses[0].GetCommandResponse().GetStatus())
406-
// assert.Equal(t, "Successfully updated all files", responses[0].GetCommandResponse().GetMessage())
407-
// assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_OK, responses[1].GetCommandResponse().GetStatus())
408-
// assert.Equal(t, "Successfully updated all files", responses[1].GetCommandResponse().GetMessage())
409-
//
410-
// verifyUpdateDataPlaneStatus(t)
411-
//}
412-
413-
//func TestGrpc_DataplaneHealthRequest(t *testing.T) {
414-
// teardownTest := setupConnectionTest(t, true, false)
415-
// defer teardownTest(t)
416-
//
417-
// verifyConnection(t, 2)
418-
//
419-
// responses := getManagementPlaneResponses(t, 1)
420-
// assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_OK, responses[0].GetCommandResponse().GetStatus())
421-
// assert.Equal(t, "Successfully updated all files", responses[0].GetCommandResponse().GetMessage())
422-
//
423-
// assert.False(t, t.Failed())
424-
//
425-
// request := `{
426-
// "message_meta": {
427-
// "message_id": "5d0fa83e-351c-4009-90cd-1f2acce2d184",
428-
// "correlation_id": "79794c1c-8e91-47c1-a92c-b9a0c3f1a263",
429-
// "timestamp": "2023-01-15T01:30:15.01Z"
430-
// },
431-
// "health_request": {}
432-
// }`
433-
//
434-
// client := resty.New()
435-
// client.SetRetryCount(retryCount).SetRetryWaitTime(retryWaitTime).SetRetryMaxWaitTime(retryMaxWaitTime)
436-
//
437-
// url := fmt.Sprintf("http://%s/api/v1/requests", mockManagementPlaneAPIAddress)
438-
// resp, err := client.R().EnableTrace().SetBody(request).Post(url)
439-
//
440-
// require.NoError(t, err)
441-
// assert.Equal(t, http.StatusOK, resp.StatusCode())
442-
//
443-
// responses = getManagementPlaneResponses(t, 2)
444-
//
445-
// assert.Equal(t, mpi.CommandResponse_COMMAND_STATUS_OK, responses[1].GetCommandResponse().GetStatus())
446-
// assert.Equal(t, "Successfully sent the health status update", responses[1].GetCommandResponse().GetMessage())
447-
//}
448-
449304
func performConfigApply(t *testing.T, nginxInstanceID string) {
450305
t.Helper()
451306

@@ -459,53 +314,6 @@ func performConfigApply(t *testing.T, nginxInstanceID string) {
459314
assert.Equal(t, http.StatusOK, resp.StatusCode())
460315
}
461316

462-
//func performInvalidConfigApply(t *testing.T, nginxInstanceID string) {
463-
// t.Helper()
464-
//
465-
// client := resty.New()
466-
// client.SetRetryCount(retryCount).SetRetryWaitTime(retryWaitTime).SetRetryMaxWaitTime(retryMaxWaitTime)
467-
//
468-
// body := fmt.Sprintf(`{
469-
// "message_meta": {
470-
// "message_id": "e2254df9-8edd-4900-91ce-88782473bcb9",
471-
// "correlation_id": "9673f3b4-bf33-4d98-ade1-ded9266f6818",
472-
// "timestamp": "2023-01-15T01:30:15.01Z"
473-
// },
474-
// "config_apply_request": {
475-
// "overview": {
476-
// "files": [{
477-
// "file_meta": {
478-
// "name": "/etc/nginx/nginx.conf",
479-
// "hash": "ea57e443-e968-3a50-b842-f37112acde71",
480-
// "modifiedTime": "2023-01-15T01:30:15.01Z",
481-
// "permissions": "0644",
482-
// "size": 0
483-
// },
484-
// "action": "FILE_ACTION_UPDATE"
485-
// },
486-
// {
487-
// "file_meta": {
488-
// "name": "/unknown/nginx.conf",
489-
// "hash": "bd1f337d-6874-35ea-9d4d-2b543efd42cf",
490-
// "modifiedTime": "2023-01-15T01:30:15.01Z",
491-
// "permissions": "0644",
492-
// "size": 0
493-
// },
494-
// "action": "FILE_ACTION_ADD"
495-
// }],
496-
// "config_version": {
497-
// "instance_id": "%s",
498-
// "version": "6f343257-55e3-309e-a2eb-bb13af5f80f4"
499-
// }
500-
// }
501-
// }
502-
// }`, nginxInstanceID)
503-
// url := fmt.Sprintf("http://%s/api/v1/requests", mockManagementPlaneAPIAddress)
504-
// resp, err := client.R().EnableTrace().SetBody(body).Post(url)
505-
// require.NoError(t, err)
506-
// assert.Equal(t, http.StatusOK, resp.StatusCode())
507-
//}
508-
509317
func getManagementPlaneResponses(t *testing.T, numberOfExpectedResponses int) []*mpi.DataPlaneResponse {
510318
t.Helper()
511319

@@ -633,112 +441,3 @@ func verifyConnection(t *testing.T, instancesLength int) string {
633441

634442
return nginxInstanceID
635443
}
636-
637-
//func verifyUpdateDataPlaneHealth(t *testing.T) {
638-
// t.Helper()
639-
//
640-
// client := resty.New()
641-
// client.SetRetryCount(retryCount).SetRetryWaitTime(retryWaitTime).SetRetryMaxWaitTime(retryMaxWaitTime)
642-
// client.AddRetryCondition(
643-
// func(r *resty.Response, err error) bool {
644-
// return r.StatusCode() == http.StatusNotFound
645-
// },
646-
// )
647-
//
648-
// url := fmt.Sprintf("http://%s/api/v1/health", mockManagementPlaneAPIAddress)
649-
// resp, err := client.R().EnableTrace().Get(url)
650-
// require.NoError(t, err)
651-
// assert.Equal(t, http.StatusOK, resp.StatusCode())
652-
//
653-
// responseData := resp.Body()
654-
// t.Logf("Response: %s", string(responseData))
655-
// assert.True(t, json.Valid(responseData))
656-
//
657-
// pb := protojson.UnmarshalOptions{DiscardUnknown: true}
658-
//
659-
// updateDataPlaneHealthRequest := mpi.UpdateDataPlaneHealthRequest{}
660-
// unmarshalErr := pb.Unmarshal(responseData, &updateDataPlaneHealthRequest)
661-
// require.NoError(t, unmarshalErr)
662-
//
663-
// t.Logf("UpdateDataPlaneHealthRequest: %v", &updateDataPlaneHealthRequest)
664-
//
665-
// assert.NotNil(t, &updateDataPlaneHealthRequest)
666-
//
667-
// // Verify message metadata
668-
// messageMeta := updateDataPlaneHealthRequest.GetMessageMeta()
669-
// assert.NotEmpty(t, messageMeta.GetCorrelationId())
670-
// assert.NotEmpty(t, messageMeta.GetMessageId())
671-
// assert.NotEmpty(t, messageMeta.GetTimestamp())
672-
//
673-
// healths := updateDataPlaneHealthRequest.GetInstanceHealths()
674-
// assert.Len(t, healths, 1)
675-
//
676-
// // Verify health metadata
677-
// assert.NotEmpty(t, healths[0].GetInstanceId())
678-
// assert.Equal(t, mpi.InstanceHealth_INSTANCE_HEALTH_STATUS_HEALTHY, healths[0].GetInstanceHealthStatus())
679-
//}
680-
//
681-
//func verifyUpdateDataPlaneStatus(t *testing.T) {
682-
// t.Helper()
683-
//
684-
// client := resty.New()
685-
// client.SetRetryCount(3).SetRetryWaitTime(50 * time.Millisecond).SetRetryMaxWaitTime(200 * time.Millisecond)
686-
//
687-
// url := fmt.Sprintf("http://%s/api/v1/status", mockManagementPlaneAPIAddress)
688-
// resp, err := client.R().EnableTrace().Get(url)
689-
//
690-
// require.NoError(t, err)
691-
// assert.Equal(t, http.StatusOK, resp.StatusCode())
692-
//
693-
// updateDataPlaneStatusRequest := mpi.UpdateDataPlaneStatusRequest{}
694-
//
695-
// responseData := resp.Body()
696-
// t.Logf("Response: %s", string(responseData))
697-
// assert.True(t, json.Valid(responseData))
698-
//
699-
// pb := protojson.UnmarshalOptions{DiscardUnknown: true}
700-
// unmarshalErr := pb.Unmarshal(responseData, &updateDataPlaneStatusRequest)
701-
// require.NoError(t, unmarshalErr)
702-
//
703-
// t.Logf("UpdateDataPlaneStatusRequest: %v", &updateDataPlaneStatusRequest)
704-
//
705-
// assert.NotNil(t, &updateDataPlaneStatusRequest)
706-
//
707-
// // Verify message metadata
708-
// messageMeta := updateDataPlaneStatusRequest.GetMessageMeta()
709-
// assert.NotEmpty(t, messageMeta.GetCorrelationId())
710-
// assert.NotEmpty(t, messageMeta.GetMessageId())
711-
// assert.NotEmpty(t, messageMeta.GetTimestamp())
712-
//
713-
// instances := updateDataPlaneStatusRequest.GetResource().GetInstances()
714-
// sort.Slice(instances, func(i, j int) bool {
715-
// return instances[i].GetInstanceMeta().GetInstanceType() < instances[j].GetInstanceMeta().GetInstanceType()
716-
// })
717-
// assert.Len(t, instances, 2)
718-
//
719-
// // Verify agent instance metadata
720-
// assert.NotEmpty(t, instances[0].GetInstanceMeta().GetInstanceId())
721-
// assert.Equal(t, mpi.InstanceMeta_INSTANCE_TYPE_AGENT, instances[0].GetInstanceMeta().GetInstanceType())
722-
// assert.NotEmpty(t, instances[0].GetInstanceMeta().GetVersion())
723-
//
724-
// // Verify agent instance configuration
725-
// assert.Empty(t, instances[0].GetInstanceConfig().GetActions())
726-
// assert.NotEmpty(t, instances[0].GetInstanceRuntime().GetProcessId())
727-
// assert.Equal(t, "/usr/bin/nginx-agent", instances[0].GetInstanceRuntime().GetBinaryPath())
728-
// assert.Equal(t, "/etc/nginx-agent/nginx-agent.conf", instances[0].GetInstanceRuntime().GetConfigPath())
729-
//
730-
// // Verify NGINX instance metadata
731-
// assert.NotEmpty(t, instances[1].GetInstanceMeta().GetInstanceId())
732-
// if os.Getenv("IMAGE_PATH") == "/nginx-plus/agent" {
733-
// assert.Equal(t, mpi.InstanceMeta_INSTANCE_TYPE_NGINX_PLUS, instances[1].GetInstanceMeta().GetInstanceType())
734-
// } else {
735-
// assert.Equal(t, mpi.InstanceMeta_INSTANCE_TYPE_NGINX, instances[1].GetInstanceMeta().GetInstanceType())
736-
// }
737-
// assert.NotEmpty(t, instances[1].GetInstanceMeta().GetVersion())
738-
//
739-
// // Verify NGINX instance configuration
740-
// assert.Empty(t, instances[1].GetInstanceConfig().GetActions())
741-
// assert.NotEmpty(t, instances[1].GetInstanceRuntime().GetProcessId())
742-
// assert.Equal(t, "/usr/sbin/nginx", instances[1].GetInstanceRuntime().GetBinaryPath())
743-
// assert.Equal(t, "/etc/nginx/nginx.conf", instances[1].GetInstanceRuntime().GetConfigPath())
744-
//}

0 commit comments

Comments
 (0)