Skip to content

Commit e6bbad5

Browse files
committed
added config apply test
1 parent 8a25503 commit e6bbad5

File tree

4 files changed

+91
-79
lines changed

4 files changed

+91
-79
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ integration-test: $(SELECTED_PACKAGE) build-mock-management-plane-grpc
161161
TEST_ENV="Container" CONTAINER_OS_TYPE=$(CONTAINER_OS_TYPE) BUILD_TARGET="install-agent-local" CONTAINER_NGINX_IMAGE_REGISTRY=${CONTAINER_NGINX_IMAGE_REGISTRY} \
162162
PACKAGES_REPO=$(OSS_PACKAGES_REPO) PACKAGE_NAME=$(PACKAGE_NAME) BASE_IMAGE=$(BASE_IMAGE) DOCKERFILE_PATH=$(DOCKERFILE_PATH) IMAGE_PATH=$(IMAGE_PATH) TAG=${IMAGE_TAG} \
163163
OS_VERSION=$(OS_VERSION) OS_RELEASE=$(OS_RELEASE) \
164-
go test -v ./test/integration/auxiliarycommandserver
164+
go test -v ./test/integration/installuninstall ./test/integration/managementplane ./test/integration/auxiliarycommandserver ./test/integration/nginxless
165165

166166
official-image-integration-test: $(SELECTED_PACKAGE) build-mock-management-plane-grpc
167167
TEST_ENV="Container" CONTAINER_OS_TYPE=$(CONTAINER_OS_TYPE) CONTAINER_NGINX_IMAGE_REGISTRY=${CONTAINER_NGINX_IMAGE_REGISTRY} BUILD_TARGET="install" \

test/integration/auxiliarycommandserver/connection_test.go

Lines changed: 73 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"fmt"
1111
"net"
1212
"net/http"
13+
"os"
14+
"sort"
1315
"testing"
1416
"time"
1517

@@ -41,17 +43,21 @@ func TestSuite(t *testing.T) {
4143
suite.Run(t, new(AuxiliaryTestSuite))
4244
}
4345

44-
func (s *AuxiliaryTestSuite) TestAuxiliary_Connection() {
46+
func (s *AuxiliaryTestSuite) TestAuxiliary_Test1_Connection() {
4547
s.instanceID = utils.VerifyConnection(s.T(), 2, utils.MockManagementPlaneAPIAddress)
4648
s.False(s.T().Failed())
4749
utils.VerifyUpdateDataPlaneHealth(s.T(), utils.MockManagementPlaneAPIAddress)
4850

4951
utils.VerifyConnection(s.T(), 2, utils.AuxiliaryMockManagementPlaneAPIAddress)
5052
s.False(s.T().Failed())
5153
utils.VerifyUpdateDataPlaneHealth(s.T(), utils.AuxiliaryMockManagementPlaneAPIAddress)
54+
55+
commandResponses := utils.ManagementPlaneResponses(s.T(), 1, utils.MockManagementPlaneAPIAddress)
56+
s.Equal(mpi.CommandResponse_COMMAND_STATUS_OK, commandResponses[0].GetCommandResponse().GetStatus())
57+
s.Equal("Successfully updated all files", commandResponses[0].GetCommandResponse().GetMessage())
5258
}
5359

54-
func (s *AuxiliaryTestSuite) TestAuxiliary_Reconnection() {
60+
func (s *AuxiliaryTestSuite) TestAuxiliary_Test2_Reconnection() {
5561
ctx := context.Background()
5662
timeout := 15 * time.Second
5763

@@ -76,7 +82,7 @@ func (s *AuxiliaryTestSuite) TestAuxiliary_Reconnection() {
7682
s.Equal(originalID, currentID)
7783
}
7884

79-
func (s *AuxiliaryTestSuite) TestAuxiliary_DataplaneHealthRequest() {
85+
func (s *AuxiliaryTestSuite) TestAuxiliary_Test3_DataplaneHealthRequest() {
8086
utils.ClearManagementPlaneResponses(s.T(), utils.MockManagementPlaneAPIAddress)
8187
utils.ClearManagementPlaneResponses(s.T(), utils.AuxiliaryMockManagementPlaneAPIAddress)
8288

@@ -105,12 +111,12 @@ func (s *AuxiliaryTestSuite) TestAuxiliary_DataplaneHealthRequest() {
105111
s.Equal("Successfully sent health status update", commandResponses[0].GetCommandResponse().GetMessage())
106112
s.False(s.T().Failed())
107113

108-
// Check auxiliary server still only has 1 ManagementPlaneResponses as it didn't sent the request
114+
// Check auxiliary server still only has 1 ManagementPlaneResponses as it didn't send the request
109115
utils.ManagementPlaneResponses(s.T(), 0, utils.AuxiliaryMockManagementPlaneAPIAddress)
110116
s.False(s.T().Failed())
111117
}
112118

113-
func (s *AuxiliaryTestSuite) TestAuxiliary_FileWatcher() {
119+
func (s *AuxiliaryTestSuite) TestAuxiliary_Test4_FileWatcher() {
114120
// Clear any previous responses from previous tests
115121
utils.ClearManagementPlaneResponses(s.T(), utils.MockManagementPlaneAPIAddress)
116122
utils.ClearManagementPlaneResponses(s.T(), utils.AuxiliaryMockManagementPlaneAPIAddress)
@@ -135,59 +141,66 @@ func (s *AuxiliaryTestSuite) TestAuxiliary_FileWatcher() {
135141
s.Equal("Successfully updated all files", auxResponses[0].GetCommandResponse().GetMessage())
136142
}
137143

138-
// func (s *AuxiliaryTestSuite) TestAuxiliary_ConfigApply() {
139-
// s.instanceID = utils.VerifyConnection(s.T(), 2, utils.MockManagementPlaneAPIAddress)
140-
// // Perform config apply
141-
// // Check new config is in both Mocks
142-
// // Check using hash with new API endpoint which was added to get the file overview
143-
// utils.ClearManagementPlaneResponses(s.T(), utils.MockManagementPlaneAPIAddress)
144-
// utils.ClearManagementPlaneResponses(s.T(), utils.AuxiliaryMockManagementPlaneAPIAddress)
145-
//
146-
// ctx := context.Background()
147-
//
148-
// newConfigFile := "../../config/nginx/nginx-with-test-location.conf"
149-
//
150-
// if os.Getenv("IMAGE_PATH") == "/nginx-plus/agent" {
151-
// newConfigFile = "../../config/nginx/nginx-plus-with-test-location.conf"
152-
// }
153-
//
154-
// err := utils.MockManagementPlaneGrpcContainer.CopyFileToContainer(
155-
// ctx,
156-
// newConfigFile,
157-
// fmt.Sprintf("/mock-management-plane-grpc/config/%s/etc/nginx/nginx.conf", s.instanceID),
158-
// 0o666,
159-
// )
160-
//
161-
// require.NoError(s.T(), err)
162-
//
163-
// utils.PerformConfigApply(s.T(), s.instanceID, utils.MockManagementPlaneAPIAddress)
164-
//
165-
// commandResponses := utils.ManagementPlaneResponses(s.T(), 2, utils.MockManagementPlaneAPIAddress)
166-
//
167-
// sort.Slice(commandResponses, func(i, j int) bool {
168-
// return commandResponses[i].GetCommandResponse().GetMessage() <
169-
// commandResponses[j].GetCommandResponse().GetMessage()
170-
// })
171-
//
172-
// assert.Equal(s.T(), mpi.CommandResponse_COMMAND_STATUS_OK, commandResponses[0].GetCommandResponse().GetStatus())
173-
// assert.Equal(s.T(), "Config apply successful", commandResponses[0].GetCommandResponse().GetMessage())
174-
// assert.Equal(s.T(), mpi.CommandResponse_COMMAND_STATUS_OK, commandResponses[1].GetCommandResponse().GetStatus())
175-
// assert.Equal(s.T(), "Successfully updated all files", commandResponses[1].GetCommandResponse().GetMessage())
176-
//
177-
// auxResponses := utils.ManagementPlaneResponses(s.T(), 1, utils.AuxiliaryMockManagementPlaneAPIAddress)
178-
// assert.Equal(s.T(), mpi.CommandResponse_COMMAND_STATUS_OK, auxResponses[1].GetCommandResponse().GetStatus())
179-
// assert.Equal(s.T(), "Successfully updated all files", auxResponses[1].GetCommandResponse().GetMessage())
180-
//
181-
// overview := utils.CurrentFileOverview(s.T(), s.instanceID, utils.MockManagementPlaneAPIAddress)
182-
// overview2 := utils.CurrentFileOverview(s.T(), s.instanceID, utils.AuxiliaryMockManagementPlaneAPIAddress)
183-
// s.T().Logf("Overview: %v", overview.ConfigVersion)
184-
// s.T().Logf("Overview 2: %v", overview2.ConfigVersion)
185-
// }
144+
func (s *AuxiliaryTestSuite) TestAuxiliary_Test5_ConfigApply() {
145+
utils.ClearManagementPlaneResponses(s.T(), utils.MockManagementPlaneAPIAddress)
146+
utils.ClearManagementPlaneResponses(s.T(), utils.AuxiliaryMockManagementPlaneAPIAddress)
186147

187-
//
188-
// func (s *AuxiliaryTestSuite) TestAuxiliary_ConfigApplyInvalid() {
189-
// // Perform config apply with aux
190-
// // Check new config is broken
191-
// // Check using hash with new API endpoint which was added to get the file overview
192-
//
193-
// }
148+
ctx := context.Background()
149+
150+
newConfigFile := "../../config/nginx/nginx-with-test-location.conf"
151+
152+
if os.Getenv("IMAGE_PATH") == "/nginx-plus/agent" {
153+
newConfigFile = "../../config/nginx/nginx-plus-with-test-location.conf"
154+
}
155+
156+
err := utils.MockManagementPlaneGrpcContainer.CopyFileToContainer(
157+
ctx,
158+
newConfigFile,
159+
fmt.Sprintf("/mock-management-plane-grpc/config/%s/etc/nginx/nginx.conf", s.instanceID),
160+
0o666,
161+
)
162+
163+
s.Require().NoError(err)
164+
165+
utils.PerformConfigApply(s.T(), s.instanceID, utils.MockManagementPlaneAPIAddress)
166+
167+
commandResponses := utils.ManagementPlaneResponses(s.T(), 2, utils.MockManagementPlaneAPIAddress)
168+
169+
sort.Slice(commandResponses, func(i, j int) bool {
170+
return commandResponses[i].GetCommandResponse().GetMessage() <
171+
commandResponses[j].GetCommandResponse().GetMessage()
172+
})
173+
174+
s.Equal(mpi.CommandResponse_COMMAND_STATUS_OK, commandResponses[0].GetCommandResponse().GetStatus())
175+
s.Equal("Config apply successful", commandResponses[0].GetCommandResponse().GetMessage())
176+
s.Equal(mpi.CommandResponse_COMMAND_STATUS_OK, commandResponses[1].GetCommandResponse().GetStatus())
177+
s.Equal("Successfully updated all files", commandResponses[1].GetCommandResponse().GetMessage())
178+
179+
auxResponses := utils.ManagementPlaneResponses(s.T(), 1, utils.AuxiliaryMockManagementPlaneAPIAddress)
180+
s.Equal(mpi.CommandResponse_COMMAND_STATUS_OK, auxResponses[0].GetCommandResponse().GetStatus())
181+
s.Equal("Successfully updated all files", auxResponses[0].GetCommandResponse().GetMessage())
182+
183+
// Check the config version is the same in both command and auxiliary servers
184+
commandOverview := utils.CurrentFileOverview(s.T(), s.instanceID, utils.MockManagementPlaneAPIAddress)
185+
auxOverview := utils.CurrentFileOverview(s.T(), s.instanceID, utils.AuxiliaryMockManagementPlaneAPIAddress)
186+
s.Equal(commandOverview.GetConfigVersion(), auxOverview.GetConfigVersion())
187+
}
188+
189+
func (s *AuxiliaryTestSuite) TestAuxiliary_Test6_ConfigApplyInvalid() {
190+
// Perform config apply with aux
191+
// Check new config is broken
192+
// Check using hash with new API endpoint which was added to get the file overview
193+
194+
utils.ClearManagementPlaneResponses(s.T(), utils.MockManagementPlaneAPIAddress)
195+
utils.ClearManagementPlaneResponses(s.T(), utils.AuxiliaryMockManagementPlaneAPIAddress)
196+
197+
utils.PerformConfigApply(s.T(), s.instanceID, utils.AuxiliaryMockManagementPlaneAPIAddress)
198+
199+
commandResponses := utils.ManagementPlaneResponses(s.T(), 1,
200+
utils.AuxiliaryMockManagementPlaneAPIAddress)
201+
s.Equal(mpi.CommandResponse_COMMAND_STATUS_FAILURE,
202+
commandResponses[0].GetCommandResponse().GetStatus())
203+
s.Equal("Config apply failed", commandResponses[0].GetCommandResponse().GetMessage())
204+
s.Equal("Unable to process request. Management plane is configured as read only.",
205+
commandResponses[0].GetCommandResponse().GetError())
206+
}

test/integration/utils/config_apply_utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ func CurrentFileOverview(t *testing.T, nginxInstanceID, mockManagementPlaneAPIAd
5858

5959
responseData := resp.Body()
6060

61-
overview := mpi.FileOverview{}
61+
overview := mpi.GetOverviewResponse{}
6262

6363
pb := protojson.UnmarshalOptions{DiscardUnknown: true}
6464
unmarshalErr := pb.Unmarshal(responseData, &overview)
6565
require.NoError(t, unmarshalErr)
6666

67-
return &overview
67+
return overview.GetOverview()
6868
}
6969

7070
func PerformInvalidConfigApply(t *testing.T, nginxInstanceID string) {

test/mock/grpc/mock_management_command_service.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,7 @@ func (cs *CommandService) handleConfigUploadRequest(
181181
instanceID := upload.ConfigUploadRequest.GetOverview().GetConfigVersion().GetInstanceId()
182182
overviewFiles := upload.ConfigUploadRequest.GetOverview().GetFiles()
183183

184-
if cs.instanceFiles[instanceID] == nil {
185-
cs.instanceFiles[instanceID] = overviewFiles
186-
} else {
184+
if cs.instanceFiles[instanceID] != nil {
187185
filesToDelete := cs.checkForDeletedFiles(instanceID, overviewFiles)
188186
for _, fileToDelete := range filesToDelete {
189187
err := os.Remove(fileToDelete)
@@ -192,6 +190,7 @@ func (cs *CommandService) handleConfigUploadRequest(
192190
}
193191
}
194192
}
193+
cs.instanceFiles[instanceID] = overviewFiles
195194
}
196195

197196
func (cs *CommandService) checkForDeletedFiles(instanceID string, overviewFiles []*mpi.File) []string {
@@ -390,24 +389,24 @@ func (cs *CommandService) addConfigApplyEndpoint() {
390389
func (cs *CommandService) addConfigEndpoint() {
391390
cs.server.GET("/api/v1/instance/:instanceID/config", func(c *gin.Context) {
392391
instanceID := c.Param("instanceID")
392+
var data map[string]interface{}
393393

394-
configFiles, err := cs.findInstanceConfigFiles(instanceID)
395-
if err != nil {
396-
c.JSON(http.StatusInternalServerError, err)
397-
return
394+
response := &mpi.GetOverviewResponse{
395+
Overview: &mpi.FileOverview{
396+
ConfigVersion: &mpi.ConfigVersion{
397+
InstanceId: instanceID,
398+
Version: files.GenerateConfigVersion(cs.instanceFiles[instanceID]),
399+
},
400+
Files: cs.instanceFiles[instanceID],
401+
},
398402
}
399403

400-
cs.instanceFiles[instanceID] = configFiles
401-
402-
request := mpi.FileOverview{
403-
ConfigVersion: &mpi.ConfigVersion{
404-
InstanceId: instanceID,
405-
Version: files.GenerateConfigVersion(cs.instanceFiles[instanceID]),
406-
},
407-
Files: cs.instanceFiles[instanceID],
404+
if err := json.Unmarshal([]byte(protojson.Format(response)), &data); err != nil {
405+
slog.Error("Failed to return connection", "error", err)
406+
c.JSON(http.StatusInternalServerError, nil)
408407
}
409408

410-
c.JSON(http.StatusOK, &request)
409+
c.JSON(http.StatusOK, data)
411410
})
412411
}
413412

0 commit comments

Comments
 (0)