Skip to content

Commit

Permalink
functional tests for volume metadata in introspection endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
sharanyad committed Aug 21, 2018
1 parent 6315a3c commit f7df7f4
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,21 @@
"awslogs-region":"$$$TEST_REGION$$$",
"awslogs-stream-prefix":"ecs-functional-tests-agent-introspection-validator"
}
}
}]
},
"mountPoints": [
{
"sourceVolume": "task-local",
"containerPath": "/ecs/"
}
]
}],
"volumes":[
{
"name": "task-local",
"dockerVolumeConfiguration" :{
"scope": "task",
"driver": "local"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@
"awslogs-region":"$$$TEST_REGION$$$",
"awslogs-stream-prefix":"ecs-functional-tests-taskmetadata-validator"
}
}
}]
},
"mountPoints": [
{
"sourceVolume": "task-local",
"containerPath": "/ecs/"
}
]
}],
"volumes":[
{
"name": "task-local",
"dockerVolumeConfiguration" :{
"scope": "task",
"driver": "local"
}
}
]
}
4 changes: 2 additions & 2 deletions agent/functional_tests/tests/functionaltests_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ func TestAgentIntrospectionValidator(t *testing.T) {
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")
agent.RequireVersion(">1.20.1")

tdOverrides := make(map[string]string)
tdOverrides["$$$TEST_REGION$$$"] = *ECS.Config.Region
Expand Down Expand Up @@ -663,7 +663,7 @@ func TestTaskMetadataValidator(t *testing.T) {
},
})
defer agent.Cleanup()
agent.RequireVersion(">1.16.2")
agent.RequireVersion(">1.20.1")

tdOverrides := make(map[string]string)
tdOverrides["$$$TEST_REGION$$$"] = *ECS.Config.Region
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ type TasksResponse struct {

// ContainerResponse is the schema for the container response JSON object
type ContainerResponse struct {
DockerID string `json:"DockerId"`
DockerName string `json:"DockerName"`
Name string `json:"Name"`
Ports []PortResponse `json:"Ports,omitempty"`
Networks Network `json:"Networks,omitempty"`
DockerID string `json:"DockerId"`
DockerName string `json:"DockerName"`
Name string `json:"Name"`
Ports []PortResponse `json:"Ports,omitempty"`
Networks Network `json:"Networks,omitempty"`
Volumes []VolumeResponse `json:"Volumes,omitempty"`
}

// PortResponse defines the schema for portmapping response JSON
Expand All @@ -72,6 +73,13 @@ type Network struct {
IPv6Addresses []string `json:"IPv6Addresses,omitempty"`
}

// VolumeResponse is the schema for the volume response JSON object
type VolumeResponse struct {
DockerName string `json:"DockerName,omitempty"`
Source string `json:"Source,omitempty"`
Destination string `json:"Destination,omitempty"`
}

func getTasksMetadata(client *http.Client, path string) (*TasksResponse, error) {
body, err := metadataResponse(client, path, tasksMetadataRespType)
if err != nil {
Expand Down Expand Up @@ -188,7 +196,7 @@ func verifyContainerMetadata(containerMetadataRawMsg json.RawMessage) error {
}

var actualContainerName string
json.Unmarshal(containerMetadataMap["Name"] ,&actualContainerName)
json.Unmarshal(containerMetadataMap["Name"], &actualContainerName)

if actualContainerName != containerName {
return fmt.Errorf("incorrect container name, expected %s, received %s",
Expand All @@ -203,6 +211,10 @@ func verifyContainerMetadata(containerMetadataRawMsg json.RawMessage) error {
return notEmptyErrMsg("DockerName")
}

if containerMetadataMap["Volumes"] == nil {
return notEmptyErrMsg("Volumes")
}

return nil
}

Expand Down
17 changes: 15 additions & 2 deletions misc/taskmetadata-validator/taskmetadata-validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ type ContainerResponse struct {
StartedAt *time.Time `json:",omitempty"`
FinishedAt *time.Time `json:",omitempty"`
Type string
Health HealthStatus `json:"health,omitempty"`
Networks []Network `json:",omitempty"`
Health HealthStatus `json:"health,omitempty"`
Networks []Network `json:",omitempty"`
Volumes []VolumeResponse `json:"Volumes,omitempty"`
}

type HealthStatus struct {
Expand Down Expand Up @@ -94,6 +95,13 @@ type Network struct {
IPv6Addresses []string `json:"IPv6Addresses,omitempty"`
}

// VolumeResponse is the schema for the volume response JSON object
type VolumeResponse struct {
DockerName string `json:"DockerName,omitempty"`
Source string `json:"Source,omitempty"`
Destination string `json:"Destination,omitempty"`
}

func taskMetadata(client *http.Client) (*TaskResponse, error) {
body, err := metadataResponse(client, v2MetadataEndpoint, "task metadata")
if err != nil {
Expand Down Expand Up @@ -243,6 +251,11 @@ func main() {
}
}

if containerMetadata.Volumes == nil {
fmt.Fprintf(os.Stderr, "Expected container volume metadata to be non-empty")
os.Exit(1)
}

_, err = taskStats(client)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to get task stats: %v", err)
Expand Down

0 comments on commit f7df7f4

Please sign in to comment.