Skip to content

Commit

Permalink
Move used until functions from initialsharding to cluster
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Jul 3, 2022
1 parent ee4db48 commit 1fae23b
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 176 deletions.
50 changes: 0 additions & 50 deletions .github/workflows/cluster_initial_sharding_multi.yml

This file was deleted.

5 changes: 2 additions & 3 deletions go/test/endtoend/backup/transform/backup_transform_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/stretchr/testify/require"

"vitess.io/vitess/go/test/endtoend/cluster"
"vitess.io/vitess/go/test/endtoend/sharding/initialsharding"
"vitess.io/vitess/go/vt/log"
)

Expand Down Expand Up @@ -87,11 +86,11 @@ func TestMainSetup(m *testing.M, useMysqlctld bool) {
}
shard := &localCluster.Keyspaces[0].Shards[0]
// changing password for mysql user
dbCredentialFile = initialsharding.WriteDbCredentialToTmp(localCluster.TmpDirectory)
dbCredentialFile = cluster.WriteDbCredentialToTmp(localCluster.TmpDirectory)
initDb, _ := os.ReadFile(path.Join(os.Getenv("VTROOT"), "/config/init_db.sql"))
sql := string(initDb)
newInitDBFile = path.Join(localCluster.TmpDirectory, "init_db_with_passwords.sql")
sql = sql + initialsharding.GetPasswordUpdateSQL(localCluster)
sql = sql + cluster.GetPasswordUpdateSQL(localCluster)
os.WriteFile(newInitDBFile, []byte(sql), 0666)

extraArgs := []string{"--db-credentials-file", dbCredentialFile}
Expand Down
5 changes: 2 additions & 3 deletions go/test/endtoend/backup/vtbackup/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"testing"

"vitess.io/vitess/go/test/endtoend/cluster"
"vitess.io/vitess/go/test/endtoend/sharding/initialsharding"
"vitess.io/vitess/go/vt/log"
)

Expand Down Expand Up @@ -87,11 +86,11 @@ func TestMain(m *testing.M) {

// Create a new init_db.sql file that sets up passwords for all users.
// Then we use a db-credentials-file with the passwords.
dbCredentialFile = initialsharding.WriteDbCredentialToTmp(localCluster.TmpDirectory)
dbCredentialFile = cluster.WriteDbCredentialToTmp(localCluster.TmpDirectory)
initDb, _ := os.ReadFile(path.Join(os.Getenv("VTROOT"), "/config/init_db.sql"))
sql := string(initDb)
newInitDBFile = path.Join(localCluster.TmpDirectory, "init_db_with_passwords.sql")
sql = sql + initialsharding.GetPasswordUpdateSQL(localCluster)
sql = sql + cluster.GetPasswordUpdateSQL(localCluster)
err = os.WriteFile(newInitDBFile, []byte(sql), 0666)
if err != nil {
return 1, err
Expand Down
5 changes: 2 additions & 3 deletions go/test/endtoend/backup/vtctlbackup/backup_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/stretchr/testify/require"

"vitess.io/vitess/go/test/endtoend/cluster"
"vitess.io/vitess/go/test/endtoend/sharding/initialsharding"
)

// constants for test variants
Expand Down Expand Up @@ -102,11 +101,11 @@ func LaunchCluster(setupType int, streamMode string, stripes int) (int, error) {
}
shard := &localCluster.Keyspaces[0].Shards[0]

dbCredentialFile = initialsharding.WriteDbCredentialToTmp(localCluster.TmpDirectory)
dbCredentialFile = cluster.WriteDbCredentialToTmp(localCluster.TmpDirectory)
initDb, _ := os.ReadFile(path.Join(os.Getenv("VTROOT"), "/config/init_db.sql"))
sql := string(initDb)
newInitDBFile = path.Join(localCluster.TmpDirectory, "init_db_with_passwords.sql")
sql = sql + initialsharding.GetPasswordUpdateSQL(localCluster)
sql = sql + cluster.GetPasswordUpdateSQL(localCluster)
err = os.WriteFile(newInitDBFile, []byte(sql), 0666)
if err != nil {
return 1, err
Expand Down
62 changes: 61 additions & 1 deletion go/test/endtoend/cluster/cluster_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"
"os"
"path"
"strings"
"testing"
"time"
Expand All @@ -37,7 +38,8 @@ import (
)

var (
tmClient = tmc.NewClient()
tmClient = tmc.NewClient()
dbCredentialFile string
)

// Restart restarts vttablet and mysql.
Expand Down Expand Up @@ -292,3 +294,61 @@ func filterDoubleDashArgs(args []string, version int) (filtered []string) {

return filtered
}

// WriteDbCredentialToTmp writes json format db credentials to tmp directory
func WriteDbCredentialToTmp(tmpDir string) string {
data := []byte(`{
"vt_dba": ["VtDbaPass"],
"vt_app": ["VtAppPass"],
"vt_allprivs": ["VtAllprivsPass"],
"vt_repl": ["VtReplPass"],
"vt_filtered": ["VtFilteredPass"]
}`)
dbCredentialFile = path.Join(tmpDir, "db_credentials.json")
os.WriteFile(dbCredentialFile, data, 0666)
return dbCredentialFile
}

// GetPasswordUpdateSQL returns the sql for password update
func GetPasswordUpdateSQL(localCluster *LocalProcessCluster) string {
pwdChangeCmd := `
# Set real passwords for all users.
UPDATE mysql.user SET %s = PASSWORD('RootPass')
WHERE User = 'root' AND Host = 'localhost';
UPDATE mysql.user SET %s = PASSWORD('VtDbaPass')
WHERE User = 'vt_dba' AND Host = 'localhost';
UPDATE mysql.user SET %s = PASSWORD('VtAppPass')
WHERE User = 'vt_app' AND Host = 'localhost';
UPDATE mysql.user SET %s = PASSWORD('VtAllprivsPass')
WHERE User = 'vt_allprivs' AND Host = 'localhost';
UPDATE mysql.user SET %s = PASSWORD('VtReplPass')
WHERE User = 'vt_repl' AND Host = '%%';
UPDATE mysql.user SET %s = PASSWORD('VtFilteredPass')
WHERE User = 'vt_filtered' AND Host = 'localhost';
FLUSH PRIVILEGES;
`
pwdCol, _ := getPasswordField(localCluster)
return fmt.Sprintf(pwdChangeCmd, pwdCol, pwdCol, pwdCol, pwdCol, pwdCol, pwdCol)
}

// getPasswordField Determines which column is used for user passwords in this MySQL version.
func getPasswordField(localCluster *LocalProcessCluster) (pwdCol string, err error) {
tablet := &Vttablet{
Type: "relpica",
TabletUID: 100,
MySQLPort: 15000,
MysqlctlProcess: *MysqlCtlProcessInstance(100, 15000, localCluster.TmpDirectory),
}
if err = tablet.MysqlctlProcess.Start(); err != nil {
return "", err
}
tablet.VttabletProcess = VttabletProcessInstance(tablet.HTTPPort, tablet.GrpcPort, tablet.TabletUID, "", "", "", 0, tablet.Type, localCluster.TopoPort, "", "", nil, false, localCluster.DefaultCharset)
result, err := tablet.VttabletProcess.QueryTablet("select password from mysql.user limit 0", "", false)
if err == nil && len(result.Rows) > 0 {
return "password", nil
}
tablet.MysqlctlProcess.Stop()
os.RemoveAll(path.Join(tablet.VttabletProcess.Directory))
return "authentication_string", nil

}
5 changes: 2 additions & 3 deletions go/test/endtoend/recovery/unshardedrecovery/recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (

"vitess.io/vitess/go/test/endtoend/cluster"
"vitess.io/vitess/go/test/endtoend/recovery"
"vitess.io/vitess/go/test/endtoend/sharding/initialsharding"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/vtgate/vtgateconn"
)
Expand Down Expand Up @@ -92,11 +91,11 @@ func TestMainImpl(m *testing.M) {
}
localCluster.Keyspaces = append(localCluster.Keyspaces, *keyspace)

dbCredentialFile = initialsharding.WriteDbCredentialToTmp(localCluster.TmpDirectory)
dbCredentialFile = cluster.WriteDbCredentialToTmp(localCluster.TmpDirectory)
initDb, _ := os.ReadFile(path.Join(os.Getenv("VTROOT"), "/config/init_db.sql"))
sql := string(initDb)
newInitDBFile = path.Join(localCluster.TmpDirectory, "init_db_with_passwords.sql")
sql = sql + initialsharding.GetPasswordUpdateSQL(localCluster)
sql = sql + cluster.GetPasswordUpdateSQL(localCluster)
// https://github.com/vitessio/vitess/issues/8315
oldAlterTableMode := `
SET GLOBAL old_alter_table = ON;
Expand Down
2 changes: 0 additions & 2 deletions test/ci_workflow_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ var (
"vtgate_queries",
"vtgate_schema_tracker",
"xb_recovery",
"resharding",
"resharding_bytes",
"mysql80",
"vreplication_across_db_versions",
"vreplication_multicell",
Expand Down
40 changes: 0 additions & 40 deletions test/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,24 +228,6 @@
"RetryMax": 1,
"Tags": []
},
"initial_sharding_bytes": {
"File": "unused.go",
"Args": ["vitess.io/vitess/go/test/endtoend/sharding/initialsharding/bytes"],
"Command": [],
"Manual": false,
"Shard": "13",
"RetryMax": 1,
"Tags": []
},
"initial_sharding_multi": {
"File": "unused.go",
"Args": ["vitess.io/vitess/go/test/endtoend/sharding/initialsharding/multi"],
"Command": [],
"Manual": false,
"Shard": "",
"RetryMax": 3,
"Tags": []
},
"keyspace": {
"File": "unused.go",
"Args": ["vitess.io/vitess/go/test/endtoend/keyspace"],
Expand All @@ -257,28 +239,6 @@
"site_test"
]
},
"merge_sharding": {
"File": "unused.go",
"Args": ["vitess.io/vitess/go/test/endtoend/sharding/mergesharding/int"],
"Command": [],
"Manual": false,
"Shard": "22",
"RetryMax": 2,
"Tags": [
"worker_test"
]
},
"merge_sharding_bytes": {
"File": "unused.go",
"Args": ["vitess.io/vitess/go/test/endtoend/sharding/mergesharding/string"],
"Command": [],
"Manual": false,
"Shard": "22",
"RetryMax": 1,
"Tags": [
"worker_test"
]
},
"mysqlctl": {
"File": "unused.go",
"Args": ["vitess.io/vitess/go/test/endtoend/mysqlctl"],
Expand Down
71 changes: 0 additions & 71 deletions test/legacy_local_example.sh

This file was deleted.

0 comments on commit 1fae23b

Please sign in to comment.