Skip to content

Commit

Permalink
Merge pull request #1768 from alainjobart/vttest
Browse files Browse the repository at this point in the history
Deprecating --topology in run_local_database.py.
  • Loading branch information
alainjobart committed Jun 7, 2016
2 parents 09aa64d + 85912f0 commit 9447953
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 52 deletions.
15 changes: 14 additions & 1 deletion examples/demo/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
from CGIHTTPServer import CGIHTTPRequestHandler
from BaseHTTPServer import HTTPServer

from google.protobuf import text_format

from vtproto import vttest_pb2


def start_http_server(port):
httpd = HTTPServer(('', port), CGIHTTPRequestHandler)
Expand All @@ -29,10 +33,19 @@ def start_http_server(port):

def start_vitess():
"""This is the main start function."""

topology = vttest_pb2.VTTestTopology()
keyspace = topology.keyspaces.add(name='user')
keyspace.shards.add(name='-80')
keyspace.shards.add(name='80-')
keyspace = topology.keyspaces.add(name='lookup')
keyspace.shards.add(name='0')

vttop = os.environ['VTTOP']
args = [os.path.join(vttop, 'py/vttest/run_local_database.py'),
'--port', '12345',
'--topology', 'user/-80:user0,user/80-:user1,lookup/0:lookup',
'--proto_topo', text_format.MessageToString(topology,
as_one_line=True),
'--web_dir', os.path.join(vttop, 'web/vtctld'),
'--schema_dir', os.path.join(vttop, 'examples/demo/schema'),
'--vschema', os.path.join(vttop, 'examples/demo/schema/vschema.json')]
Expand Down
36 changes: 19 additions & 17 deletions go/vt/vttest/local_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,6 @@ func SchemaDirectory(dir string) VitessOption {
}
}

// Topology is used to pass in the topology string.
// It cannot be used at the same time as MySQLOnly.
//
// DEPRECATED. Please use ProtoTopo that allows the specification of a
// lot more options.
func Topology(topo string) VitessOption {
return VitessOption{
beforeRun: func(hdl *Handle) error {
hdl.cmd.Args = append(hdl.cmd.Args, "--topology", topo)
return nil
},
}
}

// ProtoTopo is used to pass in the topology as a vttest proto definition.
// See vttest.proto for more information.
// It cannot be used at the same time as MySQLOnly.
Expand All @@ -102,14 +88,30 @@ func ProtoTopo(topo *vttestpb.VTTestTopology) VitessOption {

// MySQLOnly is used to launch only a mysqld instance, with the specified db name.
// Use it before Schema option.
// It cannot be used at the same as Topology.
// It cannot be used at the same as ProtoTopo.
func MySQLOnly(dbName string) VitessOption {
return VitessOption{
beforeRun: func(hdl *Handle) error {
// the way to pass the dbname for creation in
// is to provide a topology
topo := &vttestpb.VTTestTopology{
Keyspaces: []*vttestpb.Keyspace{
{
Name: dbName,
Shards: []*vttestpb.Shard{
{
Name: "0",
DbNameOverride: dbName,
},
},
},
},
}

hdl.dbname = dbName
hdl.cmd.Args = append(hdl.cmd.Args,
"--topology", fmt.Sprintf("%s/0:%s", dbName, dbName),
"--mysql_only")
"--mysql_only",
"--proto_topo", proto.CompactTextString(topo))
return nil
},
}
Expand Down
8 changes: 8 additions & 0 deletions proto/vttest.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
// and then use the protobuf library to encode it as text.
// For an example in Python, see: test/vttest_sample_test.py
// In go, see: go/vt/vttest/local_cluster_test.go
//
// Sample encoded proto configurations would be as follow. Note there are
// multiple encoding options, see the proto documentation for more info
// (first and last quote not included in the encoding):
// - single keyspace named test_keyspace with one shard '0':
// 'keyspaces:<name:"test_keyspace" shards:<name:"0" > > '
// - two keyspaces, one with two shards, the other one with a redirect:
// 'keyspaces { name: "test_keyspace" shards { name: "-80" } shards { name: "80-" } } keyspaces { name: "redirect" served_from: "test_keyspace" }'

syntax = "proto3";

Expand Down
36 changes: 2 additions & 34 deletions py/vttest/run_local_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import logging
import optparse
import os
import re
import sys

from google.protobuf import text_format
Expand All @@ -33,35 +32,11 @@

from vtproto import vttest_pb2

shard_exp = re.compile(r'(.+)/(.+):(.+)')


def main(cmdline_options):
topology = vttest_pb2.VTTestTopology()

if cmdline_options.topology:
# old style topology, will disappear soon. Build a new style
# topology from it.
keyspaces = {}

for shard in cmdline_options.topology.split(','):
m = shard_exp.match(shard)
if not m:
sys.stderr.write('invalid --shard flag format: %s\n' % shard)
sys.exit(1)

keyspace = m.group(1)
shard_name = m.group(2)
db_name = m.group(3)

if keyspace not in keyspaces:
kpb = topology.keyspaces.add(name=keyspace)
keyspaces[keyspace] = kpb

keyspaces[keyspace].shards.add(name=shard_name, db_name_override=db_name)

elif cmdline_options.proto_topo:
# new style topology, just parse it as text
if cmdline_options.proto_topo:
# Text-encoded proto topology object, just parse it.
topology = text_format.Parse(cmdline_options.proto_topo, topology)

environment.base_port = cmdline_options.port
Expand Down Expand Up @@ -100,13 +75,6 @@ def main(cmdline_options):
'-p', '--port', type='int',
help='Port to use for vtcombo. If this is 0, a random port '
'will be chosen.')
parser.add_option(
'-t', '--topology',
help='DEPRECATED, use proto_topo instead.'
' Define which shards exist in the test topology in the'
' form <keyspace>/<shardrange>:<dbname>,... The dbname'
' must be unique among all shards, since they share'
' a MySQL instance in the test environment.')
parser.add_option(
'-o', '--proto_topo',
help='Define the fake cluster topology as a compact text format encoded'
Expand Down

0 comments on commit 9447953

Please sign in to comment.