Skip to content

Commit

Permalink
Updating to verify members in the snapshot
Browse files Browse the repository at this point in the history
Signed-off-by: Geeta Gharpure <[email protected]>
  • Loading branch information
Geeta Gharpure committed Aug 11, 2023
1 parent 45c4e9b commit 67cbafa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
21 changes: 21 additions & 0 deletions tests/e2e/cluster_downgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ import (

"go.etcd.io/etcd/api/v3/version"
"go.etcd.io/etcd/client/pkg/v3/fileutil"
"go.etcd.io/etcd/client/pkg/v3/types"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/server/v3/etcdserver"
"go.etcd.io/etcd/server/v3/etcdserver/api/membership"
"go.etcd.io/etcd/server/v3/etcdserver/api/snap"
"go.etcd.io/etcd/server/v3/etcdserver/api/v2store"
"go.etcd.io/etcd/server/v3/storage/datadir"
"go.etcd.io/etcd/tests/v3/framework/config"
"go.etcd.io/etcd/tests/v3/framework/e2e"
Expand Down Expand Up @@ -293,6 +297,23 @@ func verifySnapshot(t *testing.T, epc *e2e.EtcdProcessCluster) {
t.Logf("All members have a valid snapshot")
}

func verifySnapshotMembers(t *testing.T, epc *e2e.EtcdProcessCluster, expectedMembers *clientv3.MemberListResponse) {
for i := range epc.Procs {
t.Logf("Verifying snapshot for member %d", i)
ss := snap.New(epc.Cfg.Logger, datadir.ToSnapDir(epc.Procs[i].Config().DataDirPath))
snap, err := ss.Load()
st := v2store.New(etcdserver.StoreClusterPrefix, etcdserver.StoreKeysPrefix)
err = st.Recovery(snap.Data)
assert.NoError(t, err)
for _, m := range expectedMembers.Members {
_, err := st.Get(membership.MemberStoreKey(types.ID(m.ID)), true, true)
assert.NoError(t, err)
}
t.Logf("Verifed snapshot for member %d", i)
}
t.Logf("All members have a valid snapshot")
}

func getMembersAndKeys(t *testing.T, epc *e2e.EtcdProcessCluster) (*clientv3.MemberListResponse, *clientv3.GetResponse) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down
5 changes: 4 additions & 1 deletion tests/e2e/ctl_v3_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ func TestRestoreCompactionRevBump(t *testing.T) {
require.NoError(t, ctl.Put(context.Background(), unsnappedKVs[i].Key, unsnappedKVs[i].Val, config.PutOptions{}))
}

membersBefore, err := ctl.MemberList(context.Background(), false)
require.NoError(t, err)

t.Log("Stopping the original server...")
require.NoError(t, epc.Stop())

Expand Down Expand Up @@ -388,7 +391,7 @@ func TestRestoreCompactionRevBump(t *testing.T) {
}

//Verify that initial snapshot is created by the restore operation
verifySnapshot(t, epc)
verifySnapshotMembers(t, epc, membersBefore)

require.NoError(t, epc.Restart(context.Background()))

Expand Down

0 comments on commit 67cbafa

Please sign in to comment.