Skip to content

Commit

Permalink
Adding network config client to fault handler tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mye956 committed Sep 26, 2024
1 parent 2277f68 commit 62b681b
Show file tree
Hide file tree
Showing 9 changed files with 455 additions and 173 deletions.
5 changes: 5 additions & 0 deletions agent/handlers/v4/tmdsstate_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ func (s *TMDSAgentState) GetTaskMetadataWithTaskNetworkConfig(v3EndpointID strin
field.TaskARN: taskResponse.TaskARN,
field.Error: err,
})
} else {
logger.Info("Obtained default network interface name on host", logger.Fields{
field.TaskARN: taskResponse.TaskARN,
"defaultDeviceName": hostDeviceName,
})
}
taskResponse.TaskNetworkConfig.NetworkNamespaces[0].NetworkInterfaces[0].DeviceName = hostDeviceName
}
Expand Down
2 changes: 1 addition & 1 deletion agent/handlers/v4/tmdsstate_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ import (
)

func (s *TMDSAgentState) GetTaskMetadataWithTaskNetworkConfig(v3EndpointID string, networkConfigClient *tmdsv4.NetworkConfigClient) (tmdsv4.TaskResponse, error) {
return s.getTaskMetadata(v3EndpointID, true, true)
return s.getTaskMetadata(v3EndpointID, false, true)
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions agent/vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v1
github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v2
github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4
github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state
github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state/mocks
github.com/aws/amazon-ecs-agent/ecs-agent/tmds/logging
github.com/aws/amazon-ecs-agent/ecs-agent/tmds/utils/mux
github.com/aws/amazon-ecs-agent/ecs-agent/tmds/utils/netconfig
Expand Down
37 changes: 37 additions & 0 deletions ecs-agent/tmds/handlers/fault/v1/handlers/handlers_linux_tests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//go:build linux && unit
// +build linux,unit

// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

package handlers

import (
"github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/fault/v1/types"
state "github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state"
mock_state "github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state/mocks"
mock_execwrapper "github.com/aws/amazon-ecs-agent/ecs-agent/utils/execwrapper/mocks"
mock_netlinkwrapper "github.com/aws/amazon-ecs-agent/ecs-agent/utils/netlinkwrapper/mocks"

"github.com/golang/mock/gomock"
)

type networkFaultInjectionTestCase struct {
name string
expectedStatusCode int
requestBody interface{}
expectedResponseBody types.NetworkFaultInjectionResponse
setAgentStateExpectations func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient)
setNetLinkExpectations func(netLink *mock_netlinkwrapper.MockNetLink)
setExecExpectations func(exec *mock_execwrapper.MockExec, ctrl *gomock.Controller)
}
35 changes: 35 additions & 0 deletions ecs-agent/tmds/handlers/fault/v1/handlers/handlers_other_tests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//go:build !linux && unit
// +build !linux,unit

// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.

package handlers

import (
"github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/fault/v1/types"
state "github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state"
mock_state "github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state/mocks"
mock_execwrapper "github.com/aws/amazon-ecs-agent/ecs-agent/utils/execwrapper/mocks"

"github.com/golang/mock/gomock"
)

type networkFaultInjectionTestCase struct {
name string
expectedStatusCode int
requestBody interface{}
expectedResponseBody types.NetworkFaultInjectionResponse
setAgentStateExpectations func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient)
setExecExpectations func(exec *mock_execwrapper.MockExec, ctrl *gomock.Controller)
}
Loading

0 comments on commit 62b681b

Please sign in to comment.