From 67cbafa045d394221a29ef637806fc07335b21ae Mon Sep 17 00:00:00 2001 From: Geeta Gharpure Date: Fri, 11 Aug 2023 17:46:20 +0000 Subject: [PATCH] Updating to verify members in the snapshot Signed-off-by: Geeta Gharpure --- tests/e2e/cluster_downgrade_test.go | 21 +++++++++++++++++++++ tests/e2e/ctl_v3_snapshot_test.go | 5 ++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/tests/e2e/cluster_downgrade_test.go b/tests/e2e/cluster_downgrade_test.go index 64d6b6850642..cb29a1a6c523 100644 --- a/tests/e2e/cluster_downgrade_test.go +++ b/tests/e2e/cluster_downgrade_test.go @@ -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" @@ -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() diff --git a/tests/e2e/ctl_v3_snapshot_test.go b/tests/e2e/ctl_v3_snapshot_test.go index 5fcd4e650021..721d3f2bc242 100644 --- a/tests/e2e/ctl_v3_snapshot_test.go +++ b/tests/e2e/ctl_v3_snapshot_test.go @@ -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()) @@ -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()))