Skip to content

Commit

Permalink
e2e: test etcdctl backup saves v3 db
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Romano committed Sep 1, 2017
1 parent b702632 commit 079d578
Showing 1 changed file with 44 additions and 6 deletions.
50 changes: 44 additions & 6 deletions e2e/ctl_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,13 @@ func TestCtlV2RoleList(t *testing.T) {
}
}

func TestCtlV2Backup(t *testing.T) { // For https://github.com/coreos/etcd/issues/5360
func TestCtlV2Backup(t *testing.T) { testCtlV2Backup(t, 0, false) }
func TestCtlV2BackupSnapshot(t *testing.T) { testCtlV2Backup(t, 1, false) }

func TestCtlV2BackupV3(t *testing.T) { testCtlV2Backup(t, 0, true) }
func TestCtlV2BackupV3Snapshot(t *testing.T) { testCtlV2Backup(t, 1, true) }

func testCtlV2Backup(t *testing.T, snapCount int, v3 bool) {
defer testutil.AfterTest(t)

backupDir, err := ioutil.TempDir("", "testbackup0.etcd")
Expand All @@ -235,15 +241,29 @@ func TestCtlV2Backup(t *testing.T) { // For https://github.com/coreos/etcd/issue
}
defer os.RemoveAll(backupDir)

epc1 := setupEtcdctlTest(t, &configNoTLS, false)
if err := etcdctlSet(epc1, "foo1", "bar"); err != nil {
etcdCfg := configNoTLS
etcdCfg.snapCount = snapCount
epc1 := setupEtcdctlTest(t, &etcdCfg, false)

// v3 put before v2 set so snapshot happens after v3 operations to confirm
// v3 data is preserved after snapshot.
if err := ctlV3Put(ctlCtx{t: t, epc: epc1}, "v3key", "123", ""); err != nil {
t.Fatal(err)
}

if err := etcdctlBackup(epc1, epc1.procs[0].Config().dataDirPath, backupDir); err != nil {
if err := etcdctlSet(epc1, "foo1", "bar"); err != nil {
t.Fatal(err)
}

if v3 {
// v3 must lock the db to backup, so stop process
if err := epc1.Stop(); err != nil {
t.Fatal(err)
}
}
if err := etcdctlBackup(epc1, epc1.procs[0].Config().dataDirPath, backupDir, v3); err != nil {
t.Fatal(err)
}
if err := epc1.Close(); err != nil {
t.Fatalf("error closing etcd processes (%v)", err)
}
Expand All @@ -260,6 +280,17 @@ func TestCtlV2Backup(t *testing.T) { // For https://github.com/coreos/etcd/issue
t.Fatal(err)
}

ctx2 := ctlCtx{t: t, epc: epc2}
if v3 {
if err := ctlV3Get(ctx2, []string{"v3key"}, kv{"v3key", "123"}); err != nil {
t.Fatal(err)
}
} else {
if err := ctlV3Get(ctx2, []string{"v3key"}); err != nil {
t.Fatal(err)
}
}

// check if it can serve client requests
if err := etcdctlSet(epc2, "foo2", "bar"); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -451,9 +482,16 @@ func etcdctlAuthEnable(clus *etcdProcessCluster) error {
return spawnWithExpect(cmdArgs, "Authentication Enabled")
}

func etcdctlBackup(clus *etcdProcessCluster, dataDir, backupDir string) error {
func etcdctlBackup(clus *etcdProcessCluster, dataDir, backupDir string, v3 bool) error {
cmdArgs := append(etcdctlPrefixArgs(clus), "backup", "--data-dir", dataDir, "--backup-dir", backupDir)
return spawnWithExpects(cmdArgs)
if v3 {
cmdArgs = append(cmdArgs, "--with-v3")
}
proc, err := spawnCmd(cmdArgs)
if err != nil {
return err
}
return proc.Close()
}

func mustEtcdctl(t *testing.T) {
Expand Down

0 comments on commit 079d578

Please sign in to comment.