mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdctl/ctlv3: do not modify db file on "restore"
This commit is contained in:
parent
c074e5c12b
commit
4e375497ea
@ -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))
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user