Merge pull request #17088 from grpc/tools_py3_2

Make run_tests.py python-version agnostic
pull/16916/head
Richard Belleville 6 years ago committed by GitHub
commit 6b934a8361
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      tools/gcp/utils/big_query_utils.py
  2. 6
      tools/run_tests/python_utils/jobset.py
  3. 16
      tools/run_tests/python_utils/port_server.py
  4. 2
      tools/run_tests/python_utils/report_utils.py
  5. 19
      tools/run_tests/python_utils/start_port_server.py
  6. 3
      tools/run_tests/python_utils/watch_dirs.py
  7. 6
      tools/run_tests/run_tests.py

@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import argparse
import json
import uuid
@ -50,11 +52,11 @@ def create_dataset(biq_query, project_id, dataset_id):
dataset_req.execute(num_retries=NUM_RETRIES)
except HttpError as http_error:
if http_error.resp.status == 409:
print 'Warning: The dataset %s already exists' % dataset_id
print('Warning: The dataset %s already exists' % dataset_id)
else:
# Note: For more debugging info, print "http_error.content"
print 'Error in creating dataset: %s. Err: %s' % (dataset_id,
http_error)
print('Error in creating dataset: %s. Err: %s' % (dataset_id,
http_error))
is_success = False
return is_success
@ -122,13 +124,13 @@ def create_table2(big_query,
table_req = big_query.tables().insert(
projectId=project_id, datasetId=dataset_id, body=body)
res = table_req.execute(num_retries=NUM_RETRIES)
print 'Successfully created %s "%s"' % (res['kind'], res['id'])
print('Successfully created %s "%s"' % (res['kind'], res['id']))
except HttpError as http_error:
if http_error.resp.status == 409:
print 'Warning: Table %s already exists' % table_id
print('Warning: Table %s already exists' % table_id)
else:
print 'Error in creating table: %s. Err: %s' % (table_id,
http_error)
print('Error in creating table: %s. Err: %s' % (table_id,
http_error))
is_success = False
return is_success
@ -154,9 +156,9 @@ def patch_table(big_query, project_id, dataset_id, table_id, fields_schema):
tableId=table_id,
body=body)
res = table_req.execute(num_retries=NUM_RETRIES)
print 'Successfully patched %s "%s"' % (res['kind'], res['id'])
print('Successfully patched %s "%s"' % (res['kind'], res['id']))
except HttpError as http_error:
print 'Error in creating table: %s. Err: %s' % (table_id, http_error)
print('Error in creating table: %s. Err: %s' % (table_id, http_error))
is_success = False
return is_success
@ -172,10 +174,10 @@ def insert_rows(big_query, project_id, dataset_id, table_id, rows_list):
body=body)
res = insert_req.execute(num_retries=NUM_RETRIES)
if res.get('insertErrors', None):
print 'Error inserting rows! Response: %s' % res
print('Error inserting rows! Response: %s' % res)
is_success = False
except HttpError as http_error:
print 'Error inserting rows to the table %s' % table_id
print('Error inserting rows to the table %s' % table_id)
is_success = False
return is_success
@ -189,8 +191,8 @@ def sync_query_job(big_query, project_id, query, timeout=5000):
projectId=project_id,
body=query_data).execute(num_retries=NUM_RETRIES)
except HttpError as http_error:
print 'Query execute job failed with error: %s' % http_error
print http_error.content
print('Query execute job failed with error: %s' % http_error)
print(http_error.content)
return query_job

@ -13,8 +13,6 @@
# limitations under the License.
"""Run a group of subprocesses and then finish."""
from __future__ import print_function
import logging
import multiprocessing
import os
@ -118,7 +116,7 @@ def eintr_be_gone(fn):
while True:
try:
return fn()
except IOError, e:
except IOError as e:
if e.errno != errno.EINTR:
raise
@ -144,7 +142,7 @@ def message(tag, msg, explanatory_text=None, do_newline=False):
if do_newline or explanatory_text is not None else ''))
sys.stdout.flush()
return
except IOError, e:
except IOError as e:
if e.errno != errno.EINTR:
raise

@ -14,15 +14,17 @@
# limitations under the License.
"""Manage TCP ports for unit tests; started by run_tests.py"""
from __future__ import print_function
import argparse
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from six.moves.BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from six.moves.socketserver import ThreadingMixIn
import hashlib
import os
import socket
import sys
import time
import random
from SocketServer import ThreadingMixIn
import threading
import platform
@ -32,7 +34,7 @@ import platform
_MY_VERSION = 20
if len(sys.argv) == 2 and sys.argv[1] == 'dump_version':
print _MY_VERSION
print(_MY_VERSION)
sys.exit(0)
argp = argparse.ArgumentParser(description='Server for httpcli_test')
@ -47,7 +49,7 @@ if args.logfile is not None:
sys.stderr = open(args.logfile, 'w')
sys.stdout = sys.stderr
print 'port server running on port %d' % args.port
print('port server running on port %d' % args.port)
pool = []
in_use = {}
@ -74,7 +76,7 @@ def can_connect(port):
try:
s.connect(('localhost', port))
return True
except socket.error, e:
except socket.error as e:
return False
finally:
s.close()
@ -86,7 +88,7 @@ def can_bind(port, proto):
try:
s.bind(('localhost', port))
return True
except socket.error, e:
except socket.error as e:
return False
finally:
s.close()
@ -95,7 +97,7 @@ def can_bind(port, proto):
def refill_pool(max_timeout, req):
"""Scan for ports not marked for being in use"""
chk = [
port for port in list(range(1025, 32766))
port for port in range(1025, 32766)
if port not in cronet_restricted_ports
]
random.shuffle(chk)

@ -13,8 +13,6 @@
# limitations under the License.
"""Generate XML and HTML test reports."""
from __future__ import print_function
try:
from mako.runtime import Context
from mako.template import Template

@ -12,8 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import urllib
import jobset
from __future__ import print_function
from . import jobset
import six.moves.urllib.request as request
import logging
import os
import socket
@ -33,8 +36,8 @@ def start_port_server():
# otherwise, leave it up
try:
version = int(
urllib.urlopen('http://localhost:%d/version_number' %
_PORT_SERVER_PORT).read())
request.urlopen('http://localhost:%d/version_number' %
_PORT_SERVER_PORT).read())
logging.info('detected port server running version %d', version)
running = True
except Exception as e:
@ -51,7 +54,7 @@ def start_port_server():
running = (version >= current_version)
if not running:
logging.info('port_server version mismatch: killing the old one')
urllib.urlopen(
request.urlopen(
'http://localhost:%d/quitquitquit' % _PORT_SERVER_PORT).read()
time.sleep(1)
if not running:
@ -92,7 +95,7 @@ def start_port_server():
# try one final time: maybe another build managed to start one
time.sleep(1)
try:
urllib.urlopen(
request.urlopen(
'http://localhost:%d/get' % _PORT_SERVER_PORT).read()
logging.info(
'last ditch attempt to contact port server succeeded')
@ -101,11 +104,11 @@ def start_port_server():
logging.exception(
'final attempt to contact port server failed')
port_log = open(logfile, 'r').read()
print port_log
print(port_log)
sys.exit(1)
try:
port_server_url = 'http://localhost:%d/get' % _PORT_SERVER_PORT
urllib.urlopen(port_server_url).read()
request.urlopen(port_server_url).read()
logging.info('port server is up and ready')
break
except socket.timeout:

@ -15,13 +15,14 @@
import os
import time
from six import string_types
class DirWatcher(object):
"""Helper to watch a (set) of directories for modifications."""
def __init__(self, paths):
if isinstance(paths, basestring):
if isinstance(paths, string_types):
paths = [paths]
self._done = False
self.paths = list(paths)

@ -1512,7 +1512,7 @@ if args.travis:
_FORCE_ENVIRON_FOR_WRAPPERS = {'GRPC_TRACE': 'api'}
if 'all' in args.language:
lang_list = _LANGUAGES.keys()
lang_list = list(_LANGUAGES.keys())
else:
lang_list = args.language
# We don't support code coverage on some languages
@ -1719,9 +1719,9 @@ def _has_epollexclusive():
try:
subprocess.check_call(binary)
return True
except subprocess.CalledProcessError, e:
except subprocess.CalledProcessError as e:
return False
except OSError, e:
except OSError as e:
# For languages other than C and Windows the binary won't exist
return False

Loading…
Cancel
Save