Beispiel #1
0
// Runner is the base level to start a restore and is called from command
func Runner(restorepath string) int {
	consulClient := &consul.Consul{Client: *consul.Client()}

	conf := config.ParseConfig(false)

	log.Printf("[DEBUG] Starting restore of %s/%s", conf.S3Bucket, restorepath)
	doWork(conf, consulClient, restorepath)
	return 0
}
// Setup some basic structs we can use across tests
func testingStructs() *Backup {
	consulClient := &consul.Consul{}
	consulClient.Client = *consul.Client()
	consulClient.KeyData = kvpairlist
	consulClient.PQData = pqtestlist
	consulClient.ACLData = acltestlist
	backup := &Backup{
		Client:        consulClient,
		StartTime:     time.Now().Unix(),
		Config:        testingConfig(),
		LocalFilePath: "/tmp",
	}

	return backup
}
Beispiel #3
0
// Runner is the main runner for a backup
func Runner(version string) int {
	// Start up the http server health checks
	go health.StartServer()

	conf := config.ParseConfig(false)
	conf.Version = version
	client := &consul.Consul{Client: *consul.Client()}

	if conf.Acceptance {
		doWork(conf, client)
	} else {
		log.Printf("[DEBUG] Backup starting on interval: %v", conf.BackupInterval)
		ticker := time.NewTicker(conf.BackupInterval)
		for range ticker.C {
			doWork(conf, client)
		}
	}
	return 0
}
func TestAcceptance(t *testing.T) {
	var err error
	conf := config.ParseConfig(true)
	if conf.Acceptance == false {
		t.Skip("Skipping acceptance test, Set ACCEPTANCE_TEST=1 to run")
	}
	command := "consul"
	commandargs := []string{"agent", "-dev", "-bind=127.0.0.1"}
	cmd := &LocalDevConsul{Command: command, CommandArgs: commandargs}
	go cmd.Run()

	// 5-10 seconds is about the time it takes for consul to wake up
	time.Sleep(5 * time.Second)

	c := consul.Client()

	seedData := &Seeder{}

	t.Log("Adding random seed data to consul kv")
	for i := 1; i < 500; i++ {
		// more entropy is needed here.
		randname := fmt.Sprintf("%s.%s", randomdata.SillyName(), randomdata.SillyName())
		err = putKey(c, randname, randomdata.Address(), seedData)
		if err != nil {
			t.Errorf("Failed putting test data to kv: %v", err)
		}
		err = putKey(c, randomdata.IpV4Address(), randomdata.Paragraph(), seedData)
		if err != nil {
			t.Errorf("Failed putting test data to kv: %v", err)
		}
	}

	t.Log("Starting Backup")

	backup.Runner("test")

	_, err = c.KV().DeleteTree("", nil)
	if err != nil {
		for _, i := range cmd.CommandOut {
			log.Printf("CONSUL: %v", i)
		}
		t.Errorf("Unable to clear consul kv store after backup; %v", err)
	}

	restore.Runner("/tmp/acceptancetest.tar.gz")

	for _, kv := range seedData.Data {
		//log.Printf("SEED: %v | %v", kv.Key, string(kv.Value))
		err := checkKey(c, kv)
		if err != nil {
			for _, i := range cmd.CommandOut {
				log.Printf("CONSUL: %v", i)
			}
			t.Errorf("Key Failure: %v", err)
		}
	}

	// Remove the staging path
	err = os.RemoveAll("/tmp/acceptancetest")
	if err != nil {
		log.Printf("Unable to remove temporary backup file: %v", err)
	}

	err = os.RemoveAll("/tmp/acceptancetest.tar.gz")
	if err != nil {
		log.Printf("Unable to remove temporary backup file: %v", err)
	}

}