Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add functional test for agent introspection endpoint #1485

Merged
merged 1 commit into from
Aug 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ _bin/
/misc/pause-container/pause
*-stamp
/.idea/
/misc/agent-introspection-validator/agent-introspection-validator
/misc/taskmetadata-validator/taskmetadata-validator
/bin
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ test-artifacts-linux: $(LINUX_ARTIFACTS_TARGETS)
test-artifacts: test-artifacts-windows test-artifacts-linux

# Run our 'test' registry needed for integ and functional tests
test-registry: netkitten volumes-test squid awscli image-cleanup-test-images fluentd taskmetadata-validator
test-registry: netkitten volumes-test squid awscli image-cleanup-test-images fluentd agent-introspection-validator taskmetadata-validator
@./scripts/setup-test-registry

test-in-docker:
Expand Down Expand Up @@ -242,7 +242,7 @@ volumes-test:

# TODO, replace this with a build on dockerhub or a mechanism for the
# functional tests themselves to build this
.PHONY: squid awscli fluentd gremlin taskmetadata-validator image-cleanup-test-images ecr-execution-role-image container-health-check-image telemetry-test-image
.PHONY: squid awscli fluentd gremlin agent-introspection-validator taskmetadata-validator image-cleanup-test-images ecr-execution-role-image container-health-check-image telemetry-test-image
squid:
$(MAKE) -C misc/squid $(MFLAGS)

Expand All @@ -261,6 +261,9 @@ testnnp:
image-cleanup-test-images:
$(MAKE) -C misc/image-cleanup-test-images $(MFLAGS)

agent-introspection-validator:
$(MAKE) -C misc/agent-introspection-validator $(MFLAGS)

taskmetadata-validator:
$(MAKE) -C misc/taskmetadata-validator $(MFLAGS)

Expand Down Expand Up @@ -321,6 +324,7 @@ clean:
-$(MAKE) -C misc/gremlin $(MFLAGS) clean
-$(MAKE) -C misc/testnnp $(MFLAGS) clean
-$(MAKE) -C misc/image-cleanup-test-images $(MFLAGS) clean
-$(MAKE) -C misc/agent-introspection-validator $(MFLAGS) clean
-$(MAKE) -C misc/taskmetadata-validator $(MFLAGS) clean
-$(MAKE) -C misc/container-health $(MFLAGS) clean
-$(MAKE) -C misc/telemetry $(MFLAGS) clean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"family": "ecsftest-agent-introspection-validator",
"networkMode": "host",
"containerDefinitions": [{
"image": "amazon/amazon-ecs-agent-introspection-validator:make",
"name": "agent-introspection-validator",
"memory": 50,
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group":"ecs-functional-tests",
"awslogs-region":"$$$TEST_REGION$$$",
"awslogs-stream-prefix":"ecs-functional-tests-agent-introspection-validator"
}
}
}]
}
41 changes: 40 additions & 1 deletion agent/functional_tests/tests/functionaltests_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ func fluentdDriverTest(taskDefinition string, t *testing.T) {
assert.NoError(t, err, "failed to find the log tag specified in the task definition")
}

// TestMetadataServiceValidator Tests that the metadata file can be accessed from the
// TestMetadataServiceValidator tests that the metadata file can be accessed from the
// container using the ECS_CONTAINER_METADATA_FILE environment variables
func TestMetadataServiceValidator(t *testing.T) {
agentOptions := &AgentOptions{
Expand All @@ -609,6 +609,45 @@ func TestMetadataServiceValidator(t *testing.T) {
assert.Equal(t, 42, exitCode, fmt.Sprintf("Expected exit code of 42; got %d", exitCode))
}

// TestAgentIntrospectionValidator tests that the agent introspection endpoint can
// be accessed from within the container.
func TestAgentIntrospectionValidator(t *testing.T) {
// Best effort to create a log group. It should be safe to even not do this
// as the log group gets created in the TestAWSLogsDriver functional test.
cwlClient := cloudwatchlogs.New(session.New(), aws.NewConfig().WithRegion(*ECS.Config.Region))
cwlClient.CreateLogGroup(&cloudwatchlogs.CreateLogGroupInput{
LogGroupName: aws.String(awslogsLogGroupName),
})
agent := RunAgent(t, &AgentOptions{
EnableTaskENI: true,
ExtraEnvironment: map[string]string{
"ECS_AVAILABLE_LOGGING_DRIVERS": `["awslogs"]`,
},
})
defer agent.Cleanup()
// The Agent version was 1.14.2 when we added changes to agent introspection
// endpoint feature for the last time.
agent.RequireVersion(">1.14.1")

tdOverrides := make(map[string]string)
tdOverrides["$$$TEST_REGION$$$"] = *ECS.Config.Region

task, err := agent.StartTaskWithTaskDefinitionOverrides(t, "agent-introspection-validator", tdOverrides)
require.NoError(t, err, "Unable to start task")
defer func() {
if err := task.Stop(); err != nil {
return
}
task.WaitStopped(waitTaskStateChangeDuration)
}()

err = task.WaitStopped(waitTaskStateChangeDuration)
require.NoError(t, err, "Error waiting for task to transition to STOPPED")
exitCode, _ := task.ContainerExitcode("agent-introspection-validator")

assert.Equal(t, 42, exitCode, fmt.Sprintf("Expected exit code of 42; got %d", exitCode))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: you can just use assert.Equalf to get rid of the fmt.Sprintf.

}

func TestTaskMetadataValidator(t *testing.T) {
RequireDockerVersion(t, ">=17.06.0-ce")
// Best effort to create a log group. It should be safe to even not do this
Expand Down
18 changes: 18 additions & 0 deletions misc/agent-introspection-validator/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2018 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.
FROM busybox@sha256:5551dbdfc48d66734d0f01cafee0952cb6e8eeecd1e2492240bf2fd9640c2279

MAINTAINER Amazon Web Services, Inc.
COPY agent-introspection-validator /

ENTRYPOINT ["/agent-introspection-validator"]
25 changes: 25 additions & 0 deletions misc/agent-introspection-validator/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2018 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.
.PHONY: all clean agent-introspection-validator image

all: agent-introspection-validator image

agent-introspection-validator: agent-introspection-validator.go
@./build-in-docker

image: agent-introspection-validator
docker build -t amazon/amazon-ecs-agent-introspection-validator:make .

clean:
rm -f agent-introspection-validator
-docker rmi -f "amazon/amazon-ecs-agent-introspection-validator:make"
Loading