Skip to content

Commit

Permalink
dockerapi, engine: use assert and add inspect* error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
adnxn committed Dec 27, 2018
1 parent e9f23ab commit ad95b99
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
23 changes: 7 additions & 16 deletions agent/dockerclient/dockerapi/docker_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,18 +821,11 @@ func TestListImages(t *testing.T) {
ctx, cancel := context.WithCancel(context.TODO())
defer cancel()
response := client.ListImages(ctx, dockerclient.ListImagesTimeout)
if response.Error != nil {
t.Error("Did not expect error")
}
assert.NoError(t, response.Error, "Did not expect error")

imageIDs := response.ImageIDs
if len(imageIDs) != 1 {
t.Error("Unexpected number of images in list", len(imageIDs))
}

if imageIDs[0] != "id" {
t.Error("Unexpected image id in the list:", imageIDs[0])
}
assert.EqualValues(t, len(imageIDs), 1, "Unexpected number of images in list")
assert.EqualValues(t, imageIDs[0], "id", "Unexpected id in list of images")
}

func TestListImagesTimeout(t *testing.T) {
Expand All @@ -847,13 +840,11 @@ func TestListImagesTimeout(t *testing.T) {
}).MaxTimes(1).Return(nil, errors.New("test error"))
ctx, cancel := context.WithCancel(context.TODO())
defer cancel()

response := client.ListImages(ctx, xImageShortTimeout)
if response.Error == nil {
t.Error("Expected error for pull timeout")
}
if response.Error.(apierrors.NamedError).ErrorName() != "DockerTimeoutError" {
t.Error("Wrong error type")
}
assert.Error(t, response.Error, "Expected error for pull timeout")
assert.Equal(t, response.Error.(apierrors.NamedError).ErrorName(), "DockerTimeoutError", "Wrong error type")

wait.Done()
}

Expand Down
18 changes: 13 additions & 5 deletions agent/engine/docker_image_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,11 @@ func (imageManager *dockerImageManager) removeNonECSContainers(ctx context.Conte
}
var nonECSContainerRemoveAvailableIDs []string
for _, id := range nonECSContainersIDs {
response, _ := imageManager.client.InspectContainer(ctx, id, dockerclient.InspectContainerTimeout)
response, icErr := imageManager.client.InspectContainer(ctx, id, dockerclient.InspectContainerTimeout)
if icErr != nil {
seelog.Errorf("Error inspecting non-ECS container id: %s - %v", id, icErr)
continue
}

finishedTime, _ := time.Parse(time.Now().String(), response.State.FinishedAt)

Expand Down Expand Up @@ -393,7 +397,11 @@ func (imageManager *dockerImageManager) removeNonECSImages(ctx context.Context,

var imageWithSizeList []ImageWithSize
for _, imageName := range nonECSImageNamesRemoveEligible {
resp, _ := imageManager.client.InspectImage(imageName)
resp, iiErr := imageManager.client.InspectImage(imageName)
if iiErr != nil {
seelog.Errorf("Error inspecting non-ECS image name: %s - %v", imageName, iiErr)
continue
}
imageWithSizeList = append(imageWithSizeList, ImageWithSize{imageName, resp.Size})
}
// we want to sort images with size ascending
Expand All @@ -402,9 +410,9 @@ func (imageManager *dockerImageManager) removeNonECSImages(ctx context.Context,
})

// we will remove the remaining nonECSImages in each performPeriodicImageCleanup call()
var numImagesAlreadyDelete = 0
var numImagesAlreadyDeleted = 0
for _, kv := range imageWithSizeList {
if numImagesAlreadyDelete == nonECSImagesNumToDelete {
if numImagesAlreadyDeleted == nonECSImagesNumToDelete {
break
}
seelog.Infof("Removing non-ECS Image: %s", kv.ImageName)
Expand All @@ -414,7 +422,7 @@ func (imageManager *dockerImageManager) removeNonECSImages(ctx context.Context,
continue
} else {
seelog.Infof("Image removed: %s", kv.ImageName)
numImagesAlreadyDelete++
numImagesAlreadyDeleted++
}
}
}
Expand Down

0 comments on commit ad95b99

Please sign in to comment.