Example #1
0
func newInterfaceAllocation(t *testing.T, input engine.Env) (output engine.Env) {
	eng := engine.New()
	eng.Logging = false

	done := make(chan bool)

	// set IPv6 global if given
	if input.Exists("globalIPv6Network") {
		_, globalIPv6Network, _ = net.ParseCIDR(input.Get("globalIPv6Network"))
	}

	job := eng.Job("allocate_interface", "container_id")
	job.Env().Init(&input)
	reader, _ := job.Stdout.AddPipe()
	go func() {
		output.Decode(reader)
		done <- true
	}()

	res := Allocate(job)
	job.Stdout.Close()
	<-done

	if input.Exists("expectFail") && input.GetBool("expectFail") {
		if res == engine.StatusOK {
			t.Fatal("Doesn't fail to allocate network interface")
		}
	} else {
		if res != engine.StatusOK {
			t.Fatal("Failed to allocate network interface")
		}
	}

	if input.Exists("globalIPv6Network") {
		// check for bug #11427
		_, subnet, _ := net.ParseCIDR(input.Get("globalIPv6Network"))
		if globalIPv6Network.IP.String() != subnet.IP.String() {
			t.Fatal("globalIPv6Network was modified during allocation")
		}
		// clean up IPv6 global
		globalIPv6Network = nil
	}

	return
}