Fixed the test related to setting env variables in tasks

This commit is contained in:
Diptanu Choudhury 2015-11-15 01:13:42 -08:00 committed by Alex Dadgar
parent ad4248e087
commit ba9f101660
3 changed files with 16 additions and 2 deletions

View file

@ -133,6 +133,7 @@ func TaskEnvironmentVariables(ctx *ExecContext, task *structs.Task) environment.
if len(task.Resources.Networks) > 0 {
network := task.Resources.Networks[0]
env.SetTaskIp(network.IP)
env.SetPorts(network.MapLabelToValues())
}
}

View file

@ -76,8 +76,12 @@ func TestDriver_TaskEnvironmentVariables(t *testing.T) {
"NOMAD_CPU_LIMIT": "1000",
"NOMAD_MEMORY_LIMIT": "500",
"NOMAD_IP": "1.2.3.4",
"NOMAD_PORT_admin": "8080",
"NOMAD_PORT_5000": "12345",
"NOMAD_PORT_one": "80",
"NOMAD_PORT_two": "443",
"NOMAD_PORT_three": "8080",
"NOMAD_PORT_four": "12345",
"NOMAD_PORT_admin": "8081",
"NOMAD_PORT_web": "8086",
"NOMAD_META_CHOCOLATE": "cake",
"NOMAD_META_STRAWBERRY": "icecream",
"HELLO": "world",

View file

@ -661,6 +661,15 @@ func (n *NetworkResource) GoString() string {
return fmt.Sprintf("*%#v", *n)
}
func (n *NetworkResource) MapLabelToValues() map[string]int {
labelValues := make(map[string]int)
ports := append(n.ReservedPorts, n.DynamicPorts...)
for _, port := range ports {
labelValues[port.Label] = port.Value
}
return labelValues
}
const (
// JobTypeNomad is reserved for internal system tasks and is
// always handled by the CoreScheduler.