Adding integration test support for grpc.

Only supported for vtctl client protocol for now.
This commit is contained in:
Alain Jobart 2015-02-27 14:24:04 -08:00
Родитель 69eaae951c
Коммит ed9a25393d
3 изменённых файлов: 35 добавлений и 3 удалений

Просмотреть файл

@ -44,8 +44,28 @@ class GoRpcProtocolsFlavor(ProtocolsFlavor):
def rpc_timeout_message(self): def rpc_timeout_message(self):
return 'timeout waiting for' return 'timeout waiting for'
class GRpcProtocolsFlavor(ProtocolsFlavor):
"""Overrides to use gRPC everywhere where it is supported.
If not supported yet, use GoRPC."""
def binlog_player_protocol_flags(self):
return ['-binlog_player_protocol', 'gorpc']
def vtctl_client_protocol(self):
return 'grpc'
def tablet_manager_protocol_flags(self):
return ['-tablet_manager_protocol', 'bson']
def tabletconn_protocol_flags(self):
return ['-tablet_protocol', 'gorpc']
def rpc_timeout_message(self):
return 'timeout waiting for'
__knows_protocols_flavor_map = { __knows_protocols_flavor_map = {
'gorpc': GoRpcProtocolsFlavor, 'gorpc': GoRpcProtocolsFlavor,
'grpc': GRpcProtocolsFlavor,
} }
__protocols_flavor = None __protocols_flavor = None

Просмотреть файл

@ -677,6 +677,8 @@ class Vtctld(object):
def __init__(self): def __init__(self):
self.port = environment.reserve_ports(1) self.port = environment.reserve_ports(1)
if protocols_flavor().vtctl_client_protocol() == "grpc":
self.grpc_port = environment.reserve_ports(1)
def dbtopo(self): def dbtopo(self):
data = json.load(urllib2.urlopen('http://localhost:%u/dbtopo?format=json' % data = json.load(urllib2.urlopen('http://localhost:%u/dbtopo?format=json' %
@ -700,6 +702,9 @@ class Vtctld(object):
] + \ ] + \
environment.topo_server().flags() + \ environment.topo_server().flags() + \
protocols_flavor().tablet_manager_protocol_flags() protocols_flavor().tablet_manager_protocol_flags()
if protocols_flavor().vtctl_client_protocol() == "grpc":
args += ['-grpc_port', str(self.grpc_port),
'-service_map', 'grpc-vtctl']
stderr_fd = open(os.path.join(environment.tmproot, "vtctld.stderr"), "w") stderr_fd = open(os.path.join(environment.tmproot, "vtctld.stderr"), "w")
self.proc = run_bg(args, stderr=stderr_fd) self.proc = run_bg(args, stderr=stderr_fd)
@ -713,11 +718,15 @@ class Vtctld(object):
sleep_time=0.2) sleep_time=0.2)
# save the running instance so vtctl commands can be remote executed now # save the running instance so vtctl commands can be remote executed now
protocol = protocols_flavor().vtctl_client_protocol()
# temporary protocol override until python client support works
if protocol == "grpc":
protocol = "gorpc"
global vtctld, vtctld_connection global vtctld, vtctld_connection
if not vtctld: if not vtctld:
vtctld = self vtctld = self
vtctld_connection = vtctl_client.connect( vtctld_connection = vtctl_client.connect(
protocols_flavor().vtctl_client_protocol(), 'localhost:%u' % self.port, 30) protocol, 'localhost:%u' % self.port, 30)
return self.proc return self.proc
@ -732,10 +741,13 @@ class Vtctld(object):
else: else:
log_level='ERROR' log_level='ERROR'
port = self.port
if protocols_flavor().vtctl_client_protocol() == 'grpc':
port = self.grpc_port
out, err = run(environment.binary_args('vtctlclient') + out, err = run(environment.binary_args('vtctlclient') +
['-vtctl_client_protocol', ['-vtctl_client_protocol',
protocols_flavor().vtctl_client_protocol(), protocols_flavor().vtctl_client_protocol(),
'-server', 'localhost:%u' % self.port, '-server', 'localhost:%u' % port,
'-stderrthreshold', log_level] + args, '-stderrthreshold', log_level] + args,
trap_output=True) trap_output=True)
return out return out

Просмотреть файл

@ -142,7 +142,7 @@ class TestVtctld(unittest.TestCase):
def test_vtctl(self): def test_vtctl(self):
# standalone RPC client to vtctld # standalone RPC client to vtctld
out, err = utils.run_vtctl(['ListAllTablets', 'test_nj'], out, err = utils.run_vtctl(['ListAllTablets', 'test_nj'],
mode=utils.VTCTL_RPC) mode=utils.VTCTL_VTCTLCLIENT)
self._check_all_tablets(out) self._check_all_tablets(out)
# vtctl querying the topology directly # vtctl querying the topology directly