Example #1
0
File: mock.go Project: gpxl/deis
// RunMockDatabase starts a mock postgresql database for testing.
func RunMockDatabase(t *testing.T, tag string, etcdPort string, dbPort string) {
	var err error
	cli, stdout, stdoutPipe := dockercli.NewClient()
	done := make(chan bool, 1)
	dbImage := "deis/test-postgresql:latest"
	ipaddr := utils.HostAddress()
	done <- true
	go func() {
		<-done
		err = dockercli.RunContainer(cli,
			"--name", "deis-test-database-"+tag,
			"--rm",
			"-p", dbPort+":5432",
			"-e", "POSTGRES_USER=deis",
			"-e", "POSTGRES_DB=deis",
			"-e", "POSTGRES_PASSWORD=deis",
			dbImage)
	}()
	time.Sleep(1000 * time.Millisecond)
	dockercli.PrintToStdout(t, stdout, stdoutPipe, "Initialization complete.")
	setkeys := []string{
		"/deis/database/user",
		"/deis/database/password",
		"/deis/database/name",
	}
	setdir := []string{}
	dbhandler := etcdutils.InitEtcd(setdir, setkeys, etcdPort)
	etcdutils.PublishEtcd(t, dbhandler)
	etcdutils.SetEtcd(t,
		[]string{"/deis/database/host", "/deis/database/port", "/deis/database/engine"},
		[]string{ipaddr, dbPort, "postgresql_psycopg2"}, dbhandler.C)
	if err != nil {
		t.Fatal(err)
	}
}
Example #2
0
func TestRouter(t *testing.T) {
	var err error
	setkeys := []string{
		"/deis/controller/host",
		"/deis/controller/port",
		"/deis/builder/host",
		"/deis/builder/port",
		"/deis/store/gateway/host",
		"/deis/store/gateway/port",
	}
	setdir := []string{
		"/deis/controller",
		"/deis/router",
		"/deis/database",
		"/deis/services",
		"/deis/builder",
		"/deis/domains",
		"/deis/store",
	}
	tag, etcdPort := utils.BuildTag(), utils.RandomPort()
	imageName := utils.ImagePrefix() + "router" + ":" + tag
	etcdName := "deis-etcd-" + tag
	cli, stdout, stdoutPipe := dockercli.NewClient()
	dockercli.RunTestEtcd(t, etcdName, etcdPort)
	defer cli.CmdRm("-f", etcdName)
	handler := etcdutils.InitEtcd(setdir, setkeys, etcdPort)
	etcdutils.PublishEtcd(t, handler)
	host, port := utils.HostAddress(), utils.RandomPort()
	fmt.Printf("--- Run %s at %s:%s\n", imageName, host, port)
	name := "deis-router-" + tag
	go func() {
		_ = cli.CmdRm("-f", name)
		err = dockercli.RunContainer(cli,
			"--name", name,
			"--rm",
			"-p", port+":80",
			"-p", utils.RandomPort()+":2222",
			"-e", "EXTERNAL_PORT="+port,
			"-e", "HOST="+host,
			"-e", "ETCD_PORT="+etcdPort,
			"-e", "LOG=debug",
			imageName)
	}()
	dockercli.PrintToStdout(t, stdout, stdoutPipe, "deis-router running")
	if err != nil {
		t.Fatal(err)
	}
	// FIXME: nginx needs a couple seconds to wake up here
	// FIXME: Wait until etcd keys are published
	time.Sleep(5000 * time.Millisecond)
	dockercli.DeisServiceTest(t, name, port, "http")
	etcdutils.VerifyEtcdValue(t, "/deis/router/gzip", "on", etcdPort)
	etcdutils.VerifyEtcdValue(t,
		"/deis/router/hosts/"+host,
		fmt.Sprintf("%s:%s", host, port),
		etcdPort)
	_ = cli.CmdRm("-f", name)
}
Example #3
0
func TestBuilder(t *testing.T) {
	var err error
	setkeys := []string{
		"/deis/registry/protocol",
		"/deis/registry/host",
		"/deis/registry/port",
		"/deis/cache/host",
		"/deis/cache/port",
		"/deis/controller/protocol",
		"/deis/controller/host",
		"/deis/controller/port",
		"/deis/controller/builderKey",
	}
	setdir := []string{
		"/deis/controller",
		"/deis/cache",
		"/deis/database",
		"/deis/registry",
		"/deis/domains",
		"/deis/services",
	}
	tag, etcdPort := utils.BuildTag(), utils.RandomPort()
	etcdName := "deis-etcd-" + tag
	cli, stdout, stdoutPipe := dockercli.NewClient()
	dockercli.RunTestEtcd(t, etcdName, etcdPort)
	defer cli.CmdRm("-f", etcdName)
	handler := etcdutils.InitEtcd(setdir, setkeys, etcdPort)
	etcdutils.PublishEtcd(t, handler)
	host, port := utils.HostAddress(), utils.RandomPort()
	fmt.Printf("--- Run deis/builder:%s at %s:%s\n", tag, host, port)
	name := "deis-builder-" + tag
	defer cli.CmdRm("-f", "-v", name)
	go func() {
		_ = cli.CmdRm("-f", "-v", name)
		err = dockercli.RunContainer(cli,
			"--name", name,
			"--rm",
			"-p", port+":22",
			"-e", "PORT=22",
			"-e", "STORAGE_DRIVER=aufs",
			"-e", "HOST="+host,
			"-e", "ETCD_PORT="+etcdPort,
			"-e", "EXTERNAL_PORT="+port,
			"--privileged", "deis/builder:"+tag)
	}()
	dockercli.PrintToStdout(t, stdout, stdoutPipe, "deis-builder running")
	if err != nil {
		t.Fatal(err)
	}
	// FIXME: builder needs a few seconds to wake up here!
	// FIXME: Wait until etcd keys are published
	time.Sleep(5000 * time.Millisecond)
	dockercli.DeisServiceTest(t, name, port, "tcp")
	etcdutils.VerifyEtcdValue(t, "/deis/builder/host", host, etcdPort)
	etcdutils.VerifyEtcdValue(t, "/deis/builder/port", port, etcdPort)
}
Example #4
0
func TestController(t *testing.T) {
	var err error
	setkeys := []string{
		"/deis/registry/protocol",
		"/deis/registry/host",
		"/deis/registry/port",
		"/deis/platform/domain",
		"/deis/logs/host",
	}
	setdir := []string{
		"/deis/controller",
		"/deis/database",
		"/deis/registry",
		"/deis/domains",
		"/deis/scheduler",
	}
	tag, etcdPort := utils.BuildTag(), utils.RandomPort()
	imageName := utils.ImagePrefix() + "controller" + ":" + tag

	//start etcd container
	etcdName := "deis-etcd-" + tag
	cli, stdout, stdoutPipe := dockercli.NewClient()
	dockercli.RunTestEtcd(t, etcdName, etcdPort)
	defer cli.CmdRm("-f", etcdName)

	handler := etcdutils.InitEtcd(setdir, setkeys, etcdPort)
	etcdutils.PublishEtcd(t, handler)
	mock.RunMockDatabase(t, tag, etcdPort, utils.RandomPort())
	defer cli.CmdRm("-f", "deis-test-database-"+tag)
	host, port := utils.HostAddress(), utils.RandomPort()
	fmt.Printf("--- Run %s at %s:%s\n", imageName, host, port)
	name := "deis-controller-" + tag
	defer cli.CmdRm("-f", name)
	go func() {
		cli.CmdRm("-f", name)
		err = dockercli.RunContainer(cli,
			"--name", name,
			"--rm",
			"-v", "/var/run/docker.sock:/var/run/docker.sock",
			"-v", "/var/run/fleet.sock:/var/run/fleet.sock",
			"-p", port+":8000",
			"-e", "EXTERNAL_PORT="+port,
			"-e", "HOST="+host,
			"-e", "ETCD_PORT="+etcdPort,
			imageName)
	}()
	dockercli.PrintToStdout(t, stdout, stdoutPipe, "Booting")
	if err != nil {
		t.Fatal(err)
	}
	// FIXME: Wait until etcd keys are published
	time.Sleep(5000 * time.Millisecond)
	dockercli.DeisServiceTest(t, name, port, "http")
	etcdutils.VerifyEtcdValue(t, "/deis/controller/host", host, etcdPort)
	etcdutils.VerifyEtcdValue(t, "/deis/controller/port", port, etcdPort)
}
Example #5
0
func TestRegistry(t *testing.T) {
	var err error
	setkeys := []string{
		"/deis/cache/host",
		"/deis/cache/port",
		"/deis/store/gateway/host",
		"/deis/store/gateway/port",
		"/deis/store/gateway/accessKey",
		"/deis/store/gateway/secretKey",
	}
	setdir := []string{
		"/deis/cache",
		"/deis/store",
	}
	tag, etcdPort := utils.BuildTag(), utils.RandomPort()
	etcdName := "deis-etcd-" + tag
	cli, stdout, stdoutPipe := dockercli.NewClient()
	dockercli.RunTestEtcd(t, etcdName, etcdPort)
	defer cli.CmdRm("-f", etcdName)
	handler := etcdutils.InitEtcd(setdir, setkeys, etcdPort)
	etcdutils.PublishEtcd(t, handler)

	// run mock ceph containers
	cephName := "deis-ceph-" + tag
	mock.RunMockCeph(t, cephName, cli, etcdPort)
	defer cli.CmdRm("-f", "-v", cephName+"-monitor")
	defer cli.CmdRm("-f", "-v", cephName+"-daemon")
	defer cli.CmdRm("-f", cephName+"-metadata")
	defer cli.CmdRm("-f", cephName+"-gateway")

	host, port := utils.HostAddress(), utils.RandomPort()
	fmt.Printf("--- Run deis/registry:%s at %s:%s\n", tag, host, port)
	name := "deis-registry-" + tag
	defer cli.CmdRm("-f", name)
	go func() {
		_ = cli.CmdRm("-f", name)
		err = dockercli.RunContainer(cli,
			"--name", name,
			"--rm",
			"-p", port+":5000",
			"-e", "EXTERNAL_PORT="+port,
			"-e", "HOST="+host,
			"-e", "ETCD_PORT="+etcdPort,
			"deis/registry:"+tag)
	}()
	dockercli.PrintToStdout(t, stdout, stdoutPipe, "Booting")
	if err != nil {
		t.Fatal(err)
	}
	// FIXME: Wait until etcd keys are published
	time.Sleep(5000 * time.Millisecond)
	dockercli.DeisServiceTest(t, name, port, "http")
	etcdutils.VerifyEtcdValue(t, "/deis/registry/host", host, etcdPort)
	etcdutils.VerifyEtcdValue(t, "/deis/registry/port", port, etcdPort)
}
Example #6
0
func TestBuilder(t *testing.T) {
	var err error
	var errfile error
	setkeys := []string{
		"/deis/registry/protocol",
		"/deis/registry/host",
		"/deis/registry/port",
		"/deis/cache/host",
		"/deis/cache/port",
		"/deis/controller/protocol",
		"/deis/controller/host",
		"/deis/controller/port",
		"/deis/controller/builderKey",
	}
	setdir := []string{
		"/deis/controller",
		"/deis/cache",
		"/deis/database",
		"/deis/registry",
		"/deis/domains",
		"/deis/services",
	}
	setproxy := []byte("HTTP_PROXY=\nhttp_proxy=\n")

	tmpfile, errfile := ioutil.TempFile("/tmp", "deis-test-")
	if errfile != nil {
		t.Fatal(errfile)
	}
	ioutil.WriteFile(tmpfile.Name(), setproxy, 0644)
	defer os.Remove(tmpfile.Name())

	tag, etcdPort := utils.BuildTag(), utils.RandomPort()
	imageName := utils.ImagePrefix() + "builder" + ":" + tag
	etcdName := "deis-etcd-" + tag
	cli, stdout, stdoutPipe := dockercli.NewClient()
	dockercli.RunTestEtcd(t, etcdName, etcdPort)
	defer cli.CmdRm("-f", etcdName)
	handler := etcdutils.InitEtcd(setdir, setkeys, etcdPort)
	etcdutils.PublishEtcd(t, handler)
	host, port := utils.HostAddress(), utils.RandomPort()
	fmt.Printf("--- Run %s at %s:%s\n", imageName, host, port)
	name := "deis-builder-" + tag
	defer cli.CmdRm("-f", "-v", name)
	go func() {
		_ = cli.CmdRm("-f", "-v", name)
		err = dockercli.RunContainer(cli,
			"--name", name,
			"--rm",
			"-p", port+":22",
			"-e", "PORT=22",
			"-e", "HOST="+host,
			"-e", "ETCD_PORT="+etcdPort,
			"-e", "EXTERNAL_PORT="+port,
			"--privileged",
			"-v", tmpfile.Name()+":/etc/environment_proxy",
			imageName)
	}()
	dockercli.PrintToStdout(t, stdout, stdoutPipe, "deis-builder running")
	if err != nil {
		t.Fatal(err)
	}
	// FIXME: builder needs a few seconds to wake up here!
	// FIXME: Wait until etcd keys are published
	time.Sleep(5000 * time.Millisecond)
	dockercli.DeisServiceTest(t, name, port, "tcp")
	etcdutils.VerifyEtcdValue(t, "/deis/builder/host", host, etcdPort)
	etcdutils.VerifyEtcdValue(t, "/deis/builder/port", port, etcdPort)
}
Example #7
0
func TestBuilder(t *testing.T) {
	var err error
	var errfile error
	setkeys := []string{
		"/deis/registry/protocol",
		"/deis/registry/host",
		"/deis/registry/port",
		"/deis/cache/host",
		"/deis/cache/port",
		"/deis/controller/protocol",
		"/deis/controller/host",
		"/deis/controller/port",
		"/deis/controller/builderKey",
	}
	setdir := []string{
		"/deis/controller",
		"/deis/cache",
		"/deis/database",
		"/deis/registry",
		"/deis/domains",
		"/deis/services",
	}
	setproxy := []byte("HTTP_PROXY=\nhttp_proxy=\n")

	tmpfile, errfile := ioutil.TempFile("/tmp", "deis-test-")
	if errfile != nil {
		t.Fatal(errfile)
	}
	ioutil.WriteFile(tmpfile.Name(), setproxy, 0644)
	defer os.Remove(tmpfile.Name())

	tag, etcdPort := utils.BuildTag(), utils.RandomPort()
	imageName := utils.ImagePrefix() + "builder:" + tag
	etcdName := "deis-etcd-" + tag
	cli, stdout, stdoutPipe := dockercli.NewClient()
	dockercli.RunTestEtcd(t, etcdName, etcdPort)
	defer cli.CmdRm("-f", etcdName)
	handler := etcdutils.InitEtcd(setdir, setkeys, etcdPort)
	etcdutils.PublishEtcd(t, handler)
	host, port := utils.HostAddress(), utils.RandomPort()
	fmt.Printf("--- Run %s at %s:%s\n", imageName, host, port)

	// Run a mock registry to test whether the builder can push its initial
	// images.
	regport := utils.RandomPort()
	mockRegistry(host, regport, t)
	setupRegistry("http", host, regport, t, handler)
	// When we switch to Registry v2, we probably want to uncomment this
	// and then remove mockRegistry.
	// dockercli.RunTestRegistry(t, "registry", host, regport)

	name := "deis-builder-" + tag
	defer cli.CmdRm("-f", "-v", name)
	go func() {
		_ = cli.CmdRm("-f", "-v", name)
		err = dockercli.RunContainer(cli,
			"--name", name,
			"--rm",
			"-p", port+":2223",
			"-e", "PORT=2223",
			"-e", "HOST="+host,
			"-e", "ETCD_PORT="+etcdPort,
			"-e", "EXTERNAL_PORT="+port,
			"--privileged",
			"-v", tmpfile.Name()+":/etc/environment_proxy",
			imageName)
	}()
	dockercli.PrintToStdout(t, stdout, stdoutPipe, "Builder is running")
	if err != nil {
		t.Fatal(err)
	}
	time.Sleep(5000 * time.Millisecond)
	dockercli.DeisServiceTest(t, name, port, "tcp")
	etcdutils.VerifyEtcdValue(t, "/deis/builder/host", host, etcdPort)
	etcdutils.VerifyEtcdValue(t, "/deis/builder/port", port, etcdPort)
}