From e651ae874311800ed122d51f6fad9553ecc7fc11 Mon Sep 17 00:00:00 2001 From: mye956 Date: Thu, 26 Sep 2024 19:54:54 +0000 Subject: [PATCH] Moved NetConfigClient struct into netconfig --- .../handlers/task_server_setup_linux_test.go | 7 +- .../handlers/task_server_setup_other_test.go | 4 +- agent/handlers/v4/tmdsstate_linux.go | 4 +- agent/handlers/v4/tmdsstate_other.go | 5 +- .../handlers/fault/v1/handlers/handlers.go | 5 +- .../fault/v1/handlers/handlers_linux_tests.go | 37 ---- .../fault/v1/handlers/handlers_other_tests.go | 35 ---- .../handlers/v4/state/mocks/state_mock.go | 139 -------------- .../ecs-agent/tmds/handlers/v4/state/state.go | 12 +- .../tmds/handlers/v4/state/state_linux.go | 31 ---- .../tmds/utils/netconfig/netconfig_linux.go | 10 + .../utils/netconfig/netconfig_unsupported.go | 14 +- .../tmds/utils/netconfig/netconfig_windows.go | 7 + agent/vendor/modules.txt | 1 - .../handlers/fault/v1/handlers/handlers.go | 5 +- .../fault/v1/handlers/handlers_linux_tests.go | 37 ---- .../fault/v1/handlers/handlers_other_tests.go | 35 ---- .../fault/v1/handlers/handlers_test.go | 174 +++++++++--------- .../handlers/v4/state/mocks/state_mock.go | 3 +- ecs-agent/tmds/handlers/v4/state/state.go | 12 +- .../tmds/handlers/v4/state/state_linux.go | 31 ---- .../tmds/utils/netconfig/netconfig_linux.go | 10 + .../utils/netconfig/netconfig_unsupported.go | 14 +- .../tmds/utils/netconfig/netconfig_windows.go | 7 + 24 files changed, 189 insertions(+), 450 deletions(-) delete mode 100644 agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/fault/v1/handlers/handlers_linux_tests.go delete mode 100644 agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/fault/v1/handlers/handlers_other_tests.go delete mode 100644 agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state/mocks/state_mock.go delete mode 100644 agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state/state_linux.go rename ecs-agent/tmds/handlers/v4/state/state_unsupported.go => agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/utils/netconfig/netconfig_unsupported.go (65%) delete mode 100644 ecs-agent/tmds/handlers/fault/v1/handlers/handlers_linux_tests.go delete mode 100644 ecs-agent/tmds/handlers/fault/v1/handlers/handlers_other_tests.go delete mode 100644 ecs-agent/tmds/handlers/v4/state/state_linux.go rename agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state/state_unsupported.go => ecs-agent/tmds/utils/netconfig/netconfig_unsupported.go (65%) diff --git a/agent/handlers/task_server_setup_linux_test.go b/agent/handlers/task_server_setup_linux_test.go index 03b09b40243..ed06bf15357 100644 --- a/agent/handlers/task_server_setup_linux_test.go +++ b/agent/handlers/task_server_setup_linux_test.go @@ -26,6 +26,7 @@ import ( mock_stats "github.com/aws/amazon-ecs-agent/agent/stats/mock" mock_ecs "github.com/aws/amazon-ecs-agent/ecs-agent/api/ecs/mocks" v4 "github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state" + "github.com/aws/amazon-ecs-agent/ecs-agent/tmds/utils/netconfig" mock_netlinkwrapper "github.com/aws/amazon-ecs-agent/ecs-agent/utils/netlinkwrapper/mocks" "github.com/golang/mock/gomock" @@ -45,7 +46,7 @@ func TestV4GetTaskMetadataWithTaskNetworkConfig(t *testing.T) { name: "happy case with awsvpc mode", setStateExpectations: func(state *mock_dockerstate.MockTaskEngineState) { task := standardTask() - task.FaultInjectionEnabled = true + task.EnableFaultInjection = true task.NetworkNamespace = networkNamespace task.DefaultIfname = defaultIfname gomock.InOrder( @@ -64,7 +65,7 @@ func TestV4GetTaskMetadataWithTaskNetworkConfig(t *testing.T) { name: "happy case with host mode", setStateExpectations: func(state *mock_dockerstate.MockTaskEngineState) { hostTask := standardHostTask() - hostTask.FaultInjectionEnabled = true + hostTask.EnableFaultInjection = true hostTask.NetworkNamespace = networkNamespace hostTask.DefaultIfname = defaultIfname gomock.InOrder( @@ -127,7 +128,7 @@ func TestV4GetTaskMetadataWithTaskNetworkConfig(t *testing.T) { } tmdsAgentState := agentV4.NewTMDSAgentState(state, statsEngine, ecsClient, clusterName, availabilityzone, vpcID, containerInstanceArn) - netConfigClient := v4.NewNetworkConfigClient() + netConfigClient := netconfig.NewNetworkConfigClient() if tc.setNetLinkExpectations != nil { mock_netlinkwrapper := mock_netlinkwrapper.NewMockNetLink(ctrl) diff --git a/agent/handlers/task_server_setup_other_test.go b/agent/handlers/task_server_setup_other_test.go index cd7f14835c7..e4772afbc3a 100644 --- a/agent/handlers/task_server_setup_other_test.go +++ b/agent/handlers/task_server_setup_other_test.go @@ -41,7 +41,7 @@ func TestV4GetTaskMetadataWithTaskNetworkConfig(t *testing.T) { name: "happy case with awsvpc mode", setStateExpectations: func(state *mock_dockerstate.MockTaskEngineState) { task := standardTask() - task.FaultInjectionEnabled = true + task.EnableFaultInjection = true task.NetworkNamespace = networkNamespace task.DefaultIfname = defaultIfname gomock.InOrder( @@ -60,7 +60,7 @@ func TestV4GetTaskMetadataWithTaskNetworkConfig(t *testing.T) { name: "happy case with host mode", setStateExpectations: func(state *mock_dockerstate.MockTaskEngineState) { hostTask := standardHostTask() - hostTask.FaultInjectionEnabled = true + hostTask.EnableFaultInjection = true hostTask.NetworkNamespace = networkNamespace hostTask.DefaultIfname = defaultIfname gomock.InOrder( diff --git a/agent/handlers/v4/tmdsstate_linux.go b/agent/handlers/v4/tmdsstate_linux.go index 7f061b5c452..0b223692f29 100644 --- a/agent/handlers/v4/tmdsstate_linux.go +++ b/agent/handlers/v4/tmdsstate_linux.go @@ -23,7 +23,9 @@ import ( "github.com/aws/amazon-ecs-agent/ecs-agent/tmds/utils/netconfig" ) -func (s *TMDSAgentState) GetTaskMetadataWithTaskNetworkConfig(v3EndpointID string, networkConfigClient *tmdsv4.NetworkConfigClient) (tmdsv4.TaskResponse, error) { +// Returns task metadata including the task network configuration in v4 format for the +// task identified by the provided endpointContainerID. +func (s *TMDSAgentState) GetTaskMetadataWithTaskNetworkConfig(v3EndpointID string, networkConfigClient *netconfig.NetworkConfigClient) (tmdsv4.TaskResponse, error) { taskResponse, err := s.getTaskMetadata(v3EndpointID, false, true) if err == nil { if taskResponse.TaskNetworkConfig != nil && taskResponse.TaskNetworkConfig.NetworkMode == "host" { diff --git a/agent/handlers/v4/tmdsstate_other.go b/agent/handlers/v4/tmdsstate_other.go index 55b8fd1e484..ac3a029da95 100644 --- a/agent/handlers/v4/tmdsstate_other.go +++ b/agent/handlers/v4/tmdsstate_other.go @@ -18,8 +18,11 @@ package v4 import ( tmdsv4 "github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state" + "github.com/aws/amazon-ecs-agent/ecs-agent/tmds/utils/netconfig" ) -func (s *TMDSAgentState) GetTaskMetadataWithTaskNetworkConfig(v3EndpointID string, networkConfigClient *tmdsv4.NetworkConfigClient) (tmdsv4.TaskResponse, error) { +// Returns task metadata including the task network configuration in v4 format for the +// task identified by the provided endpointContainerID. +func (s *TMDSAgentState) GetTaskMetadataWithTaskNetworkConfig(v3EndpointID string, networkConfigClient *netconfig.NetworkConfigClient) (tmdsv4.TaskResponse, error) { return s.getTaskMetadata(v3EndpointID, false, true) } diff --git a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/fault/v1/handlers/handlers.go b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/fault/v1/handlers/handlers.go index 5e1b50ae530..b8fa1362f47 100644 --- a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/fault/v1/handlers/handlers.go +++ b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/fault/v1/handlers/handlers.go @@ -34,9 +34,10 @@ import ( "github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/utils" 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" + "github.com/aws/amazon-ecs-agent/ecs-agent/tmds/utils/netconfig" "github.com/aws/amazon-ecs-agent/ecs-agent/utils/execwrapper" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws" "github.com/gorilla/mux" ) @@ -933,7 +934,7 @@ func validateRequest(w http.ResponseWriter, request types.NetworkFaultRequest, r func validateTaskMetadata(w http.ResponseWriter, agentState state.AgentState, requestType string, r *http.Request) (*state.TaskResponse, error) { var taskMetadata state.TaskResponse endpointContainerID := mux.Vars(r)[v4.EndpointContainerIDMuxName] - taskMetadata, err := agentState.GetTaskMetadataWithTaskNetworkConfig(endpointContainerID, state.NewNetworkConfigClient()) + taskMetadata, err := agentState.GetTaskMetadataWithTaskNetworkConfig(endpointContainerID, netconfig.NewNetworkConfigClient()) if err != nil { code, errResponse := getTaskMetadataErrorResponse(endpointContainerID, requestType, err) responseBody := types.NewNetworkFaultInjectionErrorResponse(fmt.Sprintf("%v", errResponse)) diff --git a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/fault/v1/handlers/handlers_linux_tests.go b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/fault/v1/handlers/handlers_linux_tests.go deleted file mode 100644 index befd3a01a77..00000000000 --- a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/fault/v1/handlers/handlers_linux_tests.go +++ /dev/null @@ -1,37 +0,0 @@ -//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) -} diff --git a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/fault/v1/handlers/handlers_other_tests.go b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/fault/v1/handlers/handlers_other_tests.go deleted file mode 100644 index 6359684ecb1..00000000000 --- a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/fault/v1/handlers/handlers_other_tests.go +++ /dev/null @@ -1,35 +0,0 @@ -//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) -} diff --git a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state/mocks/state_mock.go b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state/mocks/state_mock.go deleted file mode 100644 index 1e61f643b19..00000000000 --- a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state/mocks/state_mock.go +++ /dev/null @@ -1,139 +0,0 @@ -// 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. -// - -// Code generated by MockGen. DO NOT EDIT. -// Source: github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state (interfaces: AgentState) - -// Package mock_state is a generated GoMock package. -package mock_state - -import ( - reflect "reflect" - - state "github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state" - gomock "github.com/golang/mock/gomock" -) - -// MockAgentState is a mock of AgentState interface. -type MockAgentState struct { - ctrl *gomock.Controller - recorder *MockAgentStateMockRecorder -} - -// MockAgentStateMockRecorder is the mock recorder for MockAgentState. -type MockAgentStateMockRecorder struct { - mock *MockAgentState -} - -// NewMockAgentState creates a new mock instance. -func NewMockAgentState(ctrl *gomock.Controller) *MockAgentState { - mock := &MockAgentState{ctrl: ctrl} - mock.recorder = &MockAgentStateMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockAgentState) EXPECT() *MockAgentStateMockRecorder { - return m.recorder -} - -// GetContainerMetadata mocks base method. -func (m *MockAgentState) GetContainerMetadata(arg0 string) (state.ContainerResponse, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetContainerMetadata", arg0) - ret0, _ := ret[0].(state.ContainerResponse) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetContainerMetadata indicates an expected call of GetContainerMetadata. -func (mr *MockAgentStateMockRecorder) GetContainerMetadata(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetContainerMetadata", reflect.TypeOf((*MockAgentState)(nil).GetContainerMetadata), arg0) -} - -// GetContainerStats mocks base method. -func (m *MockAgentState) GetContainerStats(arg0 string) (state.StatsResponse, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetContainerStats", arg0) - ret0, _ := ret[0].(state.StatsResponse) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetContainerStats indicates an expected call of GetContainerStats. -func (mr *MockAgentStateMockRecorder) GetContainerStats(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetContainerStats", reflect.TypeOf((*MockAgentState)(nil).GetContainerStats), arg0) -} - -// GetTaskMetadata mocks base method. -func (m *MockAgentState) GetTaskMetadata(arg0 string) (state.TaskResponse, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetTaskMetadata", arg0) - ret0, _ := ret[0].(state.TaskResponse) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetTaskMetadata indicates an expected call of GetTaskMetadata. -func (mr *MockAgentStateMockRecorder) GetTaskMetadata(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTaskMetadata", reflect.TypeOf((*MockAgentState)(nil).GetTaskMetadata), arg0) -} - -// GetTaskMetadataWithTags mocks base method. -func (m *MockAgentState) GetTaskMetadataWithTags(arg0 string) (state.TaskResponse, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetTaskMetadataWithTags", arg0) - ret0, _ := ret[0].(state.TaskResponse) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetTaskMetadataWithTags indicates an expected call of GetTaskMetadataWithTags. -func (mr *MockAgentStateMockRecorder) GetTaskMetadataWithTags(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTaskMetadataWithTags", reflect.TypeOf((*MockAgentState)(nil).GetTaskMetadataWithTags), arg0) -} - -// GetTaskMetadataWithTaskNetworkConfig mocks base method. -func (m *MockAgentState) GetTaskMetadataWithTaskNetworkConfig(arg0 string, arg1 *state.NetworkConfigClient) (state.TaskResponse, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetTaskMetadataWithTaskNetworkConfig", arg0, arg1) - ret0, _ := ret[0].(state.TaskResponse) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetTaskMetadataWithTaskNetworkConfig indicates an expected call of GetTaskMetadataWithTaskNetworkConfig. -func (mr *MockAgentStateMockRecorder) GetTaskMetadataWithTaskNetworkConfig(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTaskMetadataWithTaskNetworkConfig", reflect.TypeOf((*MockAgentState)(nil).GetTaskMetadataWithTaskNetworkConfig), arg0, arg1) -} - -// GetTaskStats mocks base method. -func (m *MockAgentState) GetTaskStats(arg0 string) (map[string]*state.StatsResponse, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetTaskStats", arg0) - ret0, _ := ret[0].(map[string]*state.StatsResponse) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// GetTaskStats indicates an expected call of GetTaskStats. -func (mr *MockAgentStateMockRecorder) GetTaskStats(arg0 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetTaskStats", reflect.TypeOf((*MockAgentState)(nil).GetTaskStats), arg0) -} diff --git a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state/state.go b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state/state.go index 668ad970b73..04ade945bbb 100644 --- a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state/state.go +++ b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state/state.go @@ -13,7 +13,11 @@ package state -import "fmt" +import ( + "fmt" + + "github.com/aws/amazon-ecs-agent/ecs-agent/tmds/utils/netconfig" +) // Error to be returned when container or task lookup failed type ErrorLookupFailure struct { @@ -109,7 +113,11 @@ type AgentState interface { // Returns ErrorMetadataFetchFailure if something else goes wrong. GetTaskMetadataWithTags(endpointContainerID string) (TaskResponse, error) - GetTaskMetadataWithTaskNetworkConfig(endpointContainerID string, networkConfigClient *NetworkConfigClient) (TaskResponse, error) + // Returns task metadata including the task network configuration (if applicable) in v4 format + // for the task identified by the provided endpointContainerID. + // Returns ErrorTaskLookupFailed if task lookup fails. + // Returns ErrorMetadataFetchFailure if something else goes wrong. + GetTaskMetadataWithTaskNetworkConfig(endpointContainerID string, networkConfigClient *netconfig.NetworkConfigClient) (TaskResponse, error) // Returns container stats in v4 format for the container identified by the provided // endpointContainerID. diff --git a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state/state_linux.go b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state/state_linux.go deleted file mode 100644 index 218c632d8cc..00000000000 --- a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state/state_linux.go +++ /dev/null @@ -1,31 +0,0 @@ -//go:build linux -// +build linux - -// 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 state - -import ( - "github.com/aws/amazon-ecs-agent/ecs-agent/utils/netlinkwrapper" -) - -type NetworkConfigClient struct { - NetlinkClient netlinkwrapper.NetLink -} - -func NewNetworkConfigClient() *NetworkConfigClient { - return &NetworkConfigClient{ - NetlinkClient: netlinkwrapper.New(), - } -} diff --git a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/utils/netconfig/netconfig_linux.go b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/utils/netconfig/netconfig_linux.go index 1df375c5a14..e8054a1d1de 100644 --- a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/utils/netconfig/netconfig_linux.go +++ b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/utils/netconfig/netconfig_linux.go @@ -24,6 +24,16 @@ import ( "github.com/vishvananda/netlink" ) +type NetworkConfigClient struct { + NetlinkClient netlinkwrapper.NetLink +} + +func NewNetworkConfigClient() *NetworkConfigClient { + return &NetworkConfigClient{ + NetlinkClient: netlinkwrapper.New(), + } +} + // DefaultNetInterfaceName returns the device name of the first default network interface // available on the instance. If none exist, an empty string and nil will be returned. func DefaultNetInterfaceName(netlinkClient netlinkwrapper.NetLink) (string, error) { diff --git a/ecs-agent/tmds/handlers/v4/state/state_unsupported.go b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/utils/netconfig/netconfig_unsupported.go similarity index 65% rename from ecs-agent/tmds/handlers/v4/state/state_unsupported.go rename to agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/utils/netconfig/netconfig_unsupported.go index ce6c4773011..fa1588458c8 100644 --- a/ecs-agent/tmds/handlers/v4/state/state_unsupported.go +++ b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/utils/netconfig/netconfig_unsupported.go @@ -1,5 +1,5 @@ -//go:build !linux -// +build !linux +//go:build !linux && !windows +// +build !linux,!windows // Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. // @@ -14,7 +14,9 @@ // express or implied. See the License for the specific language governing // permissions and limitations under the License. -package state +package netconfig + +import "errors" type NetworkConfigClient struct { } @@ -22,3 +24,9 @@ type NetworkConfigClient struct { func NewNetworkConfigClient() *NetworkConfigClient { return &NetworkConfigClient{} } + +// DefaultNetInterfaceName returns the device name of the first default network interface +// available on the instance. This is not supported on windows as of now. +func DefaultNetInterfaceName() (string, error) { + return "", errors.New("Not supported on unknown platform") +} diff --git a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/utils/netconfig/netconfig_windows.go b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/utils/netconfig/netconfig_windows.go index f7d24b7f63b..410695a2974 100644 --- a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/utils/netconfig/netconfig_windows.go +++ b/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/utils/netconfig/netconfig_windows.go @@ -18,6 +18,13 @@ package netconfig import "errors" +type NetworkConfigClient struct { +} + +func NewNetworkConfigClient() *NetworkConfigClient { + return &NetworkConfigClient{} +} + // DefaultNetInterfaceName returns the device name of the first default network interface // available on the instance. This is not supported on windows as of now. func DefaultNetInterfaceName() (string, error) { diff --git a/agent/vendor/modules.txt b/agent/vendor/modules.txt index 976d1ae7862..a5e3c5c0629 100644 --- a/agent/vendor/modules.txt +++ b/agent/vendor/modules.txt @@ -69,7 +69,6 @@ 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 diff --git a/ecs-agent/tmds/handlers/fault/v1/handlers/handlers.go b/ecs-agent/tmds/handlers/fault/v1/handlers/handlers.go index 5e1b50ae530..b8fa1362f47 100644 --- a/ecs-agent/tmds/handlers/fault/v1/handlers/handlers.go +++ b/ecs-agent/tmds/handlers/fault/v1/handlers/handlers.go @@ -34,9 +34,10 @@ import ( "github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/utils" 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" + "github.com/aws/amazon-ecs-agent/ecs-agent/tmds/utils/netconfig" "github.com/aws/amazon-ecs-agent/ecs-agent/utils/execwrapper" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws" "github.com/gorilla/mux" ) @@ -933,7 +934,7 @@ func validateRequest(w http.ResponseWriter, request types.NetworkFaultRequest, r func validateTaskMetadata(w http.ResponseWriter, agentState state.AgentState, requestType string, r *http.Request) (*state.TaskResponse, error) { var taskMetadata state.TaskResponse endpointContainerID := mux.Vars(r)[v4.EndpointContainerIDMuxName] - taskMetadata, err := agentState.GetTaskMetadataWithTaskNetworkConfig(endpointContainerID, state.NewNetworkConfigClient()) + taskMetadata, err := agentState.GetTaskMetadataWithTaskNetworkConfig(endpointContainerID, netconfig.NewNetworkConfigClient()) if err != nil { code, errResponse := getTaskMetadataErrorResponse(endpointContainerID, requestType, err) responseBody := types.NewNetworkFaultInjectionErrorResponse(fmt.Sprintf("%v", errResponse)) diff --git a/ecs-agent/tmds/handlers/fault/v1/handlers/handlers_linux_tests.go b/ecs-agent/tmds/handlers/fault/v1/handlers/handlers_linux_tests.go deleted file mode 100644 index befd3a01a77..00000000000 --- a/ecs-agent/tmds/handlers/fault/v1/handlers/handlers_linux_tests.go +++ /dev/null @@ -1,37 +0,0 @@ -//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) -} diff --git a/ecs-agent/tmds/handlers/fault/v1/handlers/handlers_other_tests.go b/ecs-agent/tmds/handlers/fault/v1/handlers/handlers_other_tests.go deleted file mode 100644 index 6359684ecb1..00000000000 --- a/ecs-agent/tmds/handlers/fault/v1/handlers/handlers_other_tests.go +++ /dev/null @@ -1,35 +0,0 @@ -//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) -} diff --git a/ecs-agent/tmds/handlers/fault/v1/handlers/handlers_test.go b/ecs-agent/tmds/handlers/fault/v1/handlers/handlers_test.go index 4d59a62486b..bb63d6dabf8 100644 --- a/ecs-agent/tmds/handlers/fault/v1/handlers/handlers_test.go +++ b/ecs-agent/tmds/handlers/fault/v1/handlers/handlers_test.go @@ -33,6 +33,7 @@ import ( v2 "github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v2" 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" + "github.com/aws/amazon-ecs-agent/ecs-agent/tmds/utils/netconfig" mock_execwrapper "github.com/aws/amazon-ecs-agent/ecs-agent/utils/execwrapper/mocks" "github.com/golang/mock/gomock" @@ -120,6 +121,15 @@ var ( checkNetworkPacketLossTestPrefix = fmt.Sprintf(checkStatusFaultRequestType, types.PacketLossFaultType) ) +type networkFaultInjectionTestCase struct { + name string + expectedStatusCode int + requestBody interface{} + expectedResponseBody types.NetworkFaultInjectionResponse + setAgentStateExpectations func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) + setExecExpectations func(exec *mock_execwrapper.MockExec, ctrl *gomock.Controller) +} + // Tests the path for Fault Network Faults API func TestFaultBlackholeFaultPath(t *testing.T) { assert.Equal(t, "/api/{endpointContainerIDMuxName:[^/]*}/fault/v1/network-blackhole-port/start", NetworkFaultPath(types.BlackHolePortFaultType, types.StartNetworkFaultPostfix)) @@ -156,7 +166,7 @@ func testNetworkFaultInjectionCommon(t *testing.T, router := mux.NewRouter() mockExec := mock_execwrapper.NewMockExec(ctrl) handler := New(agentState, metricsFactory, mockExec) - networkConfigClient := state.NewNetworkConfigClient() + networkConfigClient := netconfig.NewNetworkConfigClient() if tc.setAgentStateExpectations != nil { tc.setAgentStateExpectations(agentState, networkConfigClient) @@ -235,7 +245,7 @@ func generateCommonNetworkBlackHolePortTestCases(name string) []networkFaultInje expectedStatusCode: 400, requestBody: nil, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("required request body is missing"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{}, nil).Times(0) }, }, @@ -248,7 +258,7 @@ func generateCommonNetworkBlackHolePortTestCases(name string) []networkFaultInje "TrafficType": trafficType, }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("json: cannot unmarshal string into Go struct field NetworkBlackholePortRequest.Port of type uint16"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{}, nil).Times(0) }, }, @@ -260,7 +270,7 @@ func generateCommonNetworkBlackHolePortTestCases(name string) []networkFaultInje "Protocol": protocol, }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("required parameter TrafficType is missing"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{}, nil).Times(0) }, }, @@ -273,7 +283,7 @@ func generateCommonNetworkBlackHolePortTestCases(name string) []networkFaultInje "TrafficType": "", }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("required parameter TrafficType is missing"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{}, nil).Times(0) }, }, @@ -286,7 +296,7 @@ func generateCommonNetworkBlackHolePortTestCases(name string) []networkFaultInje "TrafficType": trafficType, }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("invalid value invalid for parameter Protocol"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{}, nil).Times(0) }, }, @@ -299,7 +309,7 @@ func generateCommonNetworkBlackHolePortTestCases(name string) []networkFaultInje "TrafficType": "invalid", }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("invalid value invalid for parameter TrafficType"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{}, nil).Times(0) }, }, @@ -308,7 +318,7 @@ func generateCommonNetworkBlackHolePortTestCases(name string) []networkFaultInje expectedStatusCode: 404, requestBody: happyBlackHolePortReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(fmt.Sprintf("unable to lookup container: %s", endpointId)), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(state.TaskResponse{}, state.NewErrorLookupFailure("task lookup failed")). Times(1) @@ -319,7 +329,7 @@ func generateCommonNetworkBlackHolePortTestCases(name string) []networkFaultInje expectedStatusCode: 500, requestBody: happyBlackHolePortReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(fmt.Sprintf("unable to obtain container metadata for container: %s", endpointId)), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{}, state.NewErrorMetadataFetchFailure( "Unable to generate metadata for task")). Times(1) @@ -330,7 +340,7 @@ func generateCommonNetworkBlackHolePortTestCases(name string) []networkFaultInje expectedStatusCode: 500, requestBody: happyBlackHolePortReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(fmt.Sprintf("failed to get task metadata due to internal server error for container: %s", endpointId)), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(state.TaskResponse{}, errors.New("unknown error")). Times(1) @@ -341,7 +351,7 @@ func generateCommonNetworkBlackHolePortTestCases(name string) []networkFaultInje expectedStatusCode: 400, requestBody: happyBlackHolePortReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(fmt.Sprintf(faultInjectionEnabledError, taskARN)), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{ TaskResponse: &v2.TaskResponse{TaskARN: taskARN}, FaultInjectionEnabled: false, @@ -353,7 +363,7 @@ func generateCommonNetworkBlackHolePortTestCases(name string) []networkFaultInje expectedStatusCode: 400, requestBody: happyBlackHolePortReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(fmt.Sprintf(invalidNetworkModeError, invalidNetworkMode)), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{ TaskResponse: &v2.TaskResponse{TaskARN: taskARN}, FaultInjectionEnabled: true, @@ -370,7 +380,7 @@ func generateCommonNetworkBlackHolePortTestCases(name string) []networkFaultInje requestBody: happyBlackHolePortReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse( fmt.Sprintf("failed to get task metadata due to internal server error for container: %s", endpointId)), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{ TaskResponse: &v2.TaskResponse{TaskARN: taskARN}, FaultInjectionEnabled: true, @@ -384,7 +394,7 @@ func generateCommonNetworkBlackHolePortTestCases(name string) []networkFaultInje requestBody: happyBlackHolePortReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse( fmt.Sprintf("failed to get task metadata due to internal server error for container: %s", endpointId)), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{ TaskResponse: &v2.TaskResponse{TaskARN: taskARN}, FaultInjectionEnabled: true, @@ -401,7 +411,7 @@ func generateCommonNetworkBlackHolePortTestCases(name string) []networkFaultInje requestBody: happyBlackHolePortReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse( fmt.Sprintf("failed to get task metadata due to internal server error for container: %s", endpointId)), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{ TaskResponse: &v2.TaskResponse{TaskARN: taskARN}, FaultInjectionEnabled: true, @@ -418,7 +428,7 @@ func generateCommonNetworkBlackHolePortTestCases(name string) []networkFaultInje requestBody: happyBlackHolePortReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse( fmt.Sprintf("failed to get task metadata due to internal server error for container: %s", endpointId)), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{ TaskResponse: &v2.TaskResponse{TaskARN: taskARN}, FaultInjectionEnabled: true, @@ -439,7 +449,7 @@ func generateCommonNetworkBlackHolePortTestCases(name string) []networkFaultInje expectedStatusCode: 500, requestBody: happyBlackHolePortReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(fmt.Sprintf(requestTimedOutError, name)), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(happyTaskResponse, nil). Times(1) @@ -467,7 +477,7 @@ func generateStartBlackHolePortFaultTestCases() []networkFaultInjectionTestCase expectedStatusCode: 200, requestBody: happyBlackHolePortReqBody, expectedResponseBody: types.NewNetworkFaultInjectionSuccessResponse("running"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(happyTaskResponse, nil). Times(1) @@ -500,7 +510,7 @@ func generateStartBlackHolePortFaultTestCases() []networkFaultInjectionTestCase "Unknown": "", }, expectedResponseBody: types.NewNetworkFaultInjectionSuccessResponse("running"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(happyTaskResponse, nil). Times(1) @@ -528,7 +538,7 @@ func generateStartBlackHolePortFaultTestCases() []networkFaultInjectionTestCase expectedStatusCode: 200, requestBody: happyBlackHolePortReqBody, expectedResponseBody: types.NewNetworkFaultInjectionSuccessResponse("running"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(happyTaskResponse, nil). Times(1) @@ -548,7 +558,7 @@ func generateStartBlackHolePortFaultTestCases() []networkFaultInjectionTestCase expectedStatusCode: 500, requestBody: happyBlackHolePortReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(iptablesChainAlreadyExistError), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(happyTaskResponse, nil). Times(1) @@ -572,7 +582,7 @@ func generateStartBlackHolePortFaultTestCases() []networkFaultInjectionTestCase expectedStatusCode: 500, requestBody: happyBlackHolePortReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(internalError), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(happyTaskResponse, nil). Times(1) @@ -598,7 +608,7 @@ func generateStartBlackHolePortFaultTestCases() []networkFaultInjectionTestCase expectedStatusCode: 500, requestBody: happyBlackHolePortReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(internalError), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(happyTaskResponse, nil). Times(1) @@ -634,7 +644,7 @@ func generateStopBlackHolePortFaultTestCases() []networkFaultInjectionTestCase { expectedStatusCode: 200, requestBody: happyBlackHolePortReqBody, expectedResponseBody: types.NewNetworkFaultInjectionSuccessResponse("stopped"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(happyTaskResponse, nil). Times(1) @@ -665,7 +675,7 @@ func generateStopBlackHolePortFaultTestCases() []networkFaultInjectionTestCase { "Unknown": "", }, expectedResponseBody: types.NewNetworkFaultInjectionSuccessResponse("stopped"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(happyTaskResponse, nil). Times(1) @@ -691,7 +701,7 @@ func generateStopBlackHolePortFaultTestCases() []networkFaultInjectionTestCase { expectedStatusCode: 200, requestBody: happyBlackHolePortReqBody, expectedResponseBody: types.NewNetworkFaultInjectionSuccessResponse("stopped"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(happyTaskResponse, nil). Times(1) @@ -713,7 +723,7 @@ func generateStopBlackHolePortFaultTestCases() []networkFaultInjectionTestCase { expectedStatusCode: 500, requestBody: happyBlackHolePortReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(internalError), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(happyTaskResponse, nil). Times(1) @@ -735,7 +745,7 @@ func generateStopBlackHolePortFaultTestCases() []networkFaultInjectionTestCase { expectedStatusCode: 500, requestBody: happyBlackHolePortReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(internalError), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(happyTaskResponse, nil). Times(1) @@ -759,7 +769,7 @@ func generateStopBlackHolePortFaultTestCases() []networkFaultInjectionTestCase { expectedStatusCode: 500, requestBody: happyBlackHolePortReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(internalError), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(happyTaskResponse, nil). Times(1) @@ -792,7 +802,7 @@ func generateCheckBlackHolePortFaultStatusTestCases() []networkFaultInjectionTes expectedStatusCode: 200, requestBody: happyBlackHolePortReqBody, expectedResponseBody: types.NewNetworkFaultInjectionSuccessResponse("running"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(happyTaskResponse, nil). Times(1) @@ -817,7 +827,7 @@ func generateCheckBlackHolePortFaultStatusTestCases() []networkFaultInjectionTes "Unknown": "", }, expectedResponseBody: types.NewNetworkFaultInjectionSuccessResponse("running"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(happyTaskResponse, nil). Times(1) @@ -837,7 +847,7 @@ func generateCheckBlackHolePortFaultStatusTestCases() []networkFaultInjectionTes expectedStatusCode: 200, requestBody: happyBlackHolePortReqBody, expectedResponseBody: types.NewNetworkFaultInjectionSuccessResponse("not-running"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(happyTaskResponse, nil). Times(1) @@ -859,7 +869,7 @@ func generateCheckBlackHolePortFaultStatusTestCases() []networkFaultInjectionTes expectedStatusCode: 500, requestBody: happyBlackHolePortReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(internalError), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(happyTaskResponse, nil). Times(1) @@ -907,7 +917,7 @@ func generateNetworkLatencyTestCases(name, expectedHappyResponseBody string) []n expectedStatusCode: 200, requestBody: happyNetworkLatencyReqBody, expectedResponseBody: types.NewNetworkFaultInjectionSuccessResponse(expectedHappyResponseBody), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(happyTaskResponse, nil). Times(1) @@ -923,7 +933,7 @@ func generateNetworkLatencyTestCases(name, expectedHappyResponseBody string) []n "Unknown": "", }, expectedResponseBody: types.NewNetworkFaultInjectionSuccessResponse(expectedHappyResponseBody), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(happyTaskResponse, nil). Times(1) @@ -934,7 +944,7 @@ func generateNetworkLatencyTestCases(name, expectedHappyResponseBody string) []n expectedStatusCode: 400, requestBody: nil, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("required request body is missing"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{}, nil).Times(0) }, }, @@ -947,7 +957,7 @@ func generateNetworkLatencyTestCases(name, expectedHappyResponseBody string) []n "Sources": ipSources, }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("json: cannot unmarshal string into Go struct field NetworkLatencyRequest.DelayMilliseconds of type uint64"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(state.TaskResponse{}, nil). Times(0) @@ -962,7 +972,7 @@ func generateNetworkLatencyTestCases(name, expectedHappyResponseBody string) []n "Sources": ipSources, }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("json: cannot unmarshal string into Go struct field NetworkLatencyRequest.JitterMilliseconds of type uint64"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(state.TaskResponse{}, nil). Times(0) @@ -977,7 +987,7 @@ func generateNetworkLatencyTestCases(name, expectedHappyResponseBody string) []n "Sources": "", }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("json: cannot unmarshal string into Go struct field NetworkLatencyRequest.Sources of type []*string"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(state.TaskResponse{}, nil). Times(0) @@ -992,7 +1002,7 @@ func generateNetworkLatencyTestCases(name, expectedHappyResponseBody string) []n "Sources": []string{}, }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("required parameter Sources is missing"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(state.TaskResponse{}, nil). Times(0) @@ -1006,7 +1016,7 @@ func generateNetworkLatencyTestCases(name, expectedHappyResponseBody string) []n "JitterMilliseconds": jitterMilliseconds, }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("required parameter Sources is missing"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(state.TaskResponse{}, nil). Times(0) @@ -1020,7 +1030,7 @@ func generateNetworkLatencyTestCases(name, expectedHappyResponseBody string) []n "Sources": ipSources, }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("required parameter JitterMilliseconds is missing"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(state.TaskResponse{}, nil). Times(0) @@ -1034,7 +1044,7 @@ func generateNetworkLatencyTestCases(name, expectedHappyResponseBody string) []n "Sources": ipSources, }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("required parameter DelayMilliseconds is missing"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(state.TaskResponse{}, nil). Times(0) @@ -1049,7 +1059,7 @@ func generateNetworkLatencyTestCases(name, expectedHappyResponseBody string) []n "Sources": []string{"10.1.2.3.4"}, }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("invalid value 10.1.2.3.4 for parameter Sources"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(state.TaskResponse{}, nil). Times(0) @@ -1064,7 +1074,7 @@ func generateNetworkLatencyTestCases(name, expectedHappyResponseBody string) []n "Sources": []string{"52.95.154.0/33"}, }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("invalid value 52.95.154.0/33 for parameter Sources"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(state.TaskResponse{}, nil). Times(0) @@ -1075,7 +1085,7 @@ func generateNetworkLatencyTestCases(name, expectedHappyResponseBody string) []n expectedStatusCode: 404, requestBody: happyNetworkLatencyReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(fmt.Sprintf("unable to lookup container: %s", endpointId)), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(state.TaskResponse{}, state.NewErrorLookupFailure("task lookup failed")). Times(1) @@ -1086,7 +1096,7 @@ func generateNetworkLatencyTestCases(name, expectedHappyResponseBody string) []n expectedStatusCode: 500, requestBody: happyNetworkLatencyReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(fmt.Sprintf("unable to obtain container metadata for container: %s", endpointId)), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(state.TaskResponse{}, state.NewErrorMetadataFetchFailure( "Unable to generate metadata for task")). @@ -1098,7 +1108,7 @@ func generateNetworkLatencyTestCases(name, expectedHappyResponseBody string) []n expectedStatusCode: 500, requestBody: happyNetworkLatencyReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(fmt.Sprintf("failed to get task metadata due to internal server error for container: %s", endpointId)), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient). Return(state.TaskResponse{}, errors.New("unknown error")). Times(1) @@ -1109,7 +1119,7 @@ func generateNetworkLatencyTestCases(name, expectedHappyResponseBody string) []n expectedStatusCode: 400, requestBody: happyNetworkLatencyReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(fmt.Sprintf(faultInjectionEnabledError, taskARN)), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{ TaskResponse: &v2.TaskResponse{TaskARN: taskARN}, FaultInjectionEnabled: false, @@ -1121,7 +1131,7 @@ func generateNetworkLatencyTestCases(name, expectedHappyResponseBody string) []n expectedStatusCode: 400, requestBody: happyNetworkLatencyReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(fmt.Sprintf(invalidNetworkModeError, invalidNetworkMode)), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{ TaskResponse: &v2.TaskResponse{TaskARN: taskARN}, FaultInjectionEnabled: true, @@ -1137,7 +1147,7 @@ func generateNetworkLatencyTestCases(name, expectedHappyResponseBody string) []n expectedStatusCode: 500, requestBody: happyNetworkLatencyReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(fmt.Sprintf("failed to get task metadata due to internal server error for container: %s", endpointId)), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{ TaskResponse: &v2.TaskResponse{TaskARN: taskARN}, FaultInjectionEnabled: true, @@ -1174,7 +1184,7 @@ func generateCommonNetworkPacketLossTestCases(name string) []networkFaultInjecti "Sources": ipSources, }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("json: cannot unmarshal string into Go struct field NetworkPacketLossRequest.LossPercent of type uint64"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{}, nil).Times(0) }, }, @@ -1186,7 +1196,7 @@ func generateCommonNetworkPacketLossTestCases(name string) []networkFaultInjecti "Sources": "", }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("json: cannot unmarshal string into Go struct field NetworkPacketLossRequest.Sources of type []*string"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{}, nil).Times(0) }, }, @@ -1198,7 +1208,7 @@ func generateCommonNetworkPacketLossTestCases(name string) []networkFaultInjecti "Sources": []string{}, }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("required parameter Sources is missing"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{}, nil).Times(0) }, }, @@ -1209,7 +1219,7 @@ func generateCommonNetworkPacketLossTestCases(name string) []networkFaultInjecti "LossPercent": lossPercent, }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("required parameter Sources is missing"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{}, nil).Times(0) }, }, @@ -1220,7 +1230,7 @@ func generateCommonNetworkPacketLossTestCases(name string) []networkFaultInjecti "Sources": ipSources, }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("required parameter LossPercent is missing"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{}, nil).Times(0) }, }, @@ -1232,7 +1242,7 @@ func generateCommonNetworkPacketLossTestCases(name string) []networkFaultInjecti "Sources": ipSources, }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("json: cannot unmarshal number -1 into Go struct field NetworkPacketLossRequest.LossPercent of type uint64"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{}, nil).Times(0) }, }, @@ -1244,7 +1254,7 @@ func generateCommonNetworkPacketLossTestCases(name string) []networkFaultInjecti "Sources": ipSources, }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("invalid value 101 for parameter LossPercent"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{}, nil).Times(0) }, }, @@ -1256,7 +1266,7 @@ func generateCommonNetworkPacketLossTestCases(name string) []networkFaultInjecti "Sources": ipSources, }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("invalid value 0 for parameter LossPercent"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{}, nil).Times(0) }, }, @@ -1268,7 +1278,7 @@ func generateCommonNetworkPacketLossTestCases(name string) []networkFaultInjecti "Sources": []string{"10.1.2.3.4"}, }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("invalid value 10.1.2.3.4 for parameter Sources"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{}, nil).Times(0) }, }, @@ -1280,7 +1290,7 @@ func generateCommonNetworkPacketLossTestCases(name string) []networkFaultInjecti "Sources": []string{"52.95.154.0/33"}, }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("invalid value 52.95.154.0/33 for parameter Sources"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{}, nil).Times(0) }, }, @@ -1289,7 +1299,7 @@ func generateCommonNetworkPacketLossTestCases(name string) []networkFaultInjecti expectedStatusCode: 404, requestBody: happyNetworkPacketLossReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(fmt.Sprintf("unable to lookup container: %s", endpointId)), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{}, state.NewErrorLookupFailure("task lookup failed")) }, }, @@ -1298,7 +1308,7 @@ func generateCommonNetworkPacketLossTestCases(name string) []networkFaultInjecti expectedStatusCode: 500, requestBody: happyNetworkPacketLossReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(fmt.Sprintf("unable to obtain container metadata for container: %s", endpointId)), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{}, state.NewErrorMetadataFetchFailure( "Unable to generate metadata for task")) }, @@ -1308,7 +1318,7 @@ func generateCommonNetworkPacketLossTestCases(name string) []networkFaultInjecti expectedStatusCode: 500, requestBody: happyNetworkPacketLossReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(fmt.Sprintf("failed to get task metadata due to internal server error for container: %s", endpointId)), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{}, errors.New("unknown error")) }, }, @@ -1317,7 +1327,7 @@ func generateCommonNetworkPacketLossTestCases(name string) []networkFaultInjecti expectedStatusCode: 400, requestBody: happyNetworkPacketLossReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(fmt.Sprintf(faultInjectionEnabledError, taskARN)), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{ TaskResponse: &v2.TaskResponse{TaskARN: taskARN}, FaultInjectionEnabled: false, @@ -1329,7 +1339,7 @@ func generateCommonNetworkPacketLossTestCases(name string) []networkFaultInjecti expectedStatusCode: 400, requestBody: happyNetworkPacketLossReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(fmt.Sprintf(invalidNetworkModeError, invalidNetworkMode)), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{ TaskResponse: &v2.TaskResponse{TaskARN: taskARN}, FaultInjectionEnabled: true, @@ -1345,7 +1355,7 @@ func generateCommonNetworkPacketLossTestCases(name string) []networkFaultInjecti expectedStatusCode: 500, requestBody: happyNetworkPacketLossReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(fmt.Sprintf("failed to get task metadata due to internal server error for container: %s", endpointId)), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(state.TaskResponse{ TaskResponse: &v2.TaskResponse{TaskARN: taskARN}, FaultInjectionEnabled: true, @@ -1362,7 +1372,7 @@ func generateCommonNetworkPacketLossTestCases(name string) []networkFaultInjecti "Unknown": "", }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("failed to check existing network fault: failed to unmarshal tc command output: unexpected end of JSON input. TaskArn: taskArn"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(happyTaskResponse, nil) }, setExecExpectations: func(exec *mock_execwrapper.MockExec, ctrl *gomock.Controller) { @@ -1382,7 +1392,7 @@ func generateCommonNetworkPacketLossTestCases(name string) []networkFaultInjecti "Unknown": "", }, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("failed to check existing network fault: 'nsenter --net=/some/path tc -j q show dev eth0 parent 1:1' command failed with the following error: 'signal: killed'. std output: ''. TaskArn: taskArn"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(happyTaskResponse, nil) }, setExecExpectations: func(exec *mock_execwrapper.MockExec, ctrl *gomock.Controller) { @@ -1398,7 +1408,7 @@ func generateCommonNetworkPacketLossTestCases(name string) []networkFaultInjecti expectedStatusCode: 500, requestBody: happyNetworkPacketLossReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse(fmt.Sprintf(requestTimedOutError, name)), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(happyTaskResponse, nil) }, setExecExpectations: func(exec *mock_execwrapper.MockExec, ctrl *gomock.Controller) { @@ -1423,7 +1433,7 @@ func generateStartNetworkPacketLossTestCases() []networkFaultInjectionTestCase { expectedStatusCode: 200, requestBody: happyNetworkPacketLossReqBody, expectedResponseBody: types.NewNetworkFaultInjectionSuccessResponse("running"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(happyTaskResponse, nil) }, setExecExpectations: func(exec *mock_execwrapper.MockExec, ctrl *gomock.Controller) { @@ -1443,7 +1453,7 @@ func generateStartNetworkPacketLossTestCases() []networkFaultInjectionTestCase { expectedStatusCode: 409, requestBody: happyNetworkPacketLossReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("There is already one network latency fault running"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(happyTaskResponse, nil) }, setExecExpectations: func(exec *mock_execwrapper.MockExec, ctrl *gomock.Controller) { @@ -1459,7 +1469,7 @@ func generateStartNetworkPacketLossTestCases() []networkFaultInjectionTestCase { expectedStatusCode: 409, requestBody: happyNetworkPacketLossReqBody, expectedResponseBody: types.NewNetworkFaultInjectionErrorResponse("There is already one network packet loss fault running"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(happyTaskResponse, nil) }, setExecExpectations: func(exec *mock_execwrapper.MockExec, ctrl *gomock.Controller) { @@ -1479,7 +1489,7 @@ func generateStartNetworkPacketLossTestCases() []networkFaultInjectionTestCase { "Unknown": "", }, expectedResponseBody: types.NewNetworkFaultInjectionSuccessResponse("running"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(happyTaskResponse, nil) }, setExecExpectations: func(exec *mock_execwrapper.MockExec, ctrl *gomock.Controller) { @@ -1506,7 +1516,7 @@ func generateStopNetworkPacketLossTestCases() []networkFaultInjectionTestCase { expectedStatusCode: 200, requestBody: happyNetworkPacketLossReqBody, expectedResponseBody: types.NewNetworkFaultInjectionSuccessResponse("stopped"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(happyTaskResponse, nil) }, setExecExpectations: func(exec *mock_execwrapper.MockExec, ctrl *gomock.Controller) { @@ -1524,7 +1534,7 @@ func generateStopNetworkPacketLossTestCases() []networkFaultInjectionTestCase { expectedStatusCode: 200, requestBody: happyNetworkPacketLossReqBody, expectedResponseBody: types.NewNetworkFaultInjectionSuccessResponse("stopped"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(happyTaskResponse, nil) }, setExecExpectations: func(exec *mock_execwrapper.MockExec, ctrl *gomock.Controller) { @@ -1540,7 +1550,7 @@ func generateStopNetworkPacketLossTestCases() []networkFaultInjectionTestCase { expectedStatusCode: 200, requestBody: happyNetworkPacketLossReqBody, expectedResponseBody: types.NewNetworkFaultInjectionSuccessResponse("stopped"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(happyTaskResponse, nil) }, setExecExpectations: func(exec *mock_execwrapper.MockExec, ctrl *gomock.Controller) { @@ -1564,7 +1574,7 @@ func generateStopNetworkPacketLossTestCases() []networkFaultInjectionTestCase { "Unknown": "", }, expectedResponseBody: types.NewNetworkFaultInjectionSuccessResponse("stopped"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(happyTaskResponse, nil) }, setExecExpectations: func(exec *mock_execwrapper.MockExec, ctrl *gomock.Controller) { @@ -1589,7 +1599,7 @@ func generateCheckNetworkPacketLossTestCases() []networkFaultInjectionTestCase { expectedStatusCode: 200, requestBody: happyNetworkPacketLossReqBody, expectedResponseBody: types.NewNetworkFaultInjectionSuccessResponse("not-running"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(happyTaskResponse, nil) }, setExecExpectations: func(exec *mock_execwrapper.MockExec, ctrl *gomock.Controller) { @@ -1607,7 +1617,7 @@ func generateCheckNetworkPacketLossTestCases() []networkFaultInjectionTestCase { expectedStatusCode: 200, requestBody: happyNetworkPacketLossReqBody, expectedResponseBody: types.NewNetworkFaultInjectionSuccessResponse("not-running"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(happyTaskResponse, nil) }, setExecExpectations: func(exec *mock_execwrapper.MockExec, ctrl *gomock.Controller) { @@ -1625,7 +1635,7 @@ func generateCheckNetworkPacketLossTestCases() []networkFaultInjectionTestCase { expectedStatusCode: 200, requestBody: happyNetworkPacketLossReqBody, expectedResponseBody: types.NewNetworkFaultInjectionSuccessResponse("running"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(happyTaskResponse, nil) }, setExecExpectations: func(exec *mock_execwrapper.MockExec, ctrl *gomock.Controller) { @@ -1647,7 +1657,7 @@ func generateCheckNetworkPacketLossTestCases() []networkFaultInjectionTestCase { "Unknown": "", }, expectedResponseBody: types.NewNetworkFaultInjectionSuccessResponse("not-running"), - setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *state.NetworkConfigClient) { + setAgentStateExpectations: func(agentState *mock_state.MockAgentState, netConfigClient *netconfig.NetworkConfigClient) { agentState.EXPECT().GetTaskMetadataWithTaskNetworkConfig(endpointId, netConfigClient).Return(happyTaskResponse, nil) }, setExecExpectations: func(exec *mock_execwrapper.MockExec, ctrl *gomock.Controller) { diff --git a/ecs-agent/tmds/handlers/v4/state/mocks/state_mock.go b/ecs-agent/tmds/handlers/v4/state/mocks/state_mock.go index 1e61f643b19..1252fbb5eaa 100644 --- a/ecs-agent/tmds/handlers/v4/state/mocks/state_mock.go +++ b/ecs-agent/tmds/handlers/v4/state/mocks/state_mock.go @@ -22,6 +22,7 @@ import ( reflect "reflect" state "github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state" + netconfig "github.com/aws/amazon-ecs-agent/ecs-agent/tmds/utils/netconfig" gomock "github.com/golang/mock/gomock" ) @@ -109,7 +110,7 @@ func (mr *MockAgentStateMockRecorder) GetTaskMetadataWithTags(arg0 interface{}) } // GetTaskMetadataWithTaskNetworkConfig mocks base method. -func (m *MockAgentState) GetTaskMetadataWithTaskNetworkConfig(arg0 string, arg1 *state.NetworkConfigClient) (state.TaskResponse, error) { +func (m *MockAgentState) GetTaskMetadataWithTaskNetworkConfig(arg0 string, arg1 *netconfig.NetworkConfigClient) (state.TaskResponse, error) { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetTaskMetadataWithTaskNetworkConfig", arg0, arg1) ret0, _ := ret[0].(state.TaskResponse) diff --git a/ecs-agent/tmds/handlers/v4/state/state.go b/ecs-agent/tmds/handlers/v4/state/state.go index 668ad970b73..04ade945bbb 100644 --- a/ecs-agent/tmds/handlers/v4/state/state.go +++ b/ecs-agent/tmds/handlers/v4/state/state.go @@ -13,7 +13,11 @@ package state -import "fmt" +import ( + "fmt" + + "github.com/aws/amazon-ecs-agent/ecs-agent/tmds/utils/netconfig" +) // Error to be returned when container or task lookup failed type ErrorLookupFailure struct { @@ -109,7 +113,11 @@ type AgentState interface { // Returns ErrorMetadataFetchFailure if something else goes wrong. GetTaskMetadataWithTags(endpointContainerID string) (TaskResponse, error) - GetTaskMetadataWithTaskNetworkConfig(endpointContainerID string, networkConfigClient *NetworkConfigClient) (TaskResponse, error) + // Returns task metadata including the task network configuration (if applicable) in v4 format + // for the task identified by the provided endpointContainerID. + // Returns ErrorTaskLookupFailed if task lookup fails. + // Returns ErrorMetadataFetchFailure if something else goes wrong. + GetTaskMetadataWithTaskNetworkConfig(endpointContainerID string, networkConfigClient *netconfig.NetworkConfigClient) (TaskResponse, error) // Returns container stats in v4 format for the container identified by the provided // endpointContainerID. diff --git a/ecs-agent/tmds/handlers/v4/state/state_linux.go b/ecs-agent/tmds/handlers/v4/state/state_linux.go deleted file mode 100644 index 218c632d8cc..00000000000 --- a/ecs-agent/tmds/handlers/v4/state/state_linux.go +++ /dev/null @@ -1,31 +0,0 @@ -//go:build linux -// +build linux - -// 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 state - -import ( - "github.com/aws/amazon-ecs-agent/ecs-agent/utils/netlinkwrapper" -) - -type NetworkConfigClient struct { - NetlinkClient netlinkwrapper.NetLink -} - -func NewNetworkConfigClient() *NetworkConfigClient { - return &NetworkConfigClient{ - NetlinkClient: netlinkwrapper.New(), - } -} diff --git a/ecs-agent/tmds/utils/netconfig/netconfig_linux.go b/ecs-agent/tmds/utils/netconfig/netconfig_linux.go index 1df375c5a14..e8054a1d1de 100644 --- a/ecs-agent/tmds/utils/netconfig/netconfig_linux.go +++ b/ecs-agent/tmds/utils/netconfig/netconfig_linux.go @@ -24,6 +24,16 @@ import ( "github.com/vishvananda/netlink" ) +type NetworkConfigClient struct { + NetlinkClient netlinkwrapper.NetLink +} + +func NewNetworkConfigClient() *NetworkConfigClient { + return &NetworkConfigClient{ + NetlinkClient: netlinkwrapper.New(), + } +} + // DefaultNetInterfaceName returns the device name of the first default network interface // available on the instance. If none exist, an empty string and nil will be returned. func DefaultNetInterfaceName(netlinkClient netlinkwrapper.NetLink) (string, error) { diff --git a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state/state_unsupported.go b/ecs-agent/tmds/utils/netconfig/netconfig_unsupported.go similarity index 65% rename from agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state/state_unsupported.go rename to ecs-agent/tmds/utils/netconfig/netconfig_unsupported.go index ce6c4773011..fa1588458c8 100644 --- a/agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/tmds/handlers/v4/state/state_unsupported.go +++ b/ecs-agent/tmds/utils/netconfig/netconfig_unsupported.go @@ -1,5 +1,5 @@ -//go:build !linux -// +build !linux +//go:build !linux && !windows +// +build !linux,!windows // Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. // @@ -14,7 +14,9 @@ // express or implied. See the License for the specific language governing // permissions and limitations under the License. -package state +package netconfig + +import "errors" type NetworkConfigClient struct { } @@ -22,3 +24,9 @@ type NetworkConfigClient struct { func NewNetworkConfigClient() *NetworkConfigClient { return &NetworkConfigClient{} } + +// DefaultNetInterfaceName returns the device name of the first default network interface +// available on the instance. This is not supported on windows as of now. +func DefaultNetInterfaceName() (string, error) { + return "", errors.New("Not supported on unknown platform") +} diff --git a/ecs-agent/tmds/utils/netconfig/netconfig_windows.go b/ecs-agent/tmds/utils/netconfig/netconfig_windows.go index f7d24b7f63b..410695a2974 100644 --- a/ecs-agent/tmds/utils/netconfig/netconfig_windows.go +++ b/ecs-agent/tmds/utils/netconfig/netconfig_windows.go @@ -18,6 +18,13 @@ package netconfig import "errors" +type NetworkConfigClient struct { +} + +func NewNetworkConfigClient() *NetworkConfigClient { + return &NetworkConfigClient{} +} + // DefaultNetInterfaceName returns the device name of the first default network interface // available on the instance. This is not supported on windows as of now. func DefaultNetInterfaceName() (string, error) {