Skip to content

Commit

Permalink
eventhandler: fix the bug where container state change was not submitted
Browse files Browse the repository at this point in the history
  • Loading branch information
Peng Yin committed Nov 10, 2017
1 parent d2dd240 commit 9f536ef
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased
* Bug - Fixed a bug where container state change information wasn't reported.
[#1066](https://github.com/aws/amazon-ecs-agent/pull/1066)

## 1.15.0
* Feature - Support for provisioning tasks with ENIs.
* Feature - Support for `--init` Docker run flag. [#996](https://github.com/aws/amazon-ecs-agent/pull/996)
Expand Down
4 changes: 2 additions & 2 deletions agent/api/ecsclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,13 @@ func (client *APIECSClient) SubmitTaskStateChange(change api.TaskStateChange) er
return errors.New("ecs api client: SubmitTaskStateChange called with an invalid change")
}

if change.Status != api.TaskRunning && change.Status != api.TaskStopped {
if change.Status != api.TaskRunning && change.Status != api.TaskStopped && len(change.Containers) == 0 {
seelog.Debugf("Not submitting unsupported upstream task state: %s", change.Status.String())
// Not really an error
return nil
}

status := change.Status.String()
status := change.Status.BackendStatus()

req := ecs.SubmitTaskStateChangeInput{
Cluster: aws.String(client.config.Cluster),
Expand Down
40 changes: 39 additions & 1 deletion agent/api/ecsclient/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,6 @@ func TestSubmitTaskStateChangeWithAttachments(t *testing.T) {
assert.NoError(t, err, "Unable to submit task state change with attachments")
}

//
func TestSubmitTaskStateChangeWithoutAttachments(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
Expand All @@ -696,3 +695,42 @@ func TestSubmitTaskStateChangeWithoutAttachments(t *testing.T) {
})
assert.NoError(t, err, "Unable to submit task state change with no attachments")
}

// TestSubmitContainerStateChangeWhileTaskInPending tests the container state chagne was submitted
// when the task is still in pending state
func TestSubmitContainerStateChangeWhileTaskInPending(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

client, _, mockSubmitStateClient := NewMockClient(mockCtrl, ec2.NewBlackholeEC2MetadataClient(), nil)
mockSubmitStateClient.EXPECT().SubmitTaskStateChange(&taskSubmitInputMatcher{
ecs.SubmitTaskStateChangeInput{
Cluster: strptr(configuredCluster),
Task: strptr("arn"),
Status: strptr("PENDING"),
Reason: strptr(""),
Containers: []*ecs.ContainerStateChange{
{
ContainerName: strptr("container"),
Status: strptr("RUNNING"),
NetworkBindings: []*ecs.NetworkBinding{},
},
},
},
})

taskStateChangePending := api.TaskStateChange{
Status: api.TaskCreated,
TaskARN: "arn",
Containers: []api.ContainerStateChange{
{
TaskArn: "arn",
ContainerName: "container",
Status: api.ContainerRunning,
},
},
}

err := client.SubmitTaskStateChange(taskStateChangePending)
assert.NoError(t, err)
}

0 comments on commit 9f536ef

Please sign in to comment.