Skip to content

Commit 02411bf

Browse files
committed
Add devices to parseV1V2 and parseV3, tests
1 parent a0942f2 commit 02411bf

5 files changed

Lines changed: 72 additions & 1 deletion

File tree

ecs-cli/modules/cli/compose/logger/logger.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var supportedComposeV1V2YamlOptions = []string{
3131
"cap_drop",
3232
"command",
3333
"cpu_shares",
34+
"devices",
3435
"dns",
3536
"dns_search",
3637
"entrypoint",
@@ -64,6 +65,7 @@ var supportedFieldsInV3 = map[string]bool{
6465
"CapAdd": true,
6566
"CapDrop": true,
6667
"Command": true,
68+
"Devices": true,
6769
"DNS": true,
6870
"DNSSearch": true,
6971
"Entrypoint": true,

ecs-cli/modules/cli/compose/project/project_parseV1V2.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ func (p *ecsProject) parseV1V2() (*[]adapter.ContainerConfig, error) {
5555
func convertV1V2ToContainerConfig(context *project.Context, serviceName string, volumes *adapter.Volumes, service *config.ServiceConfig) (*adapter.ContainerConfig, error) {
5656
logger.LogUnsupportedV1V2ServiceConfigFields(serviceName, service)
5757

58+
devices, err := adapter.ConvertToDevices(service.Devices)
59+
if err != nil {
60+
return nil, err
61+
}
62+
5863
environment := adapter.ConvertToKeyValuePairs(context, service.Environment, serviceName)
5964

6065
extraHosts, err := adapter.ConvertToExtraHosts(service.ExtraHosts)
@@ -103,6 +108,7 @@ func convertV1V2ToContainerConfig(context *project.Context, serviceName string,
103108
CapDrop: service.CapDrop,
104109
Command: service.Command,
105110
CPU: int64(service.CPUShares),
111+
Devices: devices,
106112
DNSSearchDomains: service.DNSSearch,
107113
DNSServers: service.DNS,
108114
DockerLabels: aws.StringMap(service.Labels),

ecs-cli/modules/cli/compose/project/project_parseV1V2_test.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ func TestParseV1V2_Version1_HappyPath(t *testing.T) {
1919
webImage := "web"
2020
cpuShares := int64(73)
2121
command := []string{"bundle exec thin -p 3000"}
22+
devices := []*ecs.Device{
23+
{
24+
HostPath: aws.String("/dev/sda"),
25+
ContainerPath: aws.String("/dev/sdd"),
26+
Permissions: aws.StringSlice([]string{"read"}),
27+
},
28+
{
29+
HostPath: aws.String("/dev/sdd"),
30+
ContainerPath: aws.String("/dev/xdr"),
31+
},
32+
{
33+
HostPath: aws.String("/dev/sda"),
34+
},
35+
}
2236
dnsServers := []string{"1.2.3.4"}
2337
dnsSearchDomains := []string{"search.example.com"}
2438
entryPoint := []string{"/code/entrypoint.sh"}
@@ -98,6 +112,10 @@ func TestParseV1V2_Version1_HappyPath(t *testing.T) {
98112
cpu_shares: 73
99113
command:
100114
- bundle exec thin -p 3000
115+
devices:
116+
- "/dev/sda:/dev/sdd:r"
117+
- "/dev/sdd:/dev/xdr"
118+
- "/dev/sda"
101119
dns:
102120
- 1.2.3.4
103121
dns_search: search.example.com
@@ -173,6 +191,7 @@ redis:
173191

174192
assert.Equal(t, command, web.Command, "Expected Command to match")
175193
assert.Equal(t, cpuShares, web.CPU, "Expected CPU to match")
194+
assert.ElementsMatch(t, devices, web.Devices, "Expected Devices to match")
176195
assert.Equal(t, dnsSearchDomains, web.DNSSearchDomains, "Expected DNSSearchDomains to match")
177196
assert.Equal(t, dnsServers, web.DNSServers, "Expected DNSServers to match")
178197
assert.Equal(t, labels, web.DockerLabels, "Expected DockerLabels to match")
@@ -202,6 +221,20 @@ func TestParseV1V2_Version2Files(t *testing.T) {
202221

203222
capAdd := []string{"ALL"}
204223
capDrop := []string{"NET_ADMIN", "SYS_ADMIN"}
224+
devices := []*ecs.Device{
225+
{
226+
HostPath: aws.String("/dev/sda"),
227+
ContainerPath: aws.String("/dev/sdd"),
228+
Permissions: aws.StringSlice([]string{"read"}),
229+
},
230+
{
231+
HostPath: aws.String("/dev/sdd"),
232+
ContainerPath: aws.String("/dev/xdr"),
233+
},
234+
{
235+
HostPath: aws.String("/dev/sda"),
236+
},
237+
}
205238
logOpts := map[string]*string{
206239
"syslog-address": aws.String("tcp://192.168.0.42:123"),
207240
}
@@ -272,6 +305,10 @@ services:
272305
cap_drop:
273306
- NET_ADMIN
274307
- SYS_ADMIN
308+
devices:
309+
- "/dev/sda:/dev/sdd:r"
310+
- "/dev/sdd:/dev/xdr"
311+
- "/dev/sda"
275312
image: wordpress
276313
ports: ["80:80"]
277314
mem_reservation: 500000000
@@ -324,6 +361,7 @@ volumes:
324361
assert.Equal(t, wordpressImage, wordpress.Image, "Expected wordpress Image to match")
325362
assert.Equal(t, capAdd, wordpress.CapAdd, "Expected CapAdd to match")
326363
assert.Equal(t, capDrop, wordpress.CapDrop, "Expected CapDrop to match")
364+
assert.ElementsMatch(t, devices, wordpress.Devices, "Expected Devices to match")
327365
assert.Equal(t, logging, wordpress.LogConfiguration, "Expected Log Configuration to match")
328366

329367
assert.Equal(t, memoryReservation, wordpress.MemoryReservation, "Expected memoryReservation to match")
@@ -473,5 +511,5 @@ func getContainerConfigByName(name string, configs *[]adapter.ContainerConfig) (
473511
return &config, nil
474512
}
475513
}
476-
return nil, fmt.Errorf("Container with name %v could not be found.", name)
514+
return nil, fmt.Errorf("Container with name %v could not be found", name)
477515
}

ecs-cli/modules/cli/compose/project/project_parseV3.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ func convertToContainerConfig(serviceConfig types.ServiceConfig, serviceVols *ad
105105
WorkingDirectory: serviceConfig.WorkingDir,
106106
}
107107

108+
devices, err := adapter.ConvertToDevices(serviceConfig.Devices)
109+
if err != nil {
110+
return nil, err
111+
}
112+
c.Devices = devices
113+
108114
if serviceConfig.DNS != nil {
109115
c.DNSServers = serviceConfig.DNS
110116
}

ecs-cli/modules/cli/compose/project/project_parseV3_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ func TestParseV3WithOneFile(t *testing.T) {
2929
Protocol: aws.String("tcp"),
3030
},
3131
}
32+
wordpressCon.Devices = []*ecs.Device{
33+
{
34+
HostPath: aws.String("/dev/sda"),
35+
ContainerPath: aws.String("/dev/sdd"),
36+
Permissions: aws.StringSlice([]string{"read"}),
37+
},
38+
{
39+
HostPath: aws.String("/dev/sdd"),
40+
ContainerPath: aws.String("/dev/xdr"),
41+
},
42+
{
43+
HostPath: aws.String("/dev/sda"),
44+
},
45+
}
3246
wordpressCon.DNSServers = []string{"2.2.2.2"}
3347
wordpressCon.DNSSearchDomains = []string{"wrd.search.com", "wrd.search2.com"}
3448
wordpressCon.Environment = []*ecs.KeyValuePair{
@@ -110,6 +124,10 @@ services:
110124
image: wordpress
111125
entrypoint: /wordpress/entry
112126
ports: ["80:80"]
127+
devices:
128+
- "/dev/sda:/dev/sdd:r"
129+
- "/dev/sdd:/dev/xdr"
130+
- "/dev/sda"
113131
dns:
114132
- 2.2.2.2
115133
dns_search:
@@ -521,6 +539,7 @@ func verifyContainerConfig(t *testing.T, expected, actual adapter.ContainerConfi
521539
assert.ElementsMatch(t, expected.CapAdd, actual.CapAdd, "Expected CapAdd to match")
522540
assert.ElementsMatch(t, expected.CapDrop, actual.CapDrop, "Expected CapDrop to match")
523541
assert.ElementsMatch(t, expected.Command, actual.Command, "Expected Command to match")
542+
assert.ElementsMatch(t, expected.Devices, actual.Devices, "Expected Devices to match")
524543
assert.ElementsMatch(t, expected.DNSSearchDomains, actual.DNSSearchDomains, "Expected DNSSearchDomains to match")
525544
assert.ElementsMatch(t, expected.DNSServers, actual.DNSServers, "Expected DNSServers to match")
526545
dockerLabelsEqual := reflect.DeepEqual(expected.DockerLabels, actual.DockerLabels)

0 commit comments

Comments
 (0)