Exemple #1
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)
}
Exemple #2
0
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)
}
Exemple #3
0
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)

}