コード例 #1
0
ファイル: logger_test.go プロジェクト: Blystad/deis
func TestLogger(t *testing.T) {
	var err error
	tag, etcdPort := utils.BuildTag(), utils.RandomPort()

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

	host, port := utils.HostAddress(), utils.RandomPort()
	fmt.Printf("--- Run deis/logger:%s at %s:%s\n", tag, host, port)
	name := "deis-logger-" + tag
	defer cli.CmdRm("-f", name)
	go func() {
		_ = cli.CmdRm("-f", name)
		err = dockercli.RunContainer(cli,
			"--name", name,
			"--rm",
			"-p", port+":514/udp",
			"-e", "EXTERNAL_PORT="+port,
			"-e", "HOST="+host,
			"-e", "ETCD_PORT="+etcdPort,
			"deis/logger:"+tag)
	}()
	dockercli.PrintToStdout(t, stdout, stdoutPipe, "deis-logger running")
	if err != nil {
		t.Fatal(err)
	}
	// FIXME: Wait until etcd keys are published
	time.Sleep(5000 * time.Millisecond)
	dockercli.DeisServiceTest(t, name, port, "udp")
	etcdutils.VerifyEtcdValue(t, "/deis/logs/host", host, etcdPort)
	etcdutils.VerifyEtcdValue(t, "/deis/logs/port", port, etcdPort)
}
コード例 #2
0
ファイル: cache_test.go プロジェクト: gpxl/deis
func TestCache(t *testing.T) {
	var err error
	tag := utils.BuildTag()
	imageName := utils.ImagePrefix() + "cache" + ":" + tag
	etcdPort := utils.RandomPort()
	etcdName := "deis-etcd-" + tag
	cli, stdout, stdoutPipe := dockercli.NewClient()
	dockercli.RunTestEtcd(t, etcdName, etcdPort)
	defer cli.CmdRm("-f", etcdName)
	host, port := utils.HostAddress(), utils.RandomPort()
	fmt.Printf("--- Run %s at %s:%s\n", imageName, host, port)
	name := "deis-cache-" + tag
	defer cli.CmdRm("-f", name)
	go func() {
		_ = cli.CmdRm("-f", name)
		err = dockercli.RunContainer(cli,
			"--name", name,
			"--rm",
			"-p", port+":6379",
			"-e", "EXTERNAL_PORT="+port,
			"-e", "HOST="+host,
			"-e", "ETCD_PORT="+etcdPort,
			imageName)
	}()
	dockercli.PrintToStdout(t, stdout, stdoutPipe, "started")
	if err != nil {
		t.Fatal(err)
	}
	// FIXME: Wait until etcd keys are published
	time.Sleep(5000 * time.Millisecond)
	dockercli.DeisServiceTest(t, name, port, "tcp")
	etcdutils.VerifyEtcdValue(t, "/deis/cache/host", host, etcdPort)
	etcdutils.VerifyEtcdValue(t, "/deis/cache/port", port, etcdPort)
}
コード例 #3
0
ファイル: mock.go プロジェクト: ericcapricorn/deis
// RunMockCephGateway starts a mock S3 endpoint used for component testing
func RunMockCephGateway(t *testing.T, name string, port string, etcdPort string) {
	var err error
	cli, stdout, stdoutPipe := dockercli.NewClient()
	cephImage := "deis/store-gateway:" + utils.BuildTag()
	ipaddr := utils.HostAddress()
	cephAddr := ipaddr + ":" + port
	fmt.Printf("--- Running deis/mock-ceph-gateway at %s\n", cephAddr)
	done2 := make(chan bool, 1)
	go func() {
		done2 <- true
		_ = cli.CmdRm("-f", name)
		err = dockercli.RunContainer(cli,
			"--name", name,
			"-h", "deis-store-gateway",
			"--rm",
			"-p", port+":"+"8888",
			"-e", "ETCD_PORT="+etcdPort,
			"-e", "HOST="+ipaddr,
			"-e", "EXTERNAL_PORT="+port,
			cephImage)
	}()
	dockercli.PrintToStdout(t, stdout, stdoutPipe, "deis-store-gateway running...")
	if err != nil {
		t.Fatal(err)
	}
}
コード例 #4
0
ファイル: mock.go プロジェクト: Blystad/deis
// RunMockCeph runs a set of containers used to mock a Ceph storage cluster
func RunMockCeph(t *testing.T, name string, cli *client.DockerCli, etcdPort string) {

	etcdutils.SetSingle(t, "/deis/store/hosts/"+utils.HostAddress(), utils.HostAddress(), etcdPort)
	var err error
	cli, stdout, stdoutPipe := dockercli.NewClient()
	cephImage := "deis/mock-store:latest"
	ipaddr := utils.HostAddress()
	fmt.Printf("--- Running deis/mock-store at %s\n", ipaddr)
	done2 := make(chan bool, 1)
	go func() {
		done2 <- true
		_ = cli.CmdRm("-f", name)
		err = dockercli.RunContainer(cli,
			"--name", name,
			"--rm",
			"-e", "HOST="+ipaddr,
			"-e", "ETCD_PORT="+etcdPort,
			"--net=host",
			cephImage)
	}()
	dockercli.PrintToStdout(t, stdout, stdoutPipe, "deis-store-gateway running...")
	if err != nil {
		t.Fatal(err)
	}
}
コード例 #5
0
ファイル: mock.go プロジェクト: 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)
	}
}
コード例 #6
0
ファイル: router_test.go プロジェクト: CodeJuan/deis
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)
}
コード例 #7
0
ファイル: builder_test.go プロジェクト: ericcapricorn/deis
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)
}
コード例 #8
0
ファイル: controller_test.go プロジェクト: CodeJuan/deis
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)
}
コード例 #9
0
ファイル: registry_test.go プロジェクト: Blystad/deis
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)
}
コード例 #10
0
ファイル: database_test.go プロジェクト: Blystad/deis
func TestDatabase(t *testing.T) {
	var err error
	tag, etcdPort := utils.BuildTag(), utils.RandomPort()
	cli, stdout, stdoutPipe := dockercli.NewClient()

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

	// 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")

	// run database container
	host, port := utils.HostAddress(), utils.RandomPort()
	fmt.Printf("--- Run deis/database:%s at %s:%s\n", tag, host, port)
	name := "deis-database-" + tag
	defer cli.CmdRm("-f", name)
	go func() {
		_ = cli.CmdRm("-f", name)
		err = dockercli.RunContainer(cli,
			"--name", name,
			"--rm",
			"-p", port+":5432",
			"-e", "EXTERNAL_PORT="+port,
			"-e", "HOST="+host,
			"-e", "ETCD_PORT="+etcdPort,
			"deis/database:"+tag)
	}()
	dockercli.PrintToStdout(t, stdout, stdoutPipe, "database: postgres is running...")
	if err != nil {
		t.Fatal(err)
	}
	// FIXME: Wait until etcd keys are published
	time.Sleep(5000 * time.Millisecond)
	dockercli.DeisServiceTest(t, name, port, "tcp")
	etcdutils.VerifyEtcdValue(t, "/deis/database/host", host, etcdPort)
	etcdutils.VerifyEtcdValue(t, "/deis/database/port", port, etcdPort)
}
コード例 #11
0
ファイル: controller_test.go プロジェクト: bdemers/deis
func runDeisControllerTest(
	t *testing.T, testID string, etcdPort string, servicePort string) {
	var err error
	cli, stdout, stdoutPipe := dockercli.GetNewClient()
	go func() {
		err = dockercli.RunContainer(cli,
			"--name", "deis-controller-"+testID,
			"--rm",
			"-p", servicePort+":8000",
			"-e", "PUBLISH="+servicePort,
			"-e", "HOST="+utils.GetHostIPAddress(),
			"-e", "ETCD_PORT="+etcdPort,
			"deis/controller:"+testID)
	}()
	dockercli.PrintToStdout(t, stdout, stdoutPipe, "Booting")
	if err != nil {
		t.Fatal(err)
	}
}
コード例 #12
0
ファイル: database_test.go プロジェクト: bdemers/deis
func runDeisDatabaseTest(
	t *testing.T, testID string, etcdPort string, servicePort string) {
	var err error
	dockercli.RunDeisDataTest(t, "--name", "deis-database-data",
		"-v", "/var/lib/postgresql", "deis/base", "true")
	cli, stdout, stdoutPipe := dockercli.GetNewClient()
	go func() {
		err = dockercli.RunContainer(cli,
			"--name", "deis-database-"+testID,
			"--rm",
			"-p", servicePort+":5432",
			"-e", "PUBLISH="+servicePort,
			"-e", "HOST="+utils.GetHostIPAddress(),
			"-e", "ETCD_PORT="+etcdPort,
			"--volumes-from", "deis-database-data",
			"deis/database:"+testID)
	}()
	dockercli.PrintToStdout(t, stdout, stdoutPipe, "deis-database running")
	if err != nil {
		t.Fatal(err)
	}
}
コード例 #13
0
ファイル: mock.go プロジェクト: ericcapricorn/deis
// RunMockCephDaemon sets up a single Ceph OSD
func RunMockCephDaemon(t *testing.T, name string, etcdPort string) {
	var err error
	cli, stdout, stdoutPipe := dockercli.NewClient()
	cephImage := "deis/store-daemon:" + utils.BuildTag()
	ipaddr := utils.HostAddress()
	fmt.Printf("--- Running deis/mock-ceph-daemon at %s\n", ipaddr)
	done := make(chan bool, 1)
	go func() {
		done <- true
		_ = cli.CmdRm("-f", name)
		err = dockercli.RunContainer(cli,
			"--name", name,
			"--rm",
			"-e", "HOST="+ipaddr,
			"-e", "ETCD_PORT="+etcdPort,
			"--net=host",
			cephImage)
	}()
	dockercli.PrintToStdout(t, stdout, stdoutPipe, "journal close /var/lib/ceph/osd/ceph-0/journal")
	if err != nil {
		t.Fatal(err)
	}
}
コード例 #14
0
ファイル: mock.go プロジェクト: ericcapricorn/deis
// RunMockCephMetadata starts a mock Ceph MDS
func RunMockCephMetadata(t *testing.T, name string, etcdPort string) {
	var err error
	cli, stdout, stdoutPipe := dockercli.NewClient()
	cephImage := "deis/store-metadata:" + utils.BuildTag()
	ipaddr := utils.HostAddress()
	fmt.Printf("--- Running deis/mock-ceph-metadata at %s\n", ipaddr)
	done2 := make(chan bool, 1)
	go func() {
		done2 <- true
		_ = cli.CmdRm("-f", name)
		err = dockercli.RunContainer(cli,
			"--name", name,
			"--rm",
			"-e", "ETCD_PORT="+etcdPort,
			"-e", "HOST="+ipaddr,
			"--net=host",
			cephImage)
	}()
	dockercli.PrintToStdout(t, stdout, stdoutPipe, "mds.0.1 active_start")
	if err != nil {
		t.Fatal(err)
	}
}
コード例 #15
0
ファイル: mock.go プロジェクト: inz/deis
// RunMockDatabase starts a mock postgresql database for testing.
func RunMockDatabase(t *testing.T, uid string, etcdPort string, dbPort string) {
	var err error
	cli, stdout, stdoutPipe := dockercli.GetNewClient()
	done := make(chan bool, 1)
	dbImage := "paintedfox/postgresql:latest"
	ipaddr := utils.GetHostIPAddress()
	done <- true
	go func() {
		<-done
		err = dockercli.RunContainer(cli,
			"--name", "deis-test-database-"+uid,
			"--rm",
			"-p", dbPort+":5432",
			"-e", "PUBLISH="+dbPort,
			"-e", "HOST="+ipaddr,
			"-e", "USER=deis",
			"-e", "DB=deis",
			"-e", "PASS=deis",
			dbImage)
	}()
	time.Sleep(1000 * time.Millisecond)
	dockercli.PrintToStdout(t, stdout, stdoutPipe, "Starting")
	setkeys := []string{
		"/deis/database/user",
		"/deis/database/password",
		"/deis/database/name",
	}
	setdir := []string{}
	dbhandler := etcdutils.InitetcdValues(setdir, setkeys, etcdPort)
	etcdutils.Publishvalues(t, dbhandler)
	etcdutils.SetEtcdValues(t,
		[]string{"/deis/database/host", "/deis/database/port", "/deis/database/engine"},
		[]string{ipaddr, dbPort, "postgresql_psycopg2"}, dbhandler.C)
	if err != nil {
		t.Fatal(err)
	}
}
コード例 #16
0
ファイル: builder_test.go プロジェクト: bdemers/deis
func runDeisBuilderTest(
	t *testing.T, testID string, etcdPort string, servicePort string) {
	var err error
	dockercli.RunDeisDataTest(t, "--name", "deis-builder-data",
		"-v", "/var/lib/docker", "deis/base", "true")
	cli, stdout, stdoutPipe := dockercli.GetNewClient()
	go func() {
		err = dockercli.RunContainer(cli,
			"--name", "deis-builder-"+testID,
			"--rm",
			"-p", servicePort+":22",
			"-e", "PUBLISH=22",
			"-e", "STORAGE_DRIVER=aufs",
			"-e", "HOST="+utils.GetHostIPAddress(),
			"-e", "ETCD_PORT="+etcdPort,
			"-e", "PORT="+servicePort,
			"--volumes-from", "deis-builder-data",
			"--privileged", "deis/builder:"+testID)
	}()
	dockercli.PrintToStdout(t, stdout, stdoutPipe, "deis-builder running")
	if err != nil {
		t.Fatal(err)
	}
}
コード例 #17
0
ファイル: mock.go プロジェクト: CodeJuan/deis
// RunMockCeph runs a container used to mock a Ceph storage cluster
func RunMockCeph(t *testing.T, name string, cli *client.DockerCli, etcdPort string) {

	storeImage := utils.ImagePrefix() + "mock-store:" + utils.BuildTag()
	etcdutils.SetSingle(t, "/deis/store/hosts/"+utils.HostAddress(), utils.HostAddress(), etcdPort)
	var err error
	cli, stdout, stdoutPipe := dockercli.NewClient()
	ipaddr := utils.HostAddress()
	fmt.Printf("--- Running %s at %s\n", storeImage, ipaddr)
	done := make(chan bool, 1)
	go func() {
		done <- true
		err = dockercli.RunContainer(cli,
			"--name", name,
			"--rm",
			"-e", "HOST="+ipaddr,
			"-e", "ETCD_PORT="+etcdPort,
			"--net=host",
			storeImage)
	}()
	dockercli.PrintToStdout(t, stdout, stdoutPipe, "deis-store-gateway running...")
	if err != nil {
		t.Fatal(err)
	}
}
コード例 #18
0
ファイル: recovery_test.go プロジェクト: CodeJuan/deis
func TestDatabaseRecovery(t *testing.T) {
	var err error
	tag, etcdPort := utils.BuildTag(), utils.RandomPort()
	cli, stdout, _ := dockercli.NewClient()
	imageName := utils.ImagePrefix() + "database" + ":" + tag

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

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

	// create volumes
	databaseVolumeA := "deis-database-data-a-" + tag
	databaseVolumeB := "deis-database-data-b-" + tag
	defer cli.CmdRm("-f", databaseVolumeA)
	defer cli.CmdRm("-f", databaseVolumeB)
	go func() {
		fmt.Printf("--- Creating Volume A\n")
		_ = cli.CmdRm("-f", "-v", databaseVolumeA)
		dockercli.CreateVolume(t, cli, databaseVolumeA, "/var/lib/postgresql")

		fmt.Printf("--- Creating Volume B\n")

		_ = cli.CmdRm("-f", databaseVolumeB)
		dockercli.CreateVolume(t, cli, databaseVolumeB, "/var/lib/postgresql")
	}()
	dockercli.WaitForLine(t, stdout, databaseVolumeB, true)

	// setup database container start/stop routines
	host, port := utils.HostAddress(), utils.RandomPort()
	fmt.Printf("--- Run deis/database:%s at %s:%s\n", tag, host, port)
	name := "deis-database-" + tag
	defer cli.CmdRm("-f", name)
	startDatabase := func(volumeName string) {
		_ = cli.CmdRm("-f", name)
		err = dockercli.RunContainer(cli,
			"--name", name,
			"--volumes-from", volumeName,
			"--rm",
			"-p", port+":5432",
			"-e", "EXTERNAL_PORT="+port,
			"-e", "HOST="+host,
			"-e", "ETCD_PORT="+etcdPort,
			"-e", "ETCD_TTL=2",
			"-e", "BACKUP_FREQUENCY=1s",
			"-e", "BACKUPS_TO_RETAIN=100",
			imageName)
	}

	stopDatabase := func() {
		fmt.Println("--- Stopping data-database... ")
		if err = stdout.Close(); err != nil {
			t.Fatal("Failed to closeStdout")
		}
		_ = cli.CmdStop(name)
		fmt.Println("Done")
	}

	//ACTION

	//STEP 1: start db with volume A and wait for init to complete
	fmt.Println("--- Starting database with Volume A... ")
	go startDatabase(databaseVolumeA)
	dockercli.WaitForLine(t, stdout, "database: postgres is running...", true)
	fmt.Println("Done")

	db := OpenDeisDatabase(t, host, port)
	TryTableSelect(t, db, "api_foo", true)

	stopDatabase()

	//STEP 2a: start db with volume B, wait for init and create the table
	cli, stdout, _ = dockercli.NewClient()
	fmt.Printf("--- Starting database with Volume B... ")
	go startDatabase(databaseVolumeB)
	dockercli.WaitForLine(t, stdout, "database: postgres is running...", true)
	fmt.Println("Done")

	db = OpenDeisDatabase(t, host, port)
	TryTableSelect(t, db, "api_foo", true)

	fmt.Println("--- Creating the table")
	execSql(t, db, "create table api_foo(t text)")

	//STEP 2b: make sure we observed full backup cycle after forced checkpoint
	fmt.Println("--- Waiting for the change to be backed up... ")
	dockercli.WaitForLine(t, stdout, "database: performing a backup...", true)
	dockercli.WaitForLine(t, stdout, "database: backup has been completed.", true)
	fmt.Println("Done")

	stopDatabase()

	//STEP 3: start db with volume A again and assert table existence
	cli, stdout, _ = dockercli.NewClient()
	fmt.Printf("--- Starting database with Volume A again... ")
	go startDatabase(databaseVolumeA)
	dockercli.WaitForLine(t, stdout, "database: postgres is running...", true)
	fmt.Println("Done")

	db = OpenDeisDatabase(t, host, port)
	TryTableSelect(t, db, "api_foo", false)

}
コード例 #19
0
ファイル: store_test.go プロジェクト: Blystad/deis
func TestStore(t *testing.T) {
	hostname := utils.Hostname()
	var err error

	// Set up etcd, which will be used by all containers
	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)
	host := utils.HostAddress()

	// prep etcd with the monitor hostname -- this is done in an ExecStartPre in the monitor unit
	etcdutils.SetSingle(t, "/deis/store/hosts/"+host, hostname, etcdPort)

	// since we're only running one OSD, our default of 128 placement groups is too large
	etcdutils.SetSingle(t, "/deis/store/pgNum", "64", etcdPort)

	// test deis-store-monitor
	fmt.Printf("--- Run deis/store-monitor:%s at %s\n", tag, host)
	name := "deis-store-monitor-" + tag
	defer cli.CmdRm("-f", name)
	go func() {
		_ = cli.CmdRm("-f", name)
		err = dockercli.RunContainer(cli,
			"--name", name,
			"--rm",
			"-e", "HOST="+host,
			"-e", "ETCD_PORT="+etcdPort,
			"-e", "NUM_STORES=1",
			"--net=host",
			"deis/store-monitor:"+tag)
	}()
	dockercli.PrintToStdout(t, stdout, stdoutPipe, "monmap e1: 1 mons at")
	if err != nil {
		t.Fatal(err)
	}
	// FIXME: Wait until etcd keys are published
	time.Sleep(5000 * time.Millisecond)
	dockercli.DeisServiceTest(t, name, "6789", "tcp")
	etcdutils.VerifyEtcdKey(t, "/deis/store/monKeyring", etcdPort)
	etcdutils.VerifyEtcdKey(t, "/deis/store/adminKeyring", etcdPort)
	etcdutils.VerifyEtcdValue(t, "/deis/store/monSetupComplete", "youBetcha", etcdPort)

	// test deis-store-daemon
	fmt.Printf("--- Run deis/store-daemon:%s at %s\n", tag, host)
	name = "deis-store-daemon-" + tag
	cli2, stdout2, stdoutPipe2 := dockercli.NewClient()
	defer cli2.CmdRm("-f", "-v", name)
	go func() {
		_ = cli2.CmdRm("-f", "-v", name)
		err = dockercli.RunContainer(cli2,
			"--name", name,
			"--rm",
			"-e", "HOST="+host,
			"-e", "ETCD_PORT="+etcdPort,
			"--net=host",
			"deis/store-daemon:"+tag)
	}()
	dockercli.PrintToStdout(t, stdout2, stdoutPipe2, "journal close /var/lib/ceph/osd/ceph-0/journal")
	if err != nil {
		t.Fatal(err)
	}
	// FIXME: Wait until etcd keys are published
	time.Sleep(5000 * time.Millisecond)
	dockercli.DeisServiceTest(t, name, "6800", "tcp")
	etcdutils.VerifyEtcdValue(t, "/deis/store/osds/"+host, "0", etcdPort)

	// test deis-store-metadata
	fmt.Printf("--- Run deis/store-metadata:%s at %s\n", tag, host)
	name = "deis-store-metadata-" + tag
	cli3, stdout3, stdoutPipe3 := dockercli.NewClient()
	defer cli3.CmdRm("-f", "-v", name)
	go func() {
		_ = cli3.CmdRm("-f", "-v", name)
		err = dockercli.RunContainer(cli3,
			"--name", name,
			"--rm",
			"-e", "HOST="+host,
			"-e", "ETCD_PORT="+etcdPort,
			"--net=host",
			"deis/store-metadata:"+tag)
	}()
	dockercli.PrintToStdout(t, stdout3, stdoutPipe3, "mds.0.1 active_start")
	if err != nil {
		t.Fatal(err)
	}

	// test deis-store-gateway
	port := utils.RandomPort()
	fmt.Printf("--- Run deis/store-gateway:%s at %s:%s\n", tag, host, port)
	name = "deis-store-gateway-" + tag
	cli4, stdout4, stdoutPipe4 := dockercli.NewClient()
	defer cli4.CmdRm("-f", name)
	go func() {
		_ = cli4.CmdRm("-f", name)
		err = dockercli.RunContainer(cli4,
			"--name", name,
			"--rm",
			"-h", "deis-store-gateway",
			"-p", port+":8888",
			"-e", "HOST="+host,
			"-e", "EXTERNAL_PORT="+port,
			"-e", "ETCD_PORT="+etcdPort,
			"deis/store-gateway:"+tag)
	}()
	dockercli.PrintToStdout(t, stdout4, stdoutPipe4, "deis-store-gateway running...")
	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/store/gateway/host", host, etcdPort)
	etcdutils.VerifyEtcdValue(t, "/deis/store/gateway/port", port, etcdPort)
	etcdutils.VerifyEtcdKey(t, "/deis/store/gatewayKeyring", etcdPort)
	etcdutils.VerifyEtcdKey(t, "/deis/store/gateway/accessKey", etcdPort)
	etcdutils.VerifyEtcdKey(t, "/deis/store/gateway/secretKey", etcdPort)
}
コード例 #20
0
ファイル: builder_test.go プロジェクト: gpxl/deis
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)
}
コード例 #21
0
ファイル: builder_test.go プロジェクト: CodeJuan/deis
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)
}