Skip to content

Commit a15382f

Browse files
committed
test: add functional test for agent introspection endpoint
1 parent dfbe8cc commit a15382f

File tree

9 files changed

+419
-4
lines changed

9 files changed

+419
-4
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ _bin/
1717
/misc/pause-container/pause
1818
*-stamp
1919
/.idea/
20+
/misc/agent-introspection-validator/agent-introspection-validator
2021
/misc/taskmetadata-validator/taskmetadata-validator
2122
/bin

Makefile

+6-2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ test-artifacts-linux: $(LINUX_ARTIFACTS_TARGETS)
172172
test-artifacts: test-artifacts-windows test-artifacts-linux
173173

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

178178
test-in-docker:
@@ -242,7 +242,7 @@ volumes-test:
242242

243243
# TODO, replace this with a build on dockerhub or a mechanism for the
244244
# functional tests themselves to build this
245-
.PHONY: squid awscli fluentd gremlin taskmetadata-validator image-cleanup-test-images ecr-execution-role-image container-health-check-image telemetry-test-image
245+
.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
246246
squid:
247247
$(MAKE) -C misc/squid $(MFLAGS)
248248

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

264+
agent-introspection-validator:
265+
$(MAKE) -C misc/agent-introspection-validator $(MFLAGS)
266+
264267
taskmetadata-validator:
265268
$(MAKE) -C misc/taskmetadata-validator $(MFLAGS)
266269

@@ -321,6 +324,7 @@ clean:
321324
-$(MAKE) -C misc/gremlin $(MFLAGS) clean
322325
-$(MAKE) -C misc/testnnp $(MFLAGS) clean
323326
-$(MAKE) -C misc/image-cleanup-test-images $(MFLAGS) clean
327+
-$(MAKE) -C misc/agent-introspection-validator $(MFLAGS) clean
324328
-$(MAKE) -C misc/taskmetadata-validator $(MFLAGS) clean
325329
-$(MAKE) -C misc/container-health $(MFLAGS) clean
326330
-$(MAKE) -C misc/telemetry $(MFLAGS) clean
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"family": "ecsftest-agent-introspection-validator",
3+
"networkMode": "host",
4+
"containerDefinitions": [{
5+
"image": "amazon/amazon-ecs-agent-introspection-validator:make",
6+
"name": "agent-introspection-validator",
7+
"memory": 50,
8+
"logConfiguration": {
9+
"logDriver": "awslogs",
10+
"options": {
11+
"awslogs-group":"ecs-functional-tests",
12+
"awslogs-region":"$$$TEST_REGION$$$",
13+
"awslogs-stream-prefix":"ecs-functional-tests-agent-introspection-validator"
14+
}
15+
}
16+
}]
17+
}

agent/functional_tests/tests/functionaltests_unix_test.go

+40-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ func fluentdDriverTest(taskDefinition string, t *testing.T) {
584584
assert.NoError(t, err, "failed to find the log tag specified in the task definition")
585585
}
586586

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

612+
// TestAgentIntrospectionValidator tests that the agent introspection endpoint can
613+
// be accessed from within the container.
614+
func TestAgentIntrospectionValidator(t *testing.T) {
615+
// Best effort to create a log group. It should be safe to even not do this
616+
// as the log group gets created in the TestAWSLogsDriver functional test.
617+
cwlClient := cloudwatchlogs.New(session.New(), aws.NewConfig().WithRegion(*ECS.Config.Region))
618+
cwlClient.CreateLogGroup(&cloudwatchlogs.CreateLogGroupInput{
619+
LogGroupName: aws.String(awslogsLogGroupName),
620+
})
621+
agent := RunAgent(t, &AgentOptions{
622+
EnableTaskENI: true,
623+
ExtraEnvironment: map[string]string{
624+
"ECS_AVAILABLE_LOGGING_DRIVERS": `["awslogs"]`,
625+
},
626+
})
627+
defer agent.Cleanup()
628+
// The Agent version was 1.14.2 when we added changes to agent introspection
629+
// endpoint feature for the last time.
630+
agent.RequireVersion(">1.14.1")
631+
632+
tdOverrides := make(map[string]string)
633+
tdOverrides["$$$TEST_REGION$$$"] = *ECS.Config.Region
634+
635+
task, err := agent.StartTaskWithTaskDefinitionOverrides(t, "agent-introspection-validator", tdOverrides)
636+
require.NoError(t, err, "Unable to start task")
637+
defer func() {
638+
if err := task.Stop(); err != nil {
639+
return
640+
}
641+
task.WaitStopped(waitTaskStateChangeDuration)
642+
}()
643+
644+
err = task.WaitStopped(waitTaskStateChangeDuration)
645+
require.NoError(t, err, "Error waiting for task to transition to STOPPED")
646+
exitCode, _ := task.ContainerExitcode("agent-introspection-validator")
647+
648+
assert.Equal(t, 42, exitCode, fmt.Sprintf("Expected exit code of 42; got %d", exitCode))
649+
}
650+
612651
func TestTaskMetadataValidator(t *testing.T) {
613652
RequireDockerVersion(t, ">=17.06.0-ce")
614653
// Best effort to create a log group. It should be safe to even not do this
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
# not use this file except in compliance with the License. A copy of the
5+
# License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is distributed
10+
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
# express or implied. See the License for the specific language governing
12+
# permissions and limitations under the License.
13+
FROM busybox@sha256:5551dbdfc48d66734d0f01cafee0952cb6e8eeecd1e2492240bf2fd9640c2279
14+
15+
MAINTAINER Amazon Web Services, Inc.
16+
COPY agent-introspection-validator /
17+
18+
ENTRYPOINT ["/agent-introspection-validator"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
# not use this file except in compliance with the License. A copy of the
5+
# License is located at
6+
#
7+
# http://aws.amazon.com/apache2.0/
8+
#
9+
# or in the "license" file accompanying this file. This file is distributed
10+
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
# express or implied. See the License for the specific language governing
12+
# permissions and limitations under the License.
13+
.PHONY: all clean agent-introspection-validator image
14+
15+
all: agent-introspection-validator image
16+
17+
agent-introspection-validator: agent-introspection-validator.go
18+
@./build-in-docker
19+
20+
image: agent-introspection-validator
21+
docker build -t amazon/amazon-ecs-agent-introspection-validator:make .
22+
23+
clean:
24+
rm -f agent-introspection-validator
25+
-docker rmi -f "amazon/amazon-ecs-agent-introspection-validator:make"

0 commit comments

Comments
 (0)