From b1375dee1d3da185096f0c3f5a1598027b844cd9 Mon Sep 17 00:00:00 2001 From: Andrew Mason Date: Thu, 29 Feb 2024 11:01:33 -0500 Subject: [PATCH] rewrite with vtctldclient command Signed-off-by: Andrew Mason --- go/test/endtoend/cluster/vtctldclient_process.go | 13 +++++++++++++ go/test/endtoend/keyspace/keyspace_test.go | 5 ++--- go/test/endtoend/reparent/utils/utils.go | 7 ++++--- go/test/endtoend/tabletmanager/commands_test.go | 15 +++++++++------ 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/go/test/endtoend/cluster/vtctldclient_process.go b/go/test/endtoend/cluster/vtctldclient_process.go index 24ec6f69fe3..971e929ebfc 100644 --- a/go/test/endtoend/cluster/vtctldclient_process.go +++ b/go/test/endtoend/cluster/vtctldclient_process.go @@ -161,6 +161,19 @@ func (vtctldclient *VtctldClientProcess) ChangeTabletType(tablet *Vttablet, tabl ) } +// GetShardReplication returns a mapping of cell to shard replication for the given keyspace and shard. +func (vtctldclient *VtctldClientProcess) GetShardReplication(keyspace string, shard string, cells ...string) (replication map[string]*topodatapb.ShardReplication, err error) { + args := append([]string{"GetShardReplication", keyspace + "/" + shard}, cells...) + out, err := vtctldclient.ExecuteCommandWithOutput(args...) + if err != nil { + return nil, err + } + + replication = map[string]*topodatapb.ShardReplication{} + err = json2.Unmarshal([]byte(out), &replication) + return replication, err +} + // GetSrvKeyspaces returns a mapping of cell to srv keyspace for the given keyspace. func (vtctldclient *VtctldClientProcess) GetSrvKeyspaces(keyspace string, cells ...string) (ksMap map[string]*topodatapb.SrvKeyspace, err error) { args := append([]string{"GetSrvKeyspaces", keyspace}, cells...) diff --git a/go/test/endtoend/keyspace/keyspace_test.go b/go/test/endtoend/keyspace/keyspace_test.go index 66d9c304cc0..11632b10d72 100644 --- a/go/test/endtoend/keyspace/keyspace_test.go +++ b/go/test/endtoend/keyspace/keyspace_test.go @@ -17,7 +17,6 @@ limitations under the License. package sequence import ( - "context" "encoding/binary" "encoding/json" "flag" @@ -262,7 +261,7 @@ func TestDeleteKeyspace(t *testing.T) { // Create the serving/replication entries and check that they exist, // so we can later check they're deleted. _ = clusterForKSTest.VtctldClientProcess.ExecuteCommand("RebuildKeyspaceGraph", "test_delete_keyspace") - _, _ = clusterForKSTest.TopoProcess.Server.GetShardReplication(context.Background(), cell, "test_delete_keyspace", "0") + _, _ = clusterForKSTest.VtctldClientProcess.GetShardReplication("test_delete_keyspace/0", cell) _ = clusterForKSTest.VtctldClientProcess.ExecuteCommand("GetSrvKeyspace", cell, "test_delete_keyspace") // Recursive DeleteKeyspace @@ -275,7 +274,7 @@ func TestDeleteKeyspace(t *testing.T) { require.Error(t, err) err = clusterForKSTest.VtctldClientProcess.ExecuteCommand("GetTablet", "zone1-0000000100") require.Error(t, err) - _, err = clusterForKSTest.TopoProcess.Server.GetShardReplication(context.Background(), cell, "test_delete_keyspace", "0") + _, err = clusterForKSTest.VtctldClientProcess.GetShardReplication("test_delete_keyspace/0", cell) require.Error(t, err) err = clusterForKSTest.VtctldClientProcess.ExecuteCommand("GetSrvKeyspace", cell, "test_delete_keyspace") require.Error(t, err) diff --git a/go/test/endtoend/reparent/utils/utils.go b/go/test/endtoend/reparent/utils/utils.go index f8a4f2625dc..2ff290f2def 100644 --- a/go/test/endtoend/reparent/utils/utils.go +++ b/go/test/endtoend/reparent/utils/utils.go @@ -606,12 +606,13 @@ func CheckReplicaStatus(ctx context.Context, t *testing.T, tablet *cluster.Vttab // CheckReparentFromOutside checks that cluster was reparented from outside func CheckReparentFromOutside(t *testing.T, clusterInstance *cluster.LocalProcessCluster, tablet *cluster.Vttablet, downPrimary bool, baseTime int64) { - result, err := clusterInstance.TopoProcess.Server.GetShardReplication(context.Background(), cell1, KeyspaceName, ShardName) + result, err := clusterInstance.VtctldClientProcess.GetShardReplication(KeyspaceName, ShardName, cell1) require.Nil(t, err, "error should be Nil") + require.NotNil(t, result[cell1], "result should not be nil") if !downPrimary { - assert.Len(t, result.Nodes, 3) + assert.Len(t, result[cell1].Nodes, 3) } else { - assert.Len(t, result.Nodes, 2) + assert.Len(t, result[cell1].Nodes, 2) } // make sure the primary status page says it's the primary diff --git a/go/test/endtoend/tabletmanager/commands_test.go b/go/test/endtoend/tabletmanager/commands_test.go index 9ac5e3fb16b..e91773e1ca4 100644 --- a/go/test/endtoend/tabletmanager/commands_test.go +++ b/go/test/endtoend/tabletmanager/commands_test.go @@ -186,23 +186,26 @@ func runHookAndAssert(t *testing.T, params []string, expectedStatus int64, expec func TestShardReplicationFix(t *testing.T) { // make sure the replica is in the replication graph, 2 nodes: 1 primary, 1 replica defer cluster.PanicHandler(t) - result, err := clusterInstance.TopoProcess.Server.GetShardReplication(context.Background(), cell, keyspaceName, shardName) + result, err := clusterInstance.VtctldClientProcess.GetShardReplication(keyspaceShard, cell) require.Nil(t, err, "error should be Nil") - assert.Len(t, result.Nodes, 3) + require.NotNil(t, result[cell], "result should not be Nil") + assert.Len(t, result[cell].Nodes, 3) // Manually add a bogus entry to the replication graph, and check it is removed by ShardReplicationFix err = clusterInstance.VtctldClientProcess.ExecuteCommand("ShardReplicationAdd", keyspaceShard, fmt.Sprintf("%s-9000", cell)) require.Nil(t, err, "error should be Nil") - result, err = clusterInstance.TopoProcess.Server.GetShardReplication(context.Background(), cell, keyspaceName, shardName) + result, err = clusterInstance.VtctldClientProcess.GetShardReplication(keyspaceShard, cell) require.Nil(t, err, "error should be Nil") - assert.Len(t, result.Nodes, 4) + require.NotNil(t, result[cell], "result should not be Nil") + assert.Len(t, result[cell].Nodes, 4) err = clusterInstance.VtctldClientProcess.ExecuteCommand("ShardReplicationFix", cell, keyspaceShard) require.Nil(t, err, "error should be Nil") - result, err = clusterInstance.TopoProcess.Server.GetShardReplication(context.Background(), cell, keyspaceName, shardName) + result, err = clusterInstance.VtctldClientProcess.GetShardReplication(keyspaceShard, cell) require.Nil(t, err, "error should be Nil") - assert.Len(t, result.Nodes, 3) + require.NotNil(t, result[cell], "result should not be Nil") + assert.Len(t, result[cell].Nodes, 3) } func TestGetSchema(t *testing.T) {