forked from aws/amazon-ecs-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Awsvpc windows : Check if the pause image is loaded on the container …
…instance (aws#2498) * Changes to check if the pause image has been loaded on agent startup. We will cache pause image on ECS-Optimized Windows AMI. On agent startup, we check if the pause image is already loaded. The following changes are made as part of this commit: 1. Moved common functions from pause_linux.go to load.go 2. Moved the common code from IsLoaded function to a function in load.go 3. Unit tests for the same were moved from Linux specific files to common files
- Loading branch information
Showing
11 changed files
with
260 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
// +build 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 pause | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
|
||
"github.com/aws/amazon-ecs-agent/agent/config" | ||
"github.com/aws/amazon-ecs-agent/agent/dockerclient/dockerapi" | ||
mock_sdkclient "github.com/aws/amazon-ecs-agent/agent/dockerclient/sdkclient/mocks" | ||
mock_sdkclientfactory "github.com/aws/amazon-ecs-agent/agent/dockerclient/sdkclientfactory/mocks" | ||
|
||
"github.com/docker/docker/api/types" | ||
"github.com/golang/mock/gomock" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
const ( | ||
pauseName = "pause" | ||
pauseTag = "tag" | ||
) | ||
|
||
var defaultConfig = config.DefaultConfig() | ||
|
||
func TestGetPauseContainerImageInspectImageError(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
// Docker SDK tests | ||
mockDockerSDK := mock_sdkclient.NewMockClient(ctrl) | ||
mockDockerSDK.EXPECT().Ping(gomock.Any()).Return(types.Ping{}, nil) | ||
sdkFactory := mock_sdkclientfactory.NewMockFactory(ctrl) | ||
sdkFactory.EXPECT().GetDefaultClient().AnyTimes().Return(mockDockerSDK, nil) | ||
|
||
ctx, cancel := context.WithCancel(context.TODO()) | ||
defer cancel() | ||
|
||
client, err := dockerapi.NewDockerGoClient(sdkFactory, &defaultConfig, ctx) | ||
assert.NoError(t, err) | ||
mockDockerSDK.EXPECT().ImageInspectWithRaw(gomock.Any(), pauseName+":"+pauseTag).Return( | ||
types.ImageInspect{}, nil, errors.New("error")) | ||
|
||
_, err = getPauseContainerImage(pauseName, pauseTag, client) | ||
assert.Error(t, err) | ||
} | ||
|
||
func TestGetPauseContainerHappyPath(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
// Docker SDK tests | ||
mockDockerSDK := mock_sdkclient.NewMockClient(ctrl) | ||
mockDockerSDK.EXPECT().Ping(gomock.Any()).Return(types.Ping{}, nil) | ||
sdkFactory := mock_sdkclientfactory.NewMockFactory(ctrl) | ||
sdkFactory.EXPECT().GetDefaultClient().AnyTimes().Return(mockDockerSDK, nil) | ||
|
||
ctx, cancel := context.WithCancel(context.TODO()) | ||
defer cancel() | ||
|
||
client, err := dockerapi.NewDockerGoClient(sdkFactory, &defaultConfig, ctx) | ||
assert.NoError(t, err) | ||
mockDockerSDK.EXPECT().ImageInspectWithRaw(gomock.Any(), pauseName+":"+pauseTag).Return(types.ImageInspect{}, nil, nil) | ||
|
||
_, err = getPauseContainerImage(pauseName, pauseTag, client) | ||
assert.NoError(t, err) | ||
} | ||
|
||
func TestIsImageLoadedHappyPath(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
// Docker SDK tests | ||
mockDockerSDK := mock_sdkclient.NewMockClient(ctrl) | ||
mockDockerSDK.EXPECT().Ping(gomock.Any()).Return(types.Ping{}, nil) | ||
sdkFactory := mock_sdkclientfactory.NewMockFactory(ctrl) | ||
sdkFactory.EXPECT().GetDefaultClient().AnyTimes().Return(mockDockerSDK, nil) | ||
|
||
ctx, cancel := context.WithCancel(context.TODO()) | ||
defer cancel() | ||
|
||
client, err := dockerapi.NewDockerGoClient(sdkFactory, &defaultConfig, ctx) | ||
assert.NoError(t, err) | ||
mockDockerSDK.EXPECT().ImageInspectWithRaw(gomock.Any(), gomock.Any()).Return(types.ImageInspect{ID: "test123"}, nil, nil) | ||
|
||
isLoaded, err := isImageLoaded(client) | ||
assert.NoError(t, err) | ||
assert.True(t, isLoaded) | ||
} | ||
|
||
func TestIsImageLoadedNotLoaded(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
// Docker SDK tests | ||
mockDockerSDK := mock_sdkclient.NewMockClient(ctrl) | ||
mockDockerSDK.EXPECT().Ping(gomock.Any()).Return(types.Ping{}, nil) | ||
sdkFactory := mock_sdkclientfactory.NewMockFactory(ctrl) | ||
sdkFactory.EXPECT().GetDefaultClient().AnyTimes().Return(mockDockerSDK, nil) | ||
|
||
ctx, cancel := context.WithCancel(context.TODO()) | ||
defer cancel() | ||
|
||
client, err := dockerapi.NewDockerGoClient(sdkFactory, &defaultConfig, ctx) | ||
assert.NoError(t, err) | ||
mockDockerSDK.EXPECT().ImageInspectWithRaw(gomock.Any(), gomock.Any()).Return(types.ImageInspect{}, nil, nil) | ||
|
||
isLoaded, err := isImageLoaded(client) | ||
assert.NoError(t, err) | ||
assert.False(t, isLoaded) | ||
} | ||
|
||
func TestIsImageLoadedError(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
// Docker SDK tests | ||
mockDockerSDK := mock_sdkclient.NewMockClient(ctrl) | ||
mockDockerSDK.EXPECT().Ping(gomock.Any()).Return(types.Ping{}, nil) | ||
sdkFactory := mock_sdkclientfactory.NewMockFactory(ctrl) | ||
sdkFactory.EXPECT().GetDefaultClient().AnyTimes().Return(mockDockerSDK, nil) | ||
|
||
ctx, cancel := context.WithCancel(context.TODO()) | ||
defer cancel() | ||
|
||
client, err := dockerapi.NewDockerGoClient(sdkFactory, &defaultConfig, ctx) | ||
assert.NoError(t, err) | ||
mockDockerSDK.EXPECT().ImageInspectWithRaw(gomock.Any(), gomock.Any()).Return( | ||
types.ImageInspect{}, nil, errors.New("error")) | ||
|
||
isLoaded, err := isImageLoaded(client) | ||
assert.Error(t, err) | ||
assert.False(t, isLoaded) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.