Skip to content

Commit 86001dc

Browse files
committed
update topo flags in tests to support random notation assignment
Signed-off-by: mounicasruthi <[email protected]>
1 parent 909ba84 commit 86001dc

File tree

7 files changed

+138
-100
lines changed

7 files changed

+138
-100
lines changed

go/cmd/vttablet/cli/cli_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package cli
1818

1919
import (
2020
"context"
21-
"fmt"
21+
// "fmt"
2222
"os"
2323
"testing"
2424

@@ -45,13 +45,13 @@ func TestRunFailsToStartTabletManager(t *testing.T) {
4545
})
4646

4747
flags := make(map[string]string)
48-
utils.SetFlagVariantsForTests(flags, "topo-implementation", "test")
49-
utils.SetFlagVariantsForTests(flags, "topo-global-server-address", "localhost")
50-
utils.SetFlagVariantsForTests(flags, "topo-global-root", "cell")
48+
utils.SetFlagVariantsForTests(flags, "--topo-implementation", "test")
49+
utils.SetFlagVariantsForTests(flags, "--topo-global-server-address", "localhost")
50+
utils.SetFlagVariantsForTests(flags, "--topo-global-root", "cell")
5151

5252
var flagArgs []string
53-
for k, v := range flags {
54-
flagArgs = append(flagArgs, fmt.Sprintf("--%s=%s", k, v))
53+
for flag, value := range flags {
54+
flagArgs = append(flagArgs, flag, value)
5555
}
5656

5757
flagArgs = append(flagArgs,

go/test/endtoend/cluster/vtbackup_process.go

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,50 @@ type VtbackupProcess struct {
5656

5757
// Setup starts vtbackup process with required arguements
5858
func (vtbackup *VtbackupProcess) Setup() (err error) {
59-
flags := make(map[string]string)
59+
60+
flags := map[string]string{
61+
"--topo-implementation": vtbackup.TopoImplementation,
62+
"--topo-global-server-address": vtbackup.TopoGlobalAddress,
63+
"--topo-global-root": vtbackup.TopoGlobalRoot,
64+
"--log_dir": vtbackup.LogDir,
65+
66+
//initDBfile is required to run vtbackup
67+
"--mysql_port": fmt.Sprintf("%d", vtbackup.MysqlPort),
68+
"--init_db_sql_file": vtbackup.initDBfile,
69+
"--init_keyspace": vtbackup.Keyspace,
70+
"--init_shard": vtbackup.Shard,
71+
72+
//Backup Arguments are not optional
73+
"--backup_storage_implementation": vtbackup.BackupStorageImplementation,
74+
"--file_backup_storage_root": vtbackup.FileBackupStorageRoot,
75+
}
6076

6177
utils.SetFlagVariantsForTests(flags, "--topo-implementation", vtbackup.TopoImplementation)
6278
utils.SetFlagVariantsForTests(flags, "--topo-global-server-address", vtbackup.TopoGlobalAddress)
6379
utils.SetFlagVariantsForTests(flags, "--topo-global-root", vtbackup.TopoGlobalRoot)
6480

65-
vtbackup.proc = exec.Command(
66-
vtbackup.Binary,
67-
flags["--topo-implementation"],
68-
flags["--topo-global-server-address"],
69-
flags["--topo-global-root"],
70-
"--log_dir", vtbackup.LogDir,
71-
72-
//initDBfile is required to run vtbackup
73-
"--mysql_port", fmt.Sprintf("%d", vtbackup.MysqlPort),
74-
"--init_db_sql_file", vtbackup.initDBfile,
75-
"--init_keyspace", vtbackup.Keyspace,
76-
"--init_shard", vtbackup.Shard,
81+
vtbackup.proc = exec.Command(vtbackup.Binary)
82+
for k, v := range flags {
83+
vtbackup.proc.Args = append(vtbackup.proc.Args, k, v)
84+
}
7785

78-
//Backup Arguments are not optional
79-
"--backup_storage_implementation", vtbackup.BackupStorageImplementation,
80-
"--file_backup_storage_root", vtbackup.FileBackupStorageRoot,
81-
)
86+
// vtbackup.proc = exec.Command(
87+
// vtbackup.Binary,
88+
// "--topo-implementation", vtbackup.TopoImplementation,
89+
// "--topo-global-server-address", vtbackup.TopoGlobalAddress,
90+
// "--topo-global-root", vtbackup.TopoGlobalRoot,
91+
// "--log_dir", vtbackup.LogDir,
92+
93+
// //initDBfile is required to run vtbackup
94+
// "--mysql_port", fmt.Sprintf("%d", vtbackup.MysqlPort),
95+
// "--init_db_sql_file", vtbackup.initDBfile,
96+
// "--init_keyspace", vtbackup.Keyspace,
97+
// "--init_shard", vtbackup.Shard,
98+
99+
// //Backup Arguments are not optional
100+
// "--backup_storage_implementation", vtbackup.BackupStorageImplementation,
101+
// "--file_backup_storage_root", vtbackup.FileBackupStorageRoot,
102+
// )
82103

83104
if vtbackup.initialBackup {
84105
vtbackup.proc.Args = append(vtbackup.proc.Args, "--initial_backup")

go/test/endtoend/cluster/vtctld_process.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,27 +53,31 @@ func (vtctld *VtctldProcess) Setup(cell string, extraArgs ...string) (err error)
5353
_ = createDirectory(vtctld.LogDir, 0700)
5454
_ = createDirectory(path.Join(vtctld.Directory, "backups"), 0700)
5555

56-
flags := make(map[string]string)
56+
flags := map[string]string{
57+
"--topo-implementation": vtctld.TopoImplementation,
58+
"--topo-global-server-address": vtctld.TopoGlobalAddress,
59+
"--topo-global-root": vtctld.TopoGlobalRoot,
60+
"--cell": cell,
61+
"--service_map": vtctld.ServiceMap,
62+
"--backup_storage_implementation": vtctld.BackupStorageImplementation,
63+
"--file_backup_storage_root": vtctld.FileBackupStorageRoot,
64+
"--log_dir": vtctld.LogDir,
65+
"--port": fmt.Sprintf("%d", vtctld.Port),
66+
"--grpc_port": fmt.Sprintf("%d", vtctld.GrpcPort),
67+
"--bind-address": "127.0.0.1",
68+
"--grpc_bind_address": "127.0.0.1",
69+
}
5770

5871
utils.SetFlagVariantsForTests(flags, "--topo-implementation", vtctld.TopoImplementation)
5972
utils.SetFlagVariantsForTests(flags, "--topo-global-server-address", vtctld.TopoGlobalAddress)
6073
utils.SetFlagVariantsForTests(flags, "--topo-global-root", vtctld.TopoGlobalRoot)
6174

62-
vtctld.proc = exec.Command(
63-
vtctld.Binary,
64-
flags["--topo-implementation"],
65-
flags["--topo-global-server-address"],
66-
flags["--topo-global-root"],
67-
"--cell", cell,
68-
"--service_map", vtctld.ServiceMap,
69-
"--backup_storage_implementation", vtctld.BackupStorageImplementation,
70-
"--file_backup_storage_root", vtctld.FileBackupStorageRoot,
71-
"--log_dir", vtctld.LogDir,
72-
"--port", fmt.Sprintf("%d", vtctld.Port),
73-
"--grpc_port", fmt.Sprintf("%d", vtctld.GrpcPort),
74-
"--bind-address", "127.0.0.1",
75-
"--grpc_bind_address", "127.0.0.1",
76-
)
75+
args := []string{vtctld.Binary}
76+
for flag, value := range flags {
77+
args = append(args, flag, value)
78+
}
79+
80+
vtctld.proc = exec.Command(args[0], args[1:]...)
7781

7882
if *isCoverage {
7983
vtctld.proc.Args = append(vtctld.proc.Args, "--test.coverprofile="+getCoveragePath("vtctld.out"))

go/test/endtoend/cluster/vtgate_process.go

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -147,31 +147,36 @@ const defaultVtGatePlannerVersion = planbuilder.Gen4
147147

148148
// Setup starts Vtgate process with required arguements
149149
func (vtgate *VtgateProcess) Setup() (err error) {
150-
flags := make(map[string]string)
150+
151+
flags := map[string]string{
152+
"--topo-implementation": vtgate.TopoImplementation,
153+
"--topo-global-server-address": vtgate.TopoGlobalAddress,
154+
"--topo-global-root": vtgate.TopoGlobalRoot,
155+
"--config-file": vtgate.ConfigFile,
156+
"--log_dir": vtgate.LogDir,
157+
"--log_queries_to_file": vtgate.FileToLogQueries,
158+
"--port": fmt.Sprintf("%d", vtgate.Port),
159+
"--grpc_port": fmt.Sprintf("%d", vtgate.GrpcPort),
160+
"--mysql_server_port": fmt.Sprintf("%d", vtgate.MySQLServerPort),
161+
"--mysql_server_socket_path": vtgate.MySQLServerSocketPath,
162+
"--cell": vtgate.Cell,
163+
"--cells_to_watch": vtgate.CellsToWatch,
164+
"--tablet_types_to_wait": vtgate.TabletTypesToWait,
165+
"--service_map": vtgate.ServiceMap,
166+
"--mysql_auth_server_impl": vtgate.MySQLAuthServerImpl,
167+
"--bind-address": "127.0.0.1",
168+
"--grpc_bind_address": "127.0.0.1",
169+
}
151170

152171
utils.SetFlagVariantsForTests(flags, "--topo-implementation", vtgate.TopoImplementation)
153172
utils.SetFlagVariantsForTests(flags, "--topo-global-server-address", vtgate.TopoGlobalAddress)
154173
utils.SetFlagVariantsForTests(flags, "--topo-global-root", vtgate.TopoGlobalRoot)
155174

156-
args := []string{
157-
flags["--topo-implementation"],
158-
flags["--topo-global-server-address"],
159-
flags["--topo-global-root"],
160-
"--config-file", vtgate.ConfigFile,
161-
"--log_dir", vtgate.LogDir,
162-
"--log_queries_to_file", vtgate.FileToLogQueries,
163-
"--port", fmt.Sprintf("%d", vtgate.Port),
164-
"--grpc_port", fmt.Sprintf("%d", vtgate.GrpcPort),
165-
"--mysql_server_port", fmt.Sprintf("%d", vtgate.MySQLServerPort),
166-
"--mysql_server_socket_path", vtgate.MySQLServerSocketPath,
167-
"--cell", vtgate.Cell,
168-
"--cells_to_watch", vtgate.CellsToWatch,
169-
"--tablet_types_to_wait", vtgate.TabletTypesToWait,
170-
"--service_map", vtgate.ServiceMap,
171-
"--mysql_auth_server_impl", vtgate.MySQLAuthServerImpl,
172-
"--bind-address", "127.0.0.1",
173-
"--grpc_bind_address", "127.0.0.1",
175+
args := []string{}
176+
for flag, value := range flags {
177+
args = append(args, flag, value)
174178
}
179+
175180
// If no explicit mysql_server_version has been specified then we autodetect
176181
// the MySQL version that will be used for the test and base the vtgate's
177182
// mysql server version on that.

go/test/endtoend/cluster/vtorc_process.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,24 @@ func (orc *VTOrcProcess) Setup() (err error) {
116116
$ vtorc --topo-implementation etcd2 --topo-global-server-address localhost:2379 --topo-global-root /vitess/global
117117
--config config/vtorc/default.json --alsologtostderr
118118
*/
119-
flags := make(map[string]string)
119+
flags := map[string]string{
120+
"--topo-implementation": orc.TopoImplementation,
121+
"--topo-global-server-address": orc.TopoGlobalAddress,
122+
"--topo-global-root": orc.TopoGlobalRoot,
123+
"--config-file": orc.ConfigPath,
124+
"--port": fmt.Sprintf("%d", orc.Port),
125+
"--bind-address": "127.0.0.1",
126+
}
120127

121128
utils.SetFlagVariantsForTests(flags, "--topo-implementation", orc.TopoImplementation)
122129
utils.SetFlagVariantsForTests(flags, "--topo-global-server-address", orc.TopoGlobalAddress)
123130
utils.SetFlagVariantsForTests(flags, "--topo-global-root", orc.TopoGlobalRoot)
124131

125-
orc.proc = exec.Command(
126-
orc.Binary,
127-
flags["--topo-implementation"],
128-
flags["--topo-global-server-address"],
129-
flags["--topo-global-root"],
130-
"--config-file", orc.ConfigPath,
131-
"--port", fmt.Sprintf("%d", orc.Port),
132-
"--bind-address", "127.0.0.1",
133-
)
132+
orc.proc = exec.Command(orc.Binary)
133+
for flag, value := range flags {
134+
orc.proc.Args = append(orc.proc.Args, flag, value)
135+
}
136+
134137
if !orc.NoOverride {
135138
orc.proc.Args = append(orc.proc.Args,
136139
// This parameter is overriden from the config file. This verifies that we indeed use the flag value over the config file.

go/test/endtoend/cluster/vttablet_process.go

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -93,35 +93,37 @@ type VttabletProcess struct {
9393

9494
// Setup starts vttablet process with required arguements
9595
func (vttablet *VttabletProcess) Setup() (err error) {
96-
flags := make(map[string]string)
96+
97+
flags := map[string]string{
98+
"--topo-implementation": vttablet.TopoImplementation,
99+
"--topo-global-server-address": vttablet.TopoGlobalAddress,
100+
"--topo-global-root": vttablet.TopoGlobalRoot,
101+
"--log_queries_to_file": vttablet.FileToLogQueries,
102+
"--tablet-path": vttablet.TabletPath,
103+
"--port": fmt.Sprintf("%d", vttablet.Port),
104+
"--grpc_port": fmt.Sprintf("%d", vttablet.GrpcPort),
105+
"--init_shard": vttablet.Shard,
106+
"--log_dir": vttablet.LogDir,
107+
"--tablet_hostname": vttablet.TabletHostname,
108+
"--init_keyspace": vttablet.Keyspace,
109+
"--init_tablet_type": vttablet.TabletType,
110+
"--health_check_interval": fmt.Sprintf("%ds", vttablet.HealthCheckInterval),
111+
"--backup_storage_implementation": vttablet.BackupStorageImplementation,
112+
"--file_backup_storage_root": vttablet.FileBackupStorageRoot,
113+
"--service_map": vttablet.ServiceMap,
114+
"--db_charset": vttablet.Charset,
115+
"--bind-address": "127.0.0.1",
116+
"--grpc_bind_address": "127.0.0.1",
117+
}
97118

98119
utils.SetFlagVariantsForTests(flags, "--topo-implementation", vttablet.TopoImplementation)
99120
utils.SetFlagVariantsForTests(flags, "--topo-global-server-address", vttablet.TopoGlobalAddress)
100121
utils.SetFlagVariantsForTests(flags, "--topo-global-root", vttablet.TopoGlobalRoot)
101122

102-
vttablet.proc = exec.Command(
103-
vttablet.Binary,
104-
flags["--topo-implementation"],
105-
flags["--topo-global-server-address"],
106-
flags["--topo-global-root"],
107-
"--log_queries_to_file", vttablet.FileToLogQueries,
108-
"--tablet-path", vttablet.TabletPath,
109-
"--port", fmt.Sprintf("%d", vttablet.Port),
110-
"--grpc_port", fmt.Sprintf("%d", vttablet.GrpcPort),
111-
"--init_shard", vttablet.Shard,
112-
"--log_dir", vttablet.LogDir,
113-
"--tablet_hostname", vttablet.TabletHostname,
114-
"--init_keyspace", vttablet.Keyspace,
115-
"--init_tablet_type", vttablet.TabletType,
116-
"--health_check_interval", fmt.Sprintf("%ds", vttablet.HealthCheckInterval),
117-
"--enable_replication_reporter",
118-
"--backup_storage_implementation", vttablet.BackupStorageImplementation,
119-
"--file_backup_storage_root", vttablet.FileBackupStorageRoot,
120-
"--service_map", vttablet.ServiceMap,
121-
"--db_charset", vttablet.Charset,
122-
"--bind-address", "127.0.0.1",
123-
"--grpc_bind_address", "127.0.0.1",
124-
)
123+
vttablet.proc = exec.Command(vttablet.Binary, "--enable_replication_reporter")
124+
for flag, value := range flags {
125+
vttablet.proc.Args = append(vttablet.proc.Args, flag, value)
126+
}
125127

126128
if *isCoverage {
127129
vttablet.proc.Args = append(vttablet.proc.Args, "--test.coverprofile="+getCoveragePath("vttablet.out"))

go/test/endtoend/vtorc/readtopologyinstance/main_test.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"vitess.io/vitess/go/test/endtoend/cluster"
2626
"vitess.io/vitess/go/test/endtoend/vtorc/utils"
2727
"vitess.io/vitess/go/vt/servenv"
28+
2829
vtutils "vitess.io/vitess/go/vt/utils"
2930
"vitess.io/vitess/go/vt/vtorc/config"
3031
"vitess.io/vitess/go/vt/vtorc/inst"
@@ -50,16 +51,18 @@ func TestReadTopologyInstanceBufferable(t *testing.T) {
5051
}()
5152

5253
// Change the args such that they match how we would invoke VTOrc
53-
os.Args = []string{"vtorc"}
54-
55-
flags := make(map[string]string)
54+
args := map[string]string{
55+
"--topo-global-server-address": clusterInfo.ClusterInstance.VtctldClientProcess.TopoGlobalAddress,
56+
"--topo-implementation": clusterInfo.ClusterInstance.VtctldClientProcess.TopoImplementation,
57+
"--topo-global-root": clusterInfo.ClusterInstance.VtctldClientProcess.TopoGlobalRoot,
58+
}
5659

57-
vtutils.SetFlagVariantsForTests(flags, "topo-global-server-address", clusterInfo.ClusterInstance.VtctldClientProcess.TopoGlobalAddress)
58-
vtutils.SetFlagVariantsForTests(flags, "topo-implementation", clusterInfo.ClusterInstance.VtctldClientProcess.TopoImplementation)
59-
vtutils.SetFlagVariantsForTests(flags, "topo-global-root", clusterInfo.ClusterInstance.VtctldClientProcess.TopoGlobalRoot)
60+
vtutils.SetFlagVariantsForTests(args, "--topo-global-server-address", clusterInfo.ClusterInstance.VtctldClientProcess.TopoGlobalAddress)
61+
vtutils.SetFlagVariantsForTests(args, "--topo-implementation", clusterInfo.ClusterInstance.VtctldClientProcess.TopoImplementation)
62+
vtutils.SetFlagVariantsForTests(args, "--topo-global-root", clusterInfo.ClusterInstance.VtctldClientProcess.TopoGlobalRoot)
6063

61-
for k, v := range flags {
62-
fmt.Printf("Flag: %s, Value: %s\n", k, v)
64+
os.Args = []string{"vtorc"}
65+
for k, v := range args {
6366
os.Args = append(os.Args, k, v)
6467
}
6568

0 commit comments

Comments
 (0)