Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite _many_ tests to use vtctldclient invocations, mostly non-output related stuff #15270

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions go/test/endtoend/backup/vtbackup/backup_only_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ func TestTabletInitialBackup(t *testing.T) {
restore(t, primary, "replica", "NOT_SERVING")
// Vitess expects that the user has set the database into ReadWrite mode before calling
// TabletExternallyReparented
err = localCluster.VtctlclientProcess.ExecuteCommand(
"SetReadWrite", primary.Alias)
err = localCluster.VtctldClientProcess.ExecuteCommand(
"SetWritable", primary.Alias, "true")
require.Nil(t, err)
err = localCluster.VtctlclientProcess.ExecuteCommand(
err = localCluster.VtctldClientProcess.ExecuteCommand(
"TabletExternallyReparented", primary.Alias)
require.Nil(t, err)
restore(t, replica1, "replica", "SERVING")
Expand Down Expand Up @@ -277,7 +277,7 @@ func initTablets(t *testing.T, startTablet bool, initShardPrimary bool) {

if initShardPrimary {
// choose primary and start replication
err := localCluster.VtctlclientProcess.InitShardPrimary(keyspaceName, shardName, cell, primary.TabletUID)
err := localCluster.VtctldClientProcess.InitShardPrimary(keyspaceName, shardName, cell, primary.TabletUID)
require.Nil(t, err)
}
}
Expand Down Expand Up @@ -339,7 +339,7 @@ func tearDown(t *testing.T, initMysql bool) {
for _, tablet := range []cluster.Vttablet{*primary, *replica1, *replica2} {
resetTabletDirectory(t, tablet, initMysql)
// DeleteTablet on a primary will cause tablet to shutdown, so should only call it after tablet is already shut down
err := localCluster.VtctlclientProcess.ExecuteCommand("DeleteTablet", "--", "--allow_primary", tablet.Alias)
err := localCluster.VtctldClientProcess.ExecuteCommand("DeleteTablets", "--allow-primary", tablet.Alias)
require.Nil(t, err)
}
}
Expand Down
103 changes: 49 additions & 54 deletions go/test/endtoend/backup/vtctlbackup/backup_utils.go

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions go/test/endtoend/cellalias/cell_alias_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ func TestMain(m *testing.M) {
return 1, err
}
}
if err := localCluster.VtctlclientProcess.InitializeShard(keyspaceName, shard1.Name, shard1Primary.Cell, shard1Primary.TabletUID); err != nil {
if err := localCluster.VtctldClientProcess.InitializeShard(keyspaceName, shard1.Name, shard1Primary.Cell, shard1Primary.TabletUID); err != nil {
return 1, err
}

// run a health check on source replica so it responds to discovery
// (for binlog players) and on the source rdonlys (for workers)
for _, tablet := range []string{shard1Replica.Alias, shard1Rdonly.Alias} {
if err := localCluster.VtctlclientProcess.ExecuteCommand("RunHealthCheck", tablet); err != nil {
if err := localCluster.VtctldClientProcess.ExecuteCommand("RunHealthCheck", tablet); err != nil {
return 1, err
}
}
Expand All @@ -204,22 +204,22 @@ func TestMain(m *testing.M) {
}
}

if err := localCluster.VtctlclientProcess.InitializeShard(keyspaceName, shard2.Name, shard2Primary.Cell, shard2Primary.TabletUID); err != nil {
if err := localCluster.VtctldClientProcess.InitializeShard(keyspaceName, shard2.Name, shard2Primary.Cell, shard2Primary.TabletUID); err != nil {
return 1, err
}

if err := localCluster.StartVTOrc(keyspaceName); err != nil {
return 1, err
}

if err := localCluster.VtctlclientProcess.ApplySchema(keyspaceName, fmt.Sprintf(sqlSchema, tableName)); err != nil {
if err := localCluster.VtctldClientProcess.ApplySchema(keyspaceName, fmt.Sprintf(sqlSchema, tableName)); err != nil {
return 1, err
}
if err := localCluster.VtctlclientProcess.ApplyVSchema(keyspaceName, fmt.Sprintf(vSchema, tableName)); err != nil {
if err := localCluster.VtctldClientProcess.ApplyVSchema(keyspaceName, fmt.Sprintf(vSchema, tableName)); err != nil {
return 1, err
}

_ = localCluster.VtctlclientProcess.ExecuteCommand("RebuildKeyspaceGraph", keyspaceName)
_ = localCluster.VtctldClientProcess.ExecuteCommand("RebuildKeyspaceGraph", keyspaceName)

return m.Run(), nil
}()
Expand All @@ -237,7 +237,7 @@ func TestAlias(t *testing.T) {
insertInitialValues(t)
defer deleteInitialValues(t)

err := localCluster.VtctlclientProcess.ExecuteCommand("RebuildKeyspaceGraph", keyspaceName)
err := localCluster.VtctldClientProcess.ExecuteCommand("RebuildKeyspaceGraph", keyspaceName)
require.NoError(t, err)
shard1 := localCluster.Keyspaces[0].Shards[0]
shard2 := localCluster.Keyspaces[0].Shards[1]
Expand All @@ -251,11 +251,11 @@ func TestAlias(t *testing.T) {
cluster.CheckSrvKeyspace(t, cell2, keyspaceName, expectedPartitions, *localCluster)

// Adds alias so vtgate can route to replica/rdonly tablets that are not in the same cell, but same alias
err = localCluster.VtctlclientProcess.ExecuteCommand("AddCellsAlias", "--",
err = localCluster.VtctldClientProcess.ExecuteCommand("AddCellsAlias",
"--cells", allCells,
"region_east_coast")
require.NoError(t, err)
err = localCluster.VtctlclientProcess.ExecuteCommand("UpdateCellsAlias", "--",
err = localCluster.VtctldClientProcess.ExecuteCommand("UpdateCellsAlias",
"--cells", allCells,
"region_east_coast")
require.NoError(t, err)
Expand All @@ -277,7 +277,7 @@ func TestAlias(t *testing.T) {
testQueriesOnTabletType(t, "rdonly", vtgateInstance.GrpcPort, false)

// now, delete the alias, so that if we run above assertions again, it will fail for replica,rdonly target type
err = localCluster.VtctlclientProcess.ExecuteCommand("DeleteCellsAlias",
err = localCluster.VtctldClientProcess.ExecuteCommand("DeleteCellsAlias",
"region_east_coast")
require.NoError(t, err)

Expand All @@ -301,7 +301,7 @@ func TestAddAliasWhileVtgateUp(t *testing.T) {
insertInitialValues(t)
defer deleteInitialValues(t)

err := localCluster.VtctlclientProcess.ExecuteCommand("RebuildKeyspaceGraph", keyspaceName)
err := localCluster.VtctldClientProcess.ExecuteCommand("RebuildKeyspaceGraph", keyspaceName)
require.NoError(t, err)
shard1 := localCluster.Keyspaces[0].Shards[0]
shard2 := localCluster.Keyspaces[0].Shards[1]
Expand All @@ -328,7 +328,7 @@ func TestAddAliasWhileVtgateUp(t *testing.T) {
testQueriesOnTabletType(t, "rdonly", vtgateInstance.GrpcPort, true)

// Adds alias so vtgate can route to replica/rdonly tablets that are not in the same cell, but same alias
err = localCluster.VtctlclientProcess.ExecuteCommand("AddCellsAlias", "--",
err = localCluster.VtctldClientProcess.ExecuteCommand("AddCellsAlias",
"--cells", allCells,
"region_east_coast")
require.NoError(t, err)
Expand Down
12 changes: 6 additions & 6 deletions go/test/endtoend/cluster/cluster_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ func (cluster *LocalProcessCluster) startKeyspace(keyspace Keyspace, shardNames
}

// Make first tablet as primary
if err = cluster.VtctlclientProcess.InitializeShard(keyspace.Name, shardName, cluster.Cell, shard.Vttablets[0].TabletUID); err != nil {
if err = cluster.VtctldClientProcess.InitializeShard(keyspace.Name, shardName, cluster.Cell, shard.Vttablets[0].TabletUID); err != nil {
log.Errorf("error running InitializeShard on keyspace %v, shard %v: %v", keyspace.Name, shardName, err)
return
}
Expand All @@ -441,15 +441,15 @@ func (cluster *LocalProcessCluster) startKeyspace(keyspace Keyspace, shardNames

// Apply Schema SQL
if keyspace.SchemaSQL != "" {
if err = cluster.VtctlclientProcess.ApplySchema(keyspace.Name, keyspace.SchemaSQL); err != nil {
if err = cluster.VtctldClientProcess.ApplySchema(keyspace.Name, keyspace.SchemaSQL); err != nil {
log.Errorf("error applying schema: %v, %v", keyspace.SchemaSQL, err)
return
}
}

// Apply VSchema
if keyspace.VSchema != "" {
if err = cluster.VtctlclientProcess.ApplyVSchema(keyspace.Name, keyspace.VSchema); err != nil {
if err = cluster.VtctldClientProcess.ApplyVSchema(keyspace.Name, keyspace.VSchema); err != nil {
log.Errorf("error applying vschema: %v, %v", keyspace.VSchema, err)
return
}
Expand Down Expand Up @@ -581,7 +581,7 @@ func (cluster *LocalProcessCluster) StartKeyspaceLegacy(keyspace Keyspace, shard
}

// Make first tablet as primary
if err = cluster.VtctlclientProcess.InitShardPrimary(keyspace.Name, shardName, cluster.Cell, shard.Vttablets[0].TabletUID); err != nil {
if err = cluster.VtctldClientProcess.InitShardPrimary(keyspace.Name, shardName, cluster.Cell, shard.Vttablets[0].TabletUID); err != nil {
log.Errorf("error running ISM on keyspace %v, shard %v: %v", keyspace.Name, shardName, err)
return
}
Expand All @@ -601,15 +601,15 @@ func (cluster *LocalProcessCluster) StartKeyspaceLegacy(keyspace Keyspace, shard

// Apply Schema SQL
if keyspace.SchemaSQL != "" {
if err = cluster.VtctlclientProcess.ApplySchema(keyspace.Name, keyspace.SchemaSQL); err != nil {
if err = cluster.VtctldClientProcess.ApplySchema(keyspace.Name, keyspace.SchemaSQL); err != nil {
log.Errorf("error applying schema: %v, %v", keyspace.SchemaSQL, err)
return
}
}

// Apply VSchema
if keyspace.VSchema != "" {
if err = cluster.VtctlclientProcess.ApplyVSchema(keyspace.Name, keyspace.VSchema); err != nil {
if err = cluster.VtctldClientProcess.ApplyVSchema(keyspace.Name, keyspace.VSchema); err != nil {
log.Errorf("error applying vschema: %v, %v", keyspace.VSchema, err)
return
}
Expand Down
4 changes: 2 additions & 2 deletions go/test/endtoend/cluster/cluster_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func PanicHandler(t testing.TB) {

// ListBackups Lists back preset in shard
func (cluster LocalProcessCluster) ListBackups(shardKsName string) ([]string, error) {
output, err := cluster.VtctlclientProcess.ExecuteCommandWithOutput("ListBackups", shardKsName)
output, err := cluster.VtctldClientProcess.ExecuteCommandWithOutput("GetBackups", shardKsName)
if err != nil {
return nil, err
}
Expand All @@ -165,7 +165,7 @@ func (cluster LocalProcessCluster) RemoveAllBackups(t *testing.T, shardKsName st
backups, err := cluster.ListBackups(shardKsName)
require.Nil(t, err)
for _, backup := range backups {
cluster.VtctlclientProcess.ExecuteCommand("RemoveBackup", shardKsName, backup)
cluster.VtctldClientProcess.ExecuteCommand("RemoveBackup", shardKsName, backup)
}
}

Expand Down
76 changes: 76 additions & 0 deletions go/test/endtoend/cluster/vtctldclient_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"time"

"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/vterrors"
)

// VtctldClientProcess is a generic handle for a running vtctldclient command .
Expand Down Expand Up @@ -93,6 +94,55 @@ func VtctldClientProcessInstance(hostname string, grpcPort int, tmpDirectory str
return vtctldclient
}

type ApplySchemaParams struct {
DDLStrategy string
MigrationContext string
UUIDs string
CallerID string
BatchSize int
}

// ApplySchemaWithOutput applies SQL schema to the keyspace
func (vtctldclient *VtctldClientProcess) ApplySchemaWithOutput(keyspace string, sql string, params ApplySchemaParams) (result string, err error) {
args := []string{
"ApplySchema",
"--sql", sql,
}
if params.MigrationContext != "" {
args = append(args, "--migration-context", params.MigrationContext)
}
if params.DDLStrategy != "" {
args = append(args, "--ddl-strategy", params.DDLStrategy)
}
if params.UUIDs != "" {
args = append(args, "--uuid", params.UUIDs)
}
if params.BatchSize > 0 {
args = append(args, "--batch-size", fmt.Sprintf("%d", params.BatchSize))
}
if params.CallerID != "" {
args = append(args, "--caller-id", params.CallerID)
}
args = append(args, keyspace)
return vtctldclient.ExecuteCommandWithOutput(args...)
}

// ApplySchema applies SQL schema to the keyspace
func (vtctldclient *VtctldClientProcess) ApplySchema(keyspace string, sql string) error {
message, err := vtctldclient.ApplySchemaWithOutput(keyspace, sql, ApplySchemaParams{DDLStrategy: "direct -allow-zero-in-date"})

return vterrors.Wrap(err, message)
}

// ApplyVSchema applies vitess schema (JSON format) to the keyspace
func (vtctldclient *VtctldClientProcess) ApplyVSchema(keyspace string, json string) (err error) {
return vtctldclient.ExecuteCommand(
"ApplyVSchema",
"--vschema", json,
keyspace,
)
}

// PlannedReparentShard executes vtctlclient command to make specified tablet the primary for the shard.
func (vtctldclient *VtctldClientProcess) PlannedReparentShard(Keyspace string, Shard string, alias string) (err error) {
output, err := vtctldclient.ExecuteCommandWithOutput(
Expand All @@ -105,6 +155,32 @@ func (vtctldclient *VtctldClientProcess) PlannedReparentShard(Keyspace string, S
return err
}

// InitializeShard executes vtctldclient command to make specified tablet the primary for the shard.
func (vtctldclient *VtctldClientProcess) InitializeShard(keyspace string, shard string, cell string, uid int) error {
output, err := vtctldclient.ExecuteCommandWithOutput(
"PlannedReparentShard",
fmt.Sprintf("%s/%s", keyspace, shard),
"--wait-replicas-timeout", "31s",
"--new-primary", fmt.Sprintf("%s-%d", cell, uid))
if err != nil {
log.Errorf("error in PlannedReparentShard output %s, err %s", output, err.Error())
}
return err
}

// InitShardPrimary executes vtctldclient command to make specified tablet the primary for the shard.
func (vtctldclient *VtctldClientProcess) InitShardPrimary(keyspace string, shard string, cell string, uid int) error {
output, err := vtctldclient.ExecuteCommandWithOutput(
"InitShardPrimary",
"--force", "--wait-replicas-timeout", "31s",
fmt.Sprintf("%s/%s", keyspace, shard),
fmt.Sprintf("%s-%d", cell, uid))
if err != nil {
log.Errorf("error in InitShardPrimary output %s, err %s", output, err.Error())
}
return err
}

// CreateKeyspace executes the vtctl command to create a keyspace
func (vtctldclient *VtctldClientProcess) CreateKeyspace(keyspaceName string, sidecarDBName string) (err error) {
var output string
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/clustertest/vttablet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ func TestDeleteTablet(t *testing.T) {
defer cluster.PanicHandler(t)
primary := clusterInstance.Keyspaces[0].Shards[0].PrimaryTablet()
require.NotNil(t, primary)
_, err := clusterInstance.VtctlclientProcess.ExecuteCommandWithOutput("DeleteTablet", "--", "--allow_primary", primary.Alias)
_, err := clusterInstance.VtctldClientProcess.ExecuteCommandWithOutput("DeleteTablets", "--allow-primary", primary.Alias)
require.NoError(t, err)
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func testReplicationBase(t *testing.T, isClientCertPassed bool) {
}

// Reparent using SSL (this will also check replication works)
err = clusterInstance.VtctlclientProcess.InitializeShard(keyspace, shardName, clusterInstance.Cell, primaryTablet.TabletUID)
err = clusterInstance.VtctldClientProcess.InitializeShard(keyspace, shardName, clusterInstance.Cell, primaryTablet.TabletUID)
if isClientCertPassed {
require.NoError(t, err)
} else {
Expand Down
Loading
Loading