Skip to content

Commit

Permalink
Merge pull request #11157 from gyuho/release-3.2-patch
Browse files Browse the repository at this point in the history
etcdctl/ctlv3: do not modify db file on "restore"
  • Loading branch information
gyuho authored Sep 17, 2019
2 parents c7e4e50 + 4e37549 commit b7fab55
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions e2e/ctl_v3_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,35 @@ func snapshotCorruptTest(cx ctlCtx) {
}
}

// This test ensures that the snapshot status does not modify the snapshot file
func TestCtlV3SnapshotStatusBeforeRestore(t *testing.T) { testCtl(t, snapshotStatusBeforeRestoreTest) }

func snapshotStatusBeforeRestoreTest(cx ctlCtx) {
fpath := "test.snapshot"
defer os.RemoveAll(fpath)

if err := ctlV3SnapshotSave(cx, fpath); err != nil {
cx.t.Fatalf("snapshotTest ctlV3SnapshotSave error (%v)", err)
}

// snapshot status on the fresh snapshot file
_, err := getSnapshotStatus(cx, fpath)
if err != nil {
cx.t.Fatalf("snapshotTest getSnapshotStatus error (%v)", err)
}

defer os.RemoveAll("snap.etcd")
serr := spawnWithExpect(
append(cx.PrefixArgs(), "snapshot", "restore",
"--data-dir", "snap.etcd",
fpath),
"added member")

if serr != nil {
cx.t.Fatal(serr)
}
}

func ctlV3SnapshotSave(cx ctlCtx, fpath string) error {
cmdArgs := append(cx.PrefixArgs(), "snapshot", "save", fpath)
return spawnWithExpect(cmdArgs, fmt.Sprintf("Snapshot saved at %s", fpath))
Expand Down
2 changes: 1 addition & 1 deletion etcdctl/ctlv3/command/snapshot_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func dbStatus(p string) dbstatus {

ds := dbstatus{}

db, err := bolt.Open(p, 0400, nil)
db, err := bolt.Open(p, 0400, &bolt.Options{ReadOnly: true})
if err != nil {
ExitWithError(ExitError, err)
}
Expand Down

0 comments on commit b7fab55

Please sign in to comment.