Skip to content
Merged

Lint2 #1061

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion py/vtdb/db_object_range_sharded.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ def update_sharding_key_entity_id_lookup(class_, cursor_method,
entity_id_lookup_column,
new_entity_id)


@db_object.write_db_class_method
def insert_primary(class_, cursor, **bind_vars):
if class_.columns_list is None:
Expand Down
3 changes: 2 additions & 1 deletion py/vtdb/field_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from decimal import Decimal
from vtdb import times

# These numbers should exactly match values defined in dist/mysql-5.1.52/include/mysql/mysql_com.h
# These numbers should exactly match values defined in
# dist/mysql-5.1.52/include/mysql/mysql_com.h
VT_DECIMAL = 0
VT_TINY = 1
VT_SHORT = 2
Expand Down
6 changes: 5 additions & 1 deletion py/vtdb/sql_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ class OrExprs(SQLOperator):

"col BETWEEN 10 AND 20 OR col = 30".
"""

def __init__(self, *values):
"""Initialize with multiple BaseWhereExprs or literal values.

Expand All @@ -768,6 +769,9 @@ def __init__(self, *values):

Args:
*values: List of 2 or more BaseWhereExprs or literals.

Raises:
ValueError: On bad input.
"""
if len(values) < 2:
raise ValueError('Two or more arguments expected.')
Expand Down Expand Up @@ -962,7 +966,7 @@ def __init__(self, prev_value_pairs, asc=True, inclusive=False):

Args:
prev_value_pairs: Ordered list of (column, prev_value) pairs.
Example: [('x', 3), ('y', 5), ('z', 7)].
Example - [('x', 3), ('y', 5), ('z', 7)].
asc: If True, scan forward.
inclusive: If True, also include starting point.
"""
Expand Down
56 changes: 28 additions & 28 deletions py/vtdb/tablet.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ def begin(self):
if self.transaction_id:
raise dbexceptions.NotSupportedError('Nested transactions not supported')
req = {
'ImmediateCallerID': {'Username': self.caller_id},
'SessionId': self.session_id
'ImmediateCallerID': {'Username': self.caller_id},
'SessionId': self.session_id
}
try:
response = self.rpc_call_and_extract_error('SqlQuery.Begin2', req)
Expand All @@ -147,9 +147,9 @@ def commit(self):
return

req = {
'ImmediateCallerID': {'Username': self.caller_id},
'TransactionId': self.transaction_id,
'SessionId': self.session_id
'ImmediateCallerID': {'Username': self.caller_id},
'TransactionId': self.transaction_id,
'SessionId': self.session_id
}

# NOTE(msolomon) Unset the transaction_id irrespective of the RPC's
Expand All @@ -170,9 +170,9 @@ def rollback(self):
return

req = {
'ImmediateCallerID': {'Username': self.caller_id},
'TransactionId': self.transaction_id,
'SessionId': self.session_id
'ImmediateCallerID': {'Username': self.caller_id},
'TransactionId': self.transaction_id,
'SessionId': self.session_id
}

# NOTE(msolomon) Unset the transaction_id irrespective of the RPC. If the
Expand Down Expand Up @@ -214,13 +214,13 @@ def rpc_call_and_extract_error(self, method_name, request):

def _execute(self, sql, bind_variables):
req = {
'QueryRequest': {
'Sql': sql,
'BindVariables': field_types.convert_bind_vars(bind_variables),
'SessionId': self.session_id,
'TransactionId': self.transaction_id
},
'ImmediateCallerID': {'Username': self.caller_id}
'QueryRequest': {
'Sql': sql,
'BindVariables': field_types.convert_bind_vars(bind_variables),
'SessionId': self.session_id,
'TransactionId': self.transaction_id
},
'ImmediateCallerID': {'Username': self.caller_id}
}

fields = []
Expand Down Expand Up @@ -259,13 +259,13 @@ def _execute_batch(self, sql_list, bind_variables_list, as_transaction):

try:
req = {
'QueryBatch': {
'Queries': query_list,
'SessionId': self.session_id,
'AsTransaction': as_transaction,
'TransactionId': self.transaction_id
'QueryBatch': {
'Queries': query_list,
'SessionId': self.session_id,
'AsTransaction': as_transaction,
'TransactionId': self.transaction_id
},
'ImmediateCallerID': {'Username': self.caller_id}
'ImmediateCallerID': {'Username': self.caller_id}
}

response = self.rpc_call_and_extract_error('SqlQuery.ExecuteBatch2', req)
Expand Down Expand Up @@ -298,13 +298,13 @@ def _execute_batch(self, sql_list, bind_variables_list, as_transaction):
# (that way we avoid using a member variable here for such a corner case)
def _stream_execute(self, sql, bind_variables):
req = {
'Query': {
'Sql': sql,
'BindVariables': field_types.convert_bind_vars(bind_variables),
'SessionId': self.session_id,
'TransactionId': self.transaction_id
},
'ImmediateCallerID': {'Username': self.caller_id}
'Query': {
'Sql': sql,
'BindVariables': field_types.convert_bind_vars(bind_variables),
'SessionId': self.session_id,
'TransactionId': self.transaction_id
},
'ImmediateCallerID': {'Username': self.caller_id}
}

self._stream_fields = []
Expand Down
12 changes: 6 additions & 6 deletions py/vttest/local_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ def get_sql_commands_from_file(self, filename, source_root=None):
# Strip newline and other trailing whitespace
line = line.rstrip()

if not inside_single_quotes and not inside_double_quotes and \
line.startswith('--'):
if (not inside_single_quotes and not inside_double_quotes and
line.startswith('--')):
# Line starts with '--', skip line
continue

Expand Down Expand Up @@ -168,12 +168,12 @@ def get_sql_commands_from_file(self, filename, source_root=None):
# Reached end of line
if line and not line.isspace():
if source_root and not cmd and line.startswith('source '):
commands.extend(get_sql_commands_from_file(self,
os.path.join(source_root, line[7:]),
source_root=source_root))
commands.extend(self.get_sql_commands_from_file(
os.path.join(source_root, line[7:]),
source_root=source_root))
else:
cmd += line
cmd += "\n"
cmd += '\n'

# Accept last command even if it doesn't end in semicolon
cmd = cmd.strip()
Expand Down
15 changes: 8 additions & 7 deletions py/vttest/mysql_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""This module defines the interface for the MySQL database.
"""


class MySqlDB(object):
"""A MySqlDB contains basic info about a MySQL instance."""

Expand All @@ -14,23 +15,23 @@ def __init__(self, directory, port):

def setup(self, port):
"""Starts the MySQL database."""
raise NotImplemented('MySqlDB is the base class.')
raise NotImplementedError('MySqlDB is the base class.')

def teardown(self):
"""Stops the MySQL database."""
raise NotImplemented('MySqlDB is the base class.')
raise NotImplementedError('MySqlDB is the base class.')

def username(self):
raise NotImplemented('MySqlDB is the base class.')
raise NotImplementedError('MySqlDB is the base class.')

def password(self):
raise NotImplemented('MySqlDB is the base class.')
raise NotImplementedError('MySqlDB is the base class.')

def hostname(self):
raise NotImplemented('MySqlDB is the base class.')
raise NotImplementedError('MySqlDB is the base class.')

def port(self):
raise NotImplemented('MySqlDB is the base class.')
raise NotImplementedError('MySqlDB is the base class.')

def unix_socket(self):
raise NotImplemented('MySqlDB is the base class.')
raise NotImplementedError('MySqlDB is the base class.')
32 changes: 17 additions & 15 deletions py/vttest/mysql_db_mysqlctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ def __init__(self, directory, port):
super(MySqlDBMysqlctl, self).__init__(directory, port)

def setup(self):
cmd = [environment.mysqlctl_binary,
'-alsologtostderr',
'-tablet_uid', '1',
'-mysql_port', str(self._port),
'-db-config-dba-charset', 'utf8',
'-db-config-dba-uname', 'vt_dba',
'init',
'-bootstrap_archive', 'mysql-db-dir_10.0.13-MariaDB.tbz',
cmd = [
environment.mysqlctl_binary,
'-alsologtostderr',
'-tablet_uid', '1',
'-mysql_port', str(self._port),
'-db-config-dba-charset', 'utf8',
'-db-config-dba-uname', 'vt_dba',
'init',
'-bootstrap_archive', 'mysql-db-dir_10.0.13-MariaDB.tbz',
]
env = os.environ
env['VTDATAROOT'] = self._directory
Expand All @@ -36,13 +37,14 @@ def setup(self):
raise Exception('mysqlctl failed', result)

def teardown(self):
cmd = [environment.mysqlctl_binary,
'-alsologtostderr',
'-tablet_uid', '1',
'-mysql_port', str(self._port),
'-db-config-dba-charset', 'utf8',
'-db-config-dba-uname', 'vt_dba',
'shutdown',
cmd = [
environment.mysqlctl_binary,
'-alsologtostderr',
'-tablet_uid', '1',
'-mysql_port', str(self._port),
'-db-config-dba-charset', 'utf8',
'-db-config-dba-uname', 'vt_dba',
'shutdown',
]
result = subprocess.call(cmd)
if result != 0:
Expand Down
33 changes: 19 additions & 14 deletions py/vttest/run_local_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,25 @@ def main(port, topology, schema_dir):
if __name__ == '__main__':

parser = optparse.OptionParser()
parser.add_option('-p', '--port', type='int',
help='Port to use for vtgate. If this is 0, a random port'
' will be chosen.')
parser.add_option('-t', '--topology',
help='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('-s', '--schema_dir',
help='Directory for initial schema files. Within this dir,'
' there should be a subdir for each keyspace. Within'
' each keyspace dir, each file is executed as SQL'
' after the database is created on each shard.')
parser.add_option('-v', '--verbose', action='store_true',
help='Display extra error messages.')
parser.add_option(
'-p', '--port', type='int',
help='Port to use for vtgate. If this is 0, a random port '
'will be chosen.')
parser.add_option(
'-t', '--topology',
help='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(
'-s', '--schema_dir',
help='Directory for initial schema files. Within this dir,'
' there should be a subdir for each keyspace. Within'
' each keyspace dir, each file is executed as SQL'
' after the database is created on each shard.')
parser.add_option(
'-v', '--verbose', action='store_true',
help='Display extra error messages.')
(options, args) = parser.parse_args()
if options.verbose:
logging.getLogger().setLevel(logging.DEBUG)
Expand Down
3 changes: 2 additions & 1 deletion py/vttest/vt_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def wait_start(self):
stderr=subprocess.STDOUT)
timeout = time.time() + 20.0
while time.time() < timeout:
if environment.process_is_healthy(self.name, self.addr()) and self.get_vars():
if environment.process_is_healthy(
self.name, self.addr()) and self.get_vars():
logging.info('%s started.', self.name)
return
elif self.process.poll() is not None:
Expand Down
Loading