Skip to content

Commit

Permalink
Expose FaultInjectionEnabled in Task Metadata Response (aws#4368)
Browse files Browse the repository at this point in the history
  • Loading branch information
xxx0624 authored Sep 30, 2024
1 parent 9ecdf05 commit 49a541d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
27 changes: 22 additions & 5 deletions agent/handlers/task_server_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,14 @@ func v4ContainerResponseFromV2(
}
}

// expectedV4TaskResponseWithFaultInjectionEnabled returns a standard v4 task response with
// FaultInjection enabled.
func expectedV4TaskResponseWithFaultInjectionEnabled() v4.TaskResponse {
taskResp := expectedV4TaskResponse()
taskResp.FaultInjectionEnabled = true
return taskResp
}

// Returns a standard v4 task response. This getter function protects against tests mutating
// the response.
func expectedV4TaskResponse() v4.TaskResponse {
Expand Down Expand Up @@ -595,6 +603,14 @@ func expectedV4TaskNetworkConfig(enableFaultInjection bool, networkMode, path, d
return v4.NewTaskNetworkConfig(networkMode, path, deviceName)
}

// expectedV4TaskResponseHostModeWithFaultInjectionEnabled returns a standard v4 task response with
// FaultInjection enabled.
func expectedV4TaskResponseHostModeWithFaultInjectionEnabled() v4.TaskResponse {
taskResp := expectedV4TaskResponseHostMode()
taskResp.FaultInjectionEnabled = true
return taskResp
}

func expectedV4TaskResponseHostMode() v4.TaskResponse {
return v4TaskResponseFromV2(
v2.TaskResponse{
Expand Down Expand Up @@ -709,9 +725,10 @@ func v4TaskResponseFromV2(
) v4.TaskResponse {
v2TaskResponse.Containers = nil
return v4.TaskResponse{
TaskResponse: &v2TaskResponse,
Containers: containers,
VPCID: vpcID,
TaskResponse: &v2TaskResponse,
Containers: containers,
VPCID: vpcID,
FaultInjectionEnabled: false,
}
}

Expand Down Expand Up @@ -2108,7 +2125,7 @@ func TestV4TaskMetadata(t *testing.T) {
)
},
expectedStatusCode: http.StatusOK,
expectedResponseBody: expectedV4TaskResponse(),
expectedResponseBody: expectedV4TaskResponseWithFaultInjectionEnabled(),
})
})

Expand All @@ -2130,7 +2147,7 @@ func TestV4TaskMetadata(t *testing.T) {
)
},
expectedStatusCode: http.StatusOK,
expectedResponseBody: expectedV4TaskResponseHostMode(),
expectedResponseBody: expectedV4TaskResponseHostModeWithFaultInjectionEnabled(),
})
})

Expand Down

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

5 changes: 2 additions & 3 deletions ecs-agent/tmds/handlers/v4/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,8 @@ func TestTaskMetadata(t *testing.T) {
t.Run("happy case with FaultInjection enabled", func(t *testing.T) {
metadata := taskResponseWithFaultInjectionEnabled()
expectedTaskResponse := taskResponseWithFaultInjectionEnabled()
expectedTaskResponse.CredentialsID = "" // credentials ID not expected
expectedTaskResponse.TaskNetworkConfig = nil // TaskNetworkConfig is not expected and would be used internally
expectedTaskResponse.FaultInjectionEnabled = false // FaultInjectionEnabled is not expected and would be used internally
expectedTaskResponse.CredentialsID = "" // credentials ID not expected
expectedTaskResponse.TaskNetworkConfig = nil // TaskNetworkConfig is not expected and would be used internally

handler, _, agentState, _ := setup(t)
agentState.EXPECT().
Expand Down
2 changes: 1 addition & 1 deletion ecs-agent/tmds/handlers/v4/state/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type TaskResponse struct {
EphemeralStorageMetrics *EphemeralStorageMetrics `json:"EphemeralStorageMetrics,omitempty"`
CredentialsID string `json:"-"`
TaskNetworkConfig *TaskNetworkConfig `json:"-"`
FaultInjectionEnabled bool `json:"-"`
FaultInjectionEnabled bool `json:"FaultInjectionEnabled,omitempty"`
}

// TaskNetworkConfig contains required network configurations for network faults injection.
Expand Down

0 comments on commit 49a541d

Please sign in to comment.