test: Introduce new protocols flavor property "client_error_exception_type".

This allows the tests to check for more specific exceptions and in turn fixes the pylint error that the "except" is too broad.
This commit is contained in:
Michael Berlin 2015-11-14 21:09:35 -08:00
Родитель 00cd50edab
Коммит bd711bf077
5 изменённых файлов: 26 добавлений и 9 удалений

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

@ -1,4 +1,7 @@
#!/usr/bin/env python
"""Defines which protocols to use for the Go (BSON) RPC flavor."""
from net import gorpc
import protocols_flavor
@ -39,6 +42,9 @@ class GoRpcProtocolsFlavor(protocols_flavor.ProtocolsFlavor):
def vtgate_python_protocol(self):
return 'gorpc'
def client_error_exception_type(self):
return gorpc.AppError
def rpc_timeout_message(self):
return 'context deadline exceeded'

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

@ -1,4 +1,7 @@
#!/usr/bin/env python
"""Defines which protocols to use for the gRPC flavor."""
from grpc.framework.interfaces.face import face
import protocols_flavor
@ -36,6 +39,9 @@ class GRpcProtocolsFlavor(protocols_flavor.ProtocolsFlavor):
def vtgate_python_protocol(self):
return 'gorpc'
def client_error_exception_type(self):
return face.RemoteError
def rpc_timeout_message(self):
return 'context deadline exceeded'

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

@ -56,6 +56,10 @@ class ProtocolsFlavor(object):
"""The protocol to use to talk to vtgate with python clients."""
raise NotImplementedError('Not implemented in the base class')
def client_error_exception_type(self):
"""The exception type the RPC client implementation returns for errors."""
raise NotImplementedError('Not implemented in the base class')
def rpc_timeout_message(self):
"""The error message used by the protocol to indicate a timeout."""
raise NotImplementedError('Not implemented in the base class')
@ -69,29 +73,29 @@ class ProtocolsFlavor(object):
raise NotImplementedError('Not implemented in the base class')
__knows_protocols_flavor_map = {}
__protocols_flavor = None
_knows_protocols_flavor_map = {}
_protocols_flavor = None
def protocols_flavor():
return __protocols_flavor
return _protocols_flavor
def set_protocols_flavor(flavor):
"""Set the protocols flavor by flavor name."""
global __protocols_flavor
global _protocols_flavor
if not flavor:
flavor = 'gorpc'
cls = __knows_protocols_flavor_map.get(flavor, None)
cls = _knows_protocols_flavor_map.get(flavor, None)
if not cls:
logging.error('Unknown protocols flavor %s', flavor)
exit(1)
__protocols_flavor = cls()
_protocols_flavor = cls()
logging.debug('Using protocols flavor %s', flavor)
def register_flavor(key, cls):
__knows_protocols_flavor_map[key] = cls
_knows_protocols_flavor_map[key] = cls

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

@ -391,7 +391,7 @@ class TestTabletManager(unittest.TestCase):
try:
utils.run_vtctl_json(['GetEndPoints', 'test_nj', 'test_keyspace/0',
'replica'])
except:
except protocols_flavor().client_error_exception_type():
logging.debug('Tablet is gone from serving graph, good')
break
timeout = utils.wait_step(

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

@ -11,6 +11,7 @@ import utils
from vtdb import dbexceptions
from vtdb import update_stream
from mysql_flavor import mysql_flavor
from protocols_flavor import protocols_flavor
master_tablet = tablet.Tablet()
replica_tablet = tablet.Tablet()
@ -102,7 +103,7 @@ def setUpModule():
master_tablet.execute('select count(1) from vt_insert_test')
replica_tablet.execute('select count(1) from vt_insert_test')
break
except:
except protocols_flavor().client_error_exception_type():
logging.exception('query failed')
timeout = utils.wait_step('slave tablet having correct schema', timeout)
# also re-run ReloadSchema on slave, it case the first one