Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH v1] Support to run tests with Python 3
@ 2020-11-21  9:44 sergeyb
  2020-12-01 17:03 ` Leonid Vasiliev
  0 siblings, 1 reply; 4+ messages in thread
From: sergeyb @ 2020-11-21  9:44 UTC (permalink / raw)
  To: tarantool-patches, lvasiliev, alexander.turenko

From: Sergey Bronnikov <sergeyb@tarantool.org>

In a Python 3 'print' becomes a function, see [1]. Patch makes 'print'
in a regression tests written in Python compatible with Python 3.

1. https://docs.python.org/3/whatsnew/3.0.html#print-is-a-function

Closes #5538
---
Gitlab CI: https://gitlab.com/tarantool/tarantool/-/pipelines/219268877
GH issue: https://github.com/tarantool/tarantool/issues/5538

 test/box-py/bad_trigger.test.py          |  14 +--
 test/box-py/call.test.py                 |  20 +--
 test/box-py/iproto.test.py               | 148 ++++++++++++-----------
 test/box-py/snapshot.test.py             |  16 +--
 test/replication-py/cluster.test.py      | 113 ++++++++---------
 test/replication-py/conflict.test.py     |   8 +-
 test/replication-py/init_storage.test.py |  26 ++--
 test/replication-py/multi.test.py        |  66 +++++-----
 test/replication-py/swap.test.py         |  20 +--
 test/xlog-py/dup_key.test.py             |  12 +-
 test/xlog-py/empty.test.py               |   2 +-
 test/xlog-py/lsn_gap.test.py             |   8 +-
 test/xlog-py/misc.test.py                |  24 ++--
 test/xlog-py/missing.test.py             |   8 +-
 14 files changed, 245 insertions(+), 240 deletions(-)

diff --git a/test/box-py/bad_trigger.test.py b/test/box-py/bad_trigger.test.py
index 7d200b921..d85b9055f 100644
--- a/test/box-py/bad_trigger.test.py
+++ b/test/box-py/bad_trigger.test.py
@@ -6,11 +6,11 @@ from tarantool.const import IPROTO_GREETING_SIZE, IPROTO_CODE, IPROTO_ERROR, \
 import socket
 import msgpack
 
-print """
+print("""
  #
  # if on_connect() trigger raises an exception, the connection is dropped
  #
- """
+ """)
 
 # silence possible error of strict mode
 server.admin("nosuchfunction = nil")
@@ -24,12 +24,12 @@ conn.connect()
 s = conn.socket
 
 # Read greeting
-print 'greeting: ', len(s.recv(IPROTO_GREETING_SIZE)) == IPROTO_GREETING_SIZE
+print('greeting:  {}'.format(len(s.recv(IPROTO_GREETING_SIZE)) == IPROTO_GREETING_SIZE))
 
 # Read error packet
 IPROTO_FIXHEADER_SIZE = 5
 fixheader = s.recv(IPROTO_FIXHEADER_SIZE)
-print 'fixheader: ', len(fixheader) == IPROTO_FIXHEADER_SIZE
+print('fixheader:  {}'.format(len(fixheader) == IPROTO_FIXHEADER_SIZE))
 unpacker.feed(fixheader)
 packet_len = unpacker.unpack()
 packet = s.recv(packet_len)
@@ -38,9 +38,9 @@ unpacker.feed(packet)
 # Parse packet
 header = unpacker.unpack()
 body = unpacker.unpack()
-print 'error code', (header[IPROTO_CODE] & (REQUEST_TYPE_ERROR - 1))
-print 'error message: ', body[IPROTO_ERROR]
-print 'eof:', len(s.recv(1024)) == 0
+print('error code {}'.format((header[IPROTO_CODE] & (REQUEST_TYPE_ERROR - 1))))
+print('error message:  {}'.format(body[IPROTO_ERROR]))
+print('eof: {}'.format(len(s.recv(1024)) == 0))
 s.close()
 
 server.admin("box.session.on_connect(nil, f1)")
diff --git a/test/box-py/call.test.py b/test/box-py/call.test.py
index 974ba0cac..133c3fcfd 100644
--- a/test/box-py/call.test.py
+++ b/test/box-py/call.test.py
@@ -21,11 +21,11 @@ call("f1")
 # IPROTO required!
 call("box.error", 33333, 'Hey!')
 
-print """
+print("""
 # A test case for Bug#103491
 # server CALL processing bug with name path longer than two
 # https://bugs.launchpad.net/tarantool/+bug/1034912
-"""
+""")
 admin("f = function() return 'OK' end")
 admin("test = {}")
 admin("test.f = f")
@@ -35,11 +35,11 @@ call("f")
 call("test.f")
 call("test.test.f")
 
-print """
+print("""
 # Test for Bug #955226
 # Lua Numbers are passed back wrongly as strings
 #
-"""
+""")
 admin("function foo() return 1, 2, '1', '2' end")
 call("foo")
 
@@ -136,14 +136,14 @@ admin("index = space:create_index('primary', { type = 'tree' })")
 
 
 def lua_eval(name, *args):
-    print 'eval (%s)(%s)' % (name, ','.join([ str(arg) for arg in args]))
-    print '---'
-    print iproto.py_con.eval(name, args)
+    print('eval (%s)(%s)' % (name, ','.join([ str(arg) for arg in args])))
+    print('---')
+    print(iproto.py_con.eval(name, args))
 
 def lua_call(name, *args):
-    print 'call %s(%s)' % (name, ','.join([ str(arg) for arg in args]))
-    print '---'
-    print iproto.py_con.call(name, args)
+    print('call %s(%s)' % (name, ','.join([ str(arg) for arg in args])))
+    print('---')
+    print(iproto.py_con.call(name, args))
 
 def test(expr, *args):
     lua_eval('return ' + expr, *args)
diff --git a/test/box-py/iproto.test.py b/test/box-py/iproto.test.py
index cdd1a71c5..cc1db9a09 100644
--- a/test/box-py/iproto.test.py
+++ b/test/box-py/iproto.test.py
@@ -1,3 +1,5 @@
+from __future__ import print_function
+
 import os
 import sys
 import struct
@@ -11,25 +13,25 @@ from lib.tarantool_connection import TarantoolConnection
 
 admin("box.schema.user.grant('guest', 'read,write,execute', 'universe')")
 
-print """
+print("""
 #
 # iproto packages test
 #
-"""
+""")
 
 # opeing new connection to tarantool/box
 conn = TarantoolConnection(server.iproto.host, server.iproto.port)
 conn.connect()
 s = conn.socket
 
-print """
+print("""
 # Test bug #899343 (server assertion failure on incorrect packet)
-"""
-print "# send the package with invalid length"
+""")
+print("# send the package with invalid length")
 invalid_request = struct.pack('<LLL', 1, 4294967290, 1)
-print s.send(invalid_request)
-print "# check that is server alive"
-print iproto.py_con.ping() > 0
+print(s.send(invalid_request))
+print("# check that is server alive")
+print(iproto.py_con.ping() > 0)
 
 # closing connection
 s.close()
@@ -50,7 +52,7 @@ def test(header, body):
     # Connect and authenticate
     c = Connection('localhost', server.iproto.port)
     c.connect()
-    print 'query', repr_dict(header), repr_dict(body)
+    print('query', repr_dict(header), repr_dict(body))
     header = msgpack.dumps(header)
     body = msgpack.dumps(body)
     query = msgpack.dumps(len(header) + len(body)) + header + body
@@ -59,36 +61,36 @@ def test(header, body):
     try:
         s.send(query)
     except OSError as e:
-        print '   => ', 'Failed to send request'
+        print('   => ', 'Failed to send request')
     c.close()
-    print iproto.py_con.ping() > 0
+    print(iproto.py_con.ping() > 0)
 
-print """
+print("""
 #  Test gh-206 "Segfault if sending IPROTO package without `KEY` field"
-"""
+""")
 
-print "IPROTO_SELECT"
+print("IPROTO_SELECT")
 test({ IPROTO_CODE : REQUEST_TYPE_SELECT }, { IPROTO_SPACE_ID: 280 })
-print "\n"
+print("\n")
 
-print "IPROTO_DELETE"
+print("IPROTO_DELETE")
 test({ IPROTO_CODE : REQUEST_TYPE_DELETE }, { IPROTO_SPACE_ID: 280 })
-print "\n"
+print("\n")
 
-print "IPROTO_UPDATE"
+print("IPROTO_UPDATE")
 test({ IPROTO_CODE : REQUEST_TYPE_UPDATE }, { IPROTO_SPACE_ID: 280 })
 test({ IPROTO_CODE : REQUEST_TYPE_UPDATE },
      { IPROTO_SPACE_ID: 280, IPROTO_KEY: (1, )})
-print "\n"
+print("\n")
 
-print "IPROTO_REPLACE"
+print("IPROTO_REPLACE")
 test({ IPROTO_CODE : REQUEST_TYPE_REPLACE }, { IPROTO_SPACE_ID: 280 })
-print "\n"
+print("\n")
 
-print "IPROTO_CALL"
+print("IPROTO_CALL")
 test({ IPROTO_CODE : REQUEST_TYPE_CALL }, {})
 test({ IPROTO_CODE : REQUEST_TYPE_CALL }, { IPROTO_KEY: ('procname', )})
-print "\n"
+print("\n")
 
 # gh-434 Tarantool crashes on multiple iproto requests with WAL enabled
 admin("box.cfg.wal_mode")
@@ -104,11 +106,11 @@ s = c._socket
 try:
     s.send(bytes(request1) + bytes(request2))
 except OSError as e:
-    print '   => ', 'Failed to send request'
+    print('   => ', 'Failed to send request')
 response1 = Response(c, c._read_response())
 response2 = Response(c, c._read_response())
-print response1.__str__()
-print response2.__str__()
+print(response1.__str__())
+print(response2.__str__())
 
 request1 = RequestInsert(c, 567, [3, "occama"])
 request2 = RequestSelect(c, 567, 0, [1], 0, 1, 0)
@@ -116,11 +118,11 @@ s = c._socket
 try:
     s.send(bytes(request1) + bytes(request2))
 except OSError as e:
-    print '   => ', 'Failed to send request'
+    print('   => ', 'Failed to send request')
 response1 = Response(c, c._read_response())
 response2 = Response(c, c._read_response())
-print response1.__str__()
-print response2.__str__()
+print(response1.__str__())
+print(response2.__str__())
 
 request1 = RequestSelect(c, 567, 0, [2], 0, 1, 0)
 request2 = RequestInsert(c, 567, [4, "ockham"])
@@ -128,11 +130,11 @@ s = c._socket
 try:
     s.send(bytes(request1) + bytes(request2))
 except OSError as e:
-    print '   => ', 'Failed to send request'
+    print('   => ', 'Failed to send request')
 response1 = Response(c, c._read_response())
 response2 = Response(c, c._read_response())
-print response1.__str__()
-print response2.__str__()
+print(response1.__str__())
+print(response2.__str__())
 
 request1 = RequestSelect(c, 567, 0, [1], 0, 1, 0)
 request2 = RequestSelect(c, 567, 0, [2], 0, 1, 0)
@@ -140,11 +142,11 @@ s = c._socket
 try:
     s.send(bytes(request1) + bytes(request2))
 except OSError as e:
-    print '   => ', 'Failed to send request'
+    print('   => ', 'Failed to send request')
 response1 = Response(c, c._read_response())
 response2 = Response(c, c._read_response())
-print response1.__str__()
-print response2.__str__()
+print(response1.__str__())
+print(response2.__str__())
 
 c.close()
 
@@ -192,27 +194,27 @@ TESTS = [
 for test in TESTS:
     it = iter(test)
     size = next(it)
-    print 'STR', size
-    print '--'
+    print('STR', size)
+    print('--')
     for fmt in it:
-        print '0x' + fmt.encode('hex'), '=>',
+        print('0x' + fmt.encode('hex'), '=>', end=" ")
         field = '*' * size
         c._send_request(RawInsert(c, space_id, "\x91" + fmt + field))
         tuple = space.select(field)[0]
-        print len(tuple[0])== size and 'ok' or 'fail',
+        print(len(tuple[0])== size and 'ok' or 'fail', end=" ")
         it2 = iter(test)
         next(it2)
         for fmt2 in it2:
             tuple = c._send_request(RawSelect(c, space_id,
                 "\x91" + fmt2 + field))[0]
-            print len(tuple[0]) == size and 'ok' or 'fail',
+            print(len(tuple[0]) == size and 'ok' or 'fail', end=" ")
         tuple = space.delete(field)[0]
-        print len(tuple[0]) == size and 'ok' or 'fail',
-        print
-    print
+        print(len(tuple[0]) == size and 'ok' or 'fail', end="")
+        print()
+    print()
 
 
-print 'Test of schema_id in iproto.'
+print('Test of schema_id in iproto.')
 c = Connection('localhost', server.iproto.port)
 c.connect()
 s = c._socket
@@ -235,7 +237,7 @@ def receive_response():
         resp_header = unpacker.unpack()
         resp_body = unpacker.unpack()
     except OSError as e:
-        print '   => ', 'Failed to recv response'
+        print('   => ', 'Failed to recv response')
     res = {}
     res['header'] = resp_header
     res['body'] = resp_body
@@ -249,7 +251,7 @@ def test_request(req_header, req_body):
     try:
         s.send(query)
     except OSError as e:
-        print '   => ', 'Failed to send request'
+        print('   => ', 'Failed to send request')
     return receive_response()
 
 header = { IPROTO_CODE : REQUEST_TYPE_SELECT}
@@ -260,31 +262,31 @@ body = { IPROTO_SPACE_ID: space_id,
     IPROTO_OFFSET: 0,
     IPROTO_LIMIT: 1 }
 resp = test_request(header, body)
-print 'Normal connect done w/o errors:', resp['header'][0] == 0
-print 'Got schema_id:', resp['header'][5] > 0
+print('Normal connect done w/o errors:', resp['header'][0] == 0)
+print('Got schema_id:', resp['header'][5] > 0)
 schema_id = resp['header'][5]
 
 header = { IPROTO_CODE : REQUEST_TYPE_SELECT, 5 : 0 }
 resp = test_request(header, body)
-print 'Zero-schema_id connect done w/o errors:', resp['header'][0] == 0
-print 'Same schema_id:', resp['header'][5] == schema_id
+print('Zero-schema_id connect done w/o errors:', resp['header'][0] == 0)
+print('Same schema_id:', resp['header'][5] == schema_id)
 
 header = { IPROTO_CODE : REQUEST_TYPE_SELECT, 5 : schema_id }
 resp = test_request(header, body)
-print 'Normal connect done w/o errors:', resp['header'][0] == 0
-print 'Same schema_id:', resp['header'][5] == schema_id
+print('Normal connect done w/o errors:', resp['header'][0] == 0)
+print('Same schema_id:', resp['header'][5] == schema_id)
 
 header = { IPROTO_CODE : REQUEST_TYPE_SELECT, 5 : schema_id + 1 }
 resp = test_request(header, body)
-print 'Wrong schema_id leads to error:', resp['header'][0] != 0
-print 'Same schema_id:', resp['header'][5] == schema_id
+print('Wrong schema_id leads to error:', resp['header'][0] != 0)
+print('Same schema_id:', resp['header'][5] == schema_id)
 
 admin("space2 = box.schema.create_space('test2')")
 
 header = { IPROTO_CODE : REQUEST_TYPE_SELECT, 5 : schema_id }
 resp = test_request(header, body)
-print 'Schema changed -> error:', resp['header'][0] != 0
-print 'Got another schema_id:', resp['header'][5] != schema_id
+print('Schema changed -> error:', resp['header'][0] != 0)
+print('Got another schema_id:', resp['header'][5] != schema_id)
 
 #
 # gh-2334 Lost SYNC in JOIN response.
@@ -298,14 +300,14 @@ if resp['header'][IPROTO_SYNC] == 2334:
     while i < 3:
         resp = receive_response()
         if resp['header'][IPROTO_SYNC] != 2334:
-            print 'Bad sync on response with number ', i
+            print('Bad sync on response with number ', i)
             break
         if resp['header'][IPROTO_CODE] == REQUEST_TYPE_OK:
             i += 1
     else:
-        print 'Sync ok'
+        print('Sync ok')
 else:
-    print 'Bad first sync'
+    print('Bad first sync')
 
 #
 # Try incorrect JOIN. SYNC must be also returned.
@@ -344,10 +346,10 @@ admin("box.schema.user.revoke('guest', 'read,write,execute', 'universe')")
 # gh-272 if the packet was incorrect, respond with an error code
 # gh-1654 do not close connnection on invalid request
 #
-print """
+print("""
 # Test bugs gh-272, gh-1654 if the packet was incorrect, respond with
 # an error code and do not close connection
-"""
+""")
 
 c = Connection('localhost', server.iproto.port)
 c.connect()
@@ -355,15 +357,15 @@ s = c._socket
 header = { "hello": "world"}
 body = { "bug": 272 }
 resp = test_request(header, body)
-print 'sync=%d, %s' % (resp['header'][IPROTO_SYNC], resp['body'].get(IPROTO_ERROR))
+print('sync=%d, %s' % (resp['header'][IPROTO_SYNC], resp['body'].get(IPROTO_ERROR)))
 header = { IPROTO_CODE : REQUEST_TYPE_SELECT }
 header[IPROTO_SYNC] = 1234
 resp = test_request(header, body)
-print 'sync=%d, %s' % (resp['header'][IPROTO_SYNC], resp['body'].get(IPROTO_ERROR))
+print('sync=%d, %s' % (resp['header'][IPROTO_SYNC], resp['body'].get(IPROTO_ERROR)))
 header[IPROTO_SYNC] = 5678
 body = { IPROTO_SPACE_ID: 304, IPROTO_KEY: [], IPROTO_LIMIT: 1 }
 resp = test_request(header, body)
-print 'sync=%d, %s' % (resp['header'][IPROTO_SYNC], resp['body'].get(IPROTO_ERROR))
+print('sync=%d, %s' % (resp['header'][IPROTO_SYNC], resp['body'].get(IPROTO_ERROR)))
 c.close()
 
 
@@ -379,32 +381,32 @@ request = RequestInsert(c, 568, [1, 0, 0, 0])
 try:
     s.send(bytes(request))
 except OSError as e:
-    print '   => ', 'Failed to send request'
+    print('   => ', 'Failed to send request')
 response = Response(c, c._read_response())
-print response.__str__()
+print(response.__str__())
 
 request = RequestUpdate(c, 568, 0, [1], [['+', 2, 1], ['-', 3, 1]])
 try:
     s.send(bytes(request))
 except OSError as e:
-    print '   => ', 'Failed to send request'
+    print('   => ', 'Failed to send request')
 response = Response(c, c._read_response())
-print response.__str__()
+print(response.__str__())
 
 request = RequestUpsert(c, 568, 0, [1, 0, 0, 0], [['+', 2, 1], ['-', 3, 1]])
 try:
     s.send(bytes(request))
 except OSError as e:
-    print '   => ', 'Failed to send request'
+    print('   => ', 'Failed to send request')
 response = Response(c, c._read_response())
 
 request = RequestSelect(c, 568, 0, [1], 0, 1, 0)
 try:
     s.send(bytes(request))
 except OSError as e:
-    print '   => ', 'Failed to send request'
+    print('   => ', 'Failed to send request')
 response = Response(c, c._read_response())
-print response.__str__()
+print(response.__str__())
 
 c.close()
 
@@ -421,8 +423,8 @@ s = c._socket
 header = { IPROTO_CODE: REQUEST_TYPE_CALL, IPROTO_SYNC: 100 }
 body = { IPROTO_FUNCTION_NAME: 'kek' }
 resp = test_request(header, body)
-print "Sync: ", resp['header'][IPROTO_SYNC]
-print "Retcode: ", resp['body'][IPROTO_DATA]
+print("Sync: ", resp['header'][IPROTO_SYNC])
+print("Retcode: ", resp['body'][IPROTO_DATA])
 
 c.close()
 
diff --git a/test/box-py/snapshot.test.py b/test/box-py/snapshot.test.py
index 2bfb8f621..dc5f3ee08 100644
--- a/test/box-py/snapshot.test.py
+++ b/test/box-py/snapshot.test.py
@@ -9,13 +9,13 @@ sys.stdout.push_filter(server.vardir, "<dir>")
 admin("space = box.schema.space.create('tweedledum')")
 admin("index = space:create_index('primary', { type = 'hash' })")
 
-print """#
+print("""#
 # A test case for: http://bugs.launchpad.net/bugs/686411
 # Check that 'box.snapshot()' does not overwrite a snapshot
 # file that already exists. Verify also that any other
 # error that happens when saving snapshot is propagated
 # to the caller.
-"""
+""")
 admin("space:insert{1, 'first tuple'}")
 admin("box.snapshot()")
 #
@@ -38,14 +38,14 @@ os.rmdir(snapshot)
 admin("space:delete{1}")
 admin("space:delete{2}")
 
-print """#
+print("""#
 # A test case for http://bugs.launchpad.net/bugs/727174
 # "tarantool_box crashes when saving snapshot on SIGUSR1"
-#"""
+#""")
 
-print """
+print("""
 # Increment the lsn number, to make sure there is no such snapshot yet
-#"""
+#""")
 
 admin("space:insert{1, 'Test tuple'}")
 
@@ -65,9 +65,9 @@ while not os.access(snapshot, os.F_OK) and iteration < MAX_ITERATIONS:
   iteration = iteration + 1
 
 if iteration == 0 or iteration >= MAX_ITERATIONS:
-  print "Snapshot is missing."
+  print("Snapshot is missing.")
 else:
-  print "Snapshot exists."
+  print("Snapshot exists.")
 
 admin("space:drop()")
 
diff --git a/test/replication-py/cluster.test.py b/test/replication-py/cluster.test.py
index 088ca9c34..6a83611d7 100644
--- a/test/replication-py/cluster.test.py
+++ b/test/replication-py/cluster.test.py
@@ -12,14 +12,14 @@ try:
     cluster_uuid = yaml.safe_load(server.admin("box.space._schema:get('cluster')",
         silent = True))[0][1]
     uuid.UUID('{' + cluster_uuid + '}')
-    print 'ok - cluster uuid'
+    print('ok - cluster uuid')
 except Exception as e:
-    print 'not ok - invalid cluster uuid', e
+    print('not ok - invalid cluster uuid', e)
 
 server.iproto.reconnect() # re-connect with new permissions
-print '-------------------------------------------------------------'
-print ' gh-696: Check global READ permissions for replication'
-print '-------------------------------------------------------------'
+print('-------------------------------------------------------------')
+print(' gh-696: Check global READ permissions for replication')
+print('-------------------------------------------------------------')
 
 
 # Generate replica cluster UUID
@@ -27,23 +27,26 @@ replica_uuid = str(uuid.uuid4())
 
 ## Universal read permission is required to perform JOIN/SUBSCRIBE
 rows = list(server.iproto.py_con.join(replica_uuid))
-print len(rows) == 1 and rows[0].return_message.find('Read access') >= 0 and \
-    'ok' or 'not ok', '-', 'join without read permissions on universe'
+status = len(rows) == 1 and rows[0].return_message.find('Read access') >= 0 and \
+        'ok' or 'not ok'
+print('{} - join without read permissions on universe'.format(status))
 rows = list(server.iproto.py_con.subscribe(cluster_uuid, replica_uuid))
-print len(rows) == 1 and rows[0].return_message.find('Read access') >= 0 and \
-    'ok' or 'not ok', '-', 'subscribe without read permissions on universe'
+status = len(rows) == 1 and rows[0].return_message.find('Read access') >= 0 and \
+        'ok' or 'not ok'
+print('{} - subscribe without read permissions on universe'.format(status))
 ## Write permission to space `_cluster` is required to perform JOIN
 server.admin("box.schema.user.grant('guest', 'read', 'universe')")
 server.iproto.reconnect() # re-connect with new permissions
 rows = list(server.iproto.py_con.join(replica_uuid))
-print len(rows) == 1 and rows[0].return_message.find('Write access') >= 0 and \
-    'ok' or 'not ok', '-', 'join without write permissions to _cluster'
+status = len(rows) == 1 and rows[0].return_message.find('Write access') >= 0 and \
+        'ok' or 'not ok'
+print('{} - join without write permissions to _cluster'.format(status))
 
 def check_join(msg):
     ok = True
     for resp in server.iproto.py_con.join(replica_uuid):
         if resp._return_code != 0:
-            print 'not ok', '-', msg, resp.return_message
+            print('not ok - {} {}'.format(msg, resp.return_message))
             ok = False
 
     server.iproto.reconnect() # the only way to stop JOIN
@@ -51,10 +54,10 @@ def check_join(msg):
         return
     tuples = server.iproto.py_con.space('_cluster').select(replica_uuid, index = 1)
     if len(tuples) == 0:
-        print 'not ok', '-', msg, 'missing entry in _cluster'
+        print('not ok - {} missing entry in _cluster'.format(msg))
         return
     server_id = tuples[0][0]
-    print 'ok', '-', msg
+    print('ok - {}'.format(msg))
     return server_id
 
 ## JOIN with permissions
@@ -71,9 +74,9 @@ server.iproto.reconnect() # re-connect with new permissions
 server_id = check_join('join with granted role')
 server.iproto.py_con.space('_cluster').delete(server_id)
 
-print '-------------------------------------------------------------'
-print 'gh-434: Assertion if replace _cluster tuple for local server'
-print '-------------------------------------------------------------'
+print('-------------------------------------------------------------')
+print('gh-434: Assertion if replace _cluster tuple for local server')
+print('-------------------------------------------------------------')
 
 master_uuid = server.get_param('uuid')
 sys.stdout.push_filter(master_uuid, '<master uuid>')
@@ -87,9 +90,9 @@ server.admin("box.space._cluster:replace{1, require('uuid').str()}")
 # Update of tail is OK
 server.admin("box.space._cluster:update(1, {{'=', 3, 'test'}})")
 
-print '-------------------------------------------------------------'
-print 'gh-1140: Assertion if replace _cluster tuple for remote server'
-print '-------------------------------------------------------------'
+print('-------------------------------------------------------------')
+print('gh-1140: Assertion if replace _cluster tuple for remote server')
+print('-------------------------------------------------------------')
 
 # Test that insert is OK
 new_uuid = '0d5bd431-7f3e-4695-a5c2-82de0a9cbc95'
@@ -112,9 +115,9 @@ server.admin("box.info.vclock[5] == nil")
 server.stop()
 server.deploy()
 
-print '-------------------------------------------------------------'
-print 'Start a new replica and check box.info on the start'
-print '-------------------------------------------------------------'
+print('-------------------------------------------------------------')
+print('Start a new replica and check box.info on the start')
+print('-------------------------------------------------------------')
 # master server
 master = server
 master_id = master.get_param('id')
@@ -135,45 +138,45 @@ replica.admin('not box.info.ro')
 replica.admin('box.info.lsn == 0')
 replica.admin('box.info.vclock[%d] == nil' % replica_id)
 
-print '-------------------------------------------------------------'
-print 'Modify data to bump LSN and check box.info'
-print '-------------------------------------------------------------'
+print('-------------------------------------------------------------')
+print('Modify data to bump LSN and check box.info')
+print('-------------------------------------------------------------')
 replica.admin('box.space._schema:insert{"test", 48}')
 replica.admin('box.info.lsn == 1')
 replica.admin('box.info.vclock[%d] == 1' % replica_id)
 
-print '-------------------------------------------------------------'
-print 'Connect master to replica'
-print '-------------------------------------------------------------'
+print('-------------------------------------------------------------')
+print('Connect master to replica')
+print('-------------------------------------------------------------')
 replication_source = yaml.safe_load(replica.admin('box.cfg.listen', silent = True))[0]
 sys.stdout.push_filter(replication_source, '<replication_source>')
 master.admin("box.cfg{ replication_source = '%s' }" % replication_source)
 master.wait_lsn(replica_id, replica.get_lsn(replica_id))
 
-print '-------------------------------------------------------------'
-print 'Disconnect replica from master'
-print '-------------------------------------------------------------'
+print('-------------------------------------------------------------')
+print('Disconnect replica from master')
+print('-------------------------------------------------------------')
 replica.admin('box.cfg { replication_source = "" }')
 
-print '-------------------------------------------------------------'
-print 'Unregister replica'
-print '-------------------------------------------------------------'
+print('-------------------------------------------------------------')
+print('Unregister replica')
+print('-------------------------------------------------------------')
 
 master.admin('box.space._cluster:delete{%d} ~= nil' % replica_id)
 
 # gh-1219: LSN must not be removed from vclock on unregister
 master.admin('box.info.vclock[%d] == 1' % replica_id)
 
-print '-------------------------------------------------------------'
-print 'Modify data to bump LSN on replica'
-print '-------------------------------------------------------------'
+print('-------------------------------------------------------------')
+print('Modify data to bump LSN on replica')
+print('-------------------------------------------------------------')
 replica.admin('box.space._schema:insert{"tost", 49}')
 replica.admin('box.info.lsn == 2')
 replica.admin('box.info.vclock[%d] == 2' % replica_id)
 
-print '-------------------------------------------------------------'
-print 'Master must not crash then receives orphan rows from replica'
-print '-------------------------------------------------------------'
+print('-------------------------------------------------------------')
+print('Master must not crash then receives orphan rows from replica')
+print('-------------------------------------------------------------')
 
 replication_source = yaml.safe_load(replica.admin('box.cfg.listen', silent = True))[0]
 sys.stdout.push_filter(replication_source, '<replication>')
@@ -186,9 +189,9 @@ master.admin("box.cfg{ replication = '' }")
 replica.stop()
 replica.cleanup()
 
-print '-------------------------------------------------------------'
-print 'Start a new replica and check that server_id, LSN is re-used'
-print '-------------------------------------------------------------'
+print('-------------------------------------------------------------')
+print('Start a new replica and check that server_id, LSN is re-used')
+print('-------------------------------------------------------------')
 
 #
 # gh-1219: Proper removal of servers with non-zero LSN from _cluster
@@ -216,9 +219,9 @@ replica.stop()
 replica.cleanup()
 master.admin('box.space._cluster:delete{%d} ~= nil' % replica_id)
 
-print '-------------------------------------------------------------'
-print 'JOIN replica to read-only master'
-print '-------------------------------------------------------------'
+print('-------------------------------------------------------------')
+print('JOIN replica to read-only master')
+print('-------------------------------------------------------------')
 
 # master server
 master = server
@@ -235,13 +238,13 @@ try:
 except Exception as e:
     line = "ER_READONLY"
     if failed.logfile_pos.seek_once(line) >= 0:
-        print "'%s' exists in server log" % line
+        print("'%s' exists in server log" % line)
 
 master.admin('box.cfg { read_only = false }')
 
-print '-------------------------------------------------------------'
-print 'JOIN replica with different replica set UUID'
-print '-------------------------------------------------------------'
+print('-------------------------------------------------------------')
+print('JOIN replica with different replica set UUID')
+print('-------------------------------------------------------------')
 
 failed = TarantoolServer(server.ini)
 failed.script = 'replication-py/uuid_mismatch.lua'
@@ -254,13 +257,13 @@ try:
 except Exception as e:
     line = "ER_REPLICASET_UUID_MISMATCH"
     if failed.logfile_pos.seek_once(line) >= 0:
-        print "'%s' exists in server log" % line
+        print("'%s' exists in server log" % line)
 
 failed.cleanup()
 
-print '-------------------------------------------------------------'
-print 'Cleanup'
-print '-------------------------------------------------------------'
+print('-------------------------------------------------------------')
+print('Cleanup')
+print('-------------------------------------------------------------')
 
 # Cleanup
 sys.stdout.pop_filter()
diff --git a/test/replication-py/conflict.test.py b/test/replication-py/conflict.test.py
index 1dcd66765..70afdeda4 100644
--- a/test/replication-py/conflict.test.py
+++ b/test/replication-py/conflict.test.py
@@ -16,8 +16,8 @@ replica.rpl_master = master
 replica.deploy()
 
 def parallel_run(cmd1, cmd2, compare):
-    print 'parallel send: %s' % cmd1
-    print 'parallel send: %s' % cmd2
+    print('parallel send: %s' % cmd1)
+    print('parallel send: %s' % cmd2)
     master.admin.socket.sendall('%s\n' % cmd1)
     replica.admin.socket.sendall('%s\n' % cmd2)
 
@@ -37,11 +37,11 @@ def parallel_run(cmd1, cmd2, compare):
     while True:
         sleep(0.01)
         if any(results):
-            print 'replication state is correct'
+            print('replication state is correct')
             break
 
 def prepare_cluster():
-    print 'reset master-master replication'
+    print('reset master-master replication')
     master.stop()
     master.cleanup()
     master.start()
diff --git a/test/replication-py/init_storage.test.py b/test/replication-py/init_storage.test.py
index 4be531f8d..c65fca27b 100644
--- a/test/replication-py/init_storage.test.py
+++ b/test/replication-py/init_storage.test.py
@@ -7,9 +7,9 @@ master = server
 master_id = master.get_param('id')
 master.admin("box.schema.user.grant('guest', 'replication')")
 
-print '-------------------------------------------------------------'
-print 'gh-484: JOIN doesn\'t save data to snapshot with TREE index'
-print '-------------------------------------------------------------'
+print('-------------------------------------------------------------')
+print('gh-484: JOIN doesn\'t save data to snapshot with TREE index')
+print('-------------------------------------------------------------')
 
 master.admin("space = box.schema.space.create('test', {id =  42})")
 master.admin("index = space:create_index('primary', { type = 'tree'})")
@@ -28,9 +28,9 @@ replica.admin('box.space.test:select()')
 replica.stop()
 replica.cleanup()
 
-print '-------------------------------------------------------------'
-print 'replica test 2 (must be ok)'
-print '-------------------------------------------------------------'
+print('-------------------------------------------------------------')
+print('replica test 2 (must be ok)')
+print('-------------------------------------------------------------')
 
 master.restart()
 master.admin('for k = 10, 19 do box.space[42]:insert{k, k*k*k} end')
@@ -51,9 +51,9 @@ for i in range(1, 20):
 replica.stop()
 replica.cleanup()
 
-print '-------------------------------------------------------------'
-print 'reconnect on JOIN/SUBSCRIBE'
-print '-------------------------------------------------------------'
+print('-------------------------------------------------------------')
+print('reconnect on JOIN/SUBSCRIBE')
+print('-------------------------------------------------------------')
 
 server.stop()
 replica = TarantoolServer(server.ini)
@@ -62,19 +62,19 @@ replica.vardir = server.vardir #os.path.join(server.vardir, 'replica')
 replica.rpl_master = master
 replica.deploy(wait=False)
 
-print 'waiting reconnect on JOIN...'
+print('waiting reconnect on JOIN...')
 server.start()
 replica.wait_until_started()
-print 'ok'
+print('ok')
 
 replica.stop()
 server.stop()
 
-print 'waiting reconnect on SUBSCRIBE...'
+print('waiting reconnect on SUBSCRIBE...')
 replica.start(wait=False)
 server.start()
 replica.wait_until_started()
-print 'ok'
+print('ok')
 
 replica.stop()
 replica.cleanup()
diff --git a/test/replication-py/multi.test.py b/test/replication-py/multi.test.py
index 233802458..21495fa2e 100644
--- a/test/replication-py/multi.test.py
+++ b/test/replication-py/multi.test.py
@@ -14,9 +14,9 @@ master.admin("fiber = require('fiber')")
 master.admin("box.schema.user.grant('guest', 'replication')")
 master.admin("box.schema.user.grant('guest', 'execute', 'universe')")
 
-print '----------------------------------------------------------------------'
-print 'Bootstrap replicas'
-print '----------------------------------------------------------------------'
+print('----------------------------------------------------------------------')
+print('Bootstrap replicas')
+print('----------------------------------------------------------------------')
 
 # Start replicas
 master.id = master.get_param('id')
@@ -31,17 +31,17 @@ for i in range(REPLICA_N - 1):
     # Otherwise can get ACCESS_DENIED error.
     cluster.append(server)
 
-# Make a list of servers
+# Makie a list of servers
 sources = []
 for server in cluster:
     sources.append(yaml.safe_load(server.admin('box.cfg.listen', silent = True))[0])
     server.id = server.get_param('id')
 
-print 'done'
+print('done')
 
-print '----------------------------------------------------------------------'
-print 'Make a full mesh'
-print '----------------------------------------------------------------------'
+print('----------------------------------------------------------------------')
+print('Make a full mesh')
+print('----------------------------------------------------------------------')
 
 # Connect each server to each other to make full mesh
 for server in cluster:
@@ -54,55 +54,55 @@ for server in cluster:
             while #box.info.vclock[...] ~= nil do
                 fiber.sleep(0.01)
             end;""", server2.id)
-        print 'server', server.id, "connected"
+        print('server {} connected'.format(server.id))
 
-print 'done'
+print('done')
 
-print '----------------------------------------------------------------------'
-print 'Test inserts'
-print '----------------------------------------------------------------------'
+print('----------------------------------------------------------------------')
+print('Test inserts')
+print('----------------------------------------------------------------------')
 
-print 'Create a test space'
+print('Create a test space')
 master.admin("_ = box.schema.space.create('test')")
 master.admin("_ = box.space.test:create_index('primary')")
 master_lsn = master.get_lsn(master.id)
 # Wait changes to propagate to replicas
 for server in cluster:
     server.wait_lsn(master.id, master_lsn)
-    print 'server', server.id, 'is ok'
-print
+    print('server {} is ok'.format(server.id))
+print('')
 
-print 'Insert records'
+print('Insert records')
 for i in range(ROW_N):
     server = cluster[i % REPLICA_N]
     server.admin("box.space.test:insert{%d, %s}" % (i, server.id), silent = True)
-print 'inserted %d records' % ROW_N
-print
+print('inserted {} records'.format(ROW_N))
+print('')
 
-print 'Synchronize'
+print('Synchronize')
 for server1 in cluster:
     for server2 in cluster:
         server1.wait_lsn(server2.id, server2.get_lsn(server2.id))
-    print 'server', server1.id, 'done'
-print 'done'
-print
+    print('server {} done'.format(server1.id))
+print('done')
+print('')
 
-print 'Check data'
+print('Check data')
 for server in cluster:
     cnt = yaml.safe_load(server.admin("box.space.test:len()", silent = True))[0]
-    print 'server', server.id, 'is', cnt == ROW_N and 'ok' or 'not ok'
-print 'Done'
-print
+    print('server {} is {}'.format(server.id, cnt == ROW_N and 'ok' or 'not ok'))
+print('Done')
+print('')
 
-print
-print '----------------------------------------------------------------------'
-print 'Cleanup'
-print '----------------------------------------------------------------------'
+print('')
+print('----------------------------------------------------------------------')
+print('Cleanup')
+print('----------------------------------------------------------------------')
 
 for server in cluster:
     server.stop()
-    print 'server', server.id, 'done'
-print
+    print('server {} done'.format(server.id))
+print('')
 
 master.cleanup()
 master.deploy()
diff --git a/test/replication-py/swap.test.py b/test/replication-py/swap.test.py
index 98eeeea6d..a96b5a117 100644
--- a/test/replication-py/swap.test.py
+++ b/test/replication-py/swap.test.py
@@ -15,18 +15,18 @@ engines = ['memtx', 'vinyl']
 def insert_tuples(_server, begin, end, msg = "tuple"):
     for engine in engines:
         for i in range(begin, end):
-            print 'box.space.%s:insert{%d, "%s %d"}' % (engine, i, msg, i)
-            print '-'
+            print('box.space.%s:insert{%d, "%s %d"}' % (engine, i, msg, i))
+            print('-')
             space = _server.iproto.py_con.space(engine)
-            print space.insert((i, '%s %d' % (msg, i)))
+            print(space.insert((i, '%s %d' % (msg, i))))
 
 def select_tuples(_server, begin, end):
     for engine in engines:
         for i in range(begin, end):
-            print 'box.space.%s:select{%d}' % (engine, i)
-            print '-'
+            print('box.space.%s:select{%d}' % (engine, i))
+            print('-')
             space = _server.iproto.py_con.space(engine)
-            print space.select(i)
+            print(space.select(i))
 
 # master server
 master = server
@@ -59,14 +59,14 @@ for engine in engines:
 #host_port = "%s:%s" % master.iproto.uri
 #m = re.search(r'replica/(.*)/.*', status)
 #if not m or m.group(1) != host_port:
-#    print 'invalid box.info.status', status, 'expected host:port', host_port
+#    print('invalid box.info.status', status, 'expected host:port', host_port)
 
 master_id = master.get_param('id')
 replica_id = replica.get_param('id')
 
 id = ID_BEGIN
 for i in range(REPEAT):
-    print "test %d iteration" % i
+    print("test %d iteration" % i)
 
     # insert to master
     insert_tuples(master, id, id + ID_STEP)
@@ -82,7 +82,7 @@ for i in range(REPEAT):
     select_tuples(replica, id, id + ID_STEP)
     id += ID_STEP
 
-    print "swap servers"
+    print("swap servers")
     # reconfigure replica to master
     replica.rpl_master = None
     print("switch replica to master")
@@ -106,7 +106,7 @@ for i in range(REPEAT):
     select_tuples(master, id, id + ID_STEP)
     id += ID_STEP
 
-    print "rollback servers configuration"
+    print("rollback servers configuration")
     # reconfigure replica to master
     master.rpl_master = None
     print("switch master to master")
diff --git a/test/xlog-py/dup_key.test.py b/test/xlog-py/dup_key.test.py
index 7609c9555..0b11c863d 100644
--- a/test/xlog-py/dup_key.test.py
+++ b/test/xlog-py/dup_key.test.py
@@ -26,7 +26,7 @@ server.stop()
 
 # Save wal#1
 if os.access(wal, os.F_OK):
-    print ".xlog exists"
+    print(".xlog exists")
     os.rename(wal, wal_old)
 
 # Write wal#2
@@ -37,16 +37,16 @@ server.stop()
 
 # Restore wal#1
 if not os.access(wal, os.F_OK):
-    print ".xlog does not exist"
+    print(".xlog does not exist")
     os.rename(wal_old, wal)
 
 server.start()
 line = 'Duplicate key'
-print "check log line for '%s'" % line
-print
+print("check log line for '%s'" % line)
+print('')
 if server.logfile_pos.seek_once(line) >= 0:
-    print "'%s' exists in server log" % line
-print
+    print("'%s' exists in server log" % line)
+print('')
 
 server.admin("box.space.test:get{1}")
 server.admin("box.space.test:get{2}")
diff --git a/test/xlog-py/empty.test.py b/test/xlog-py/empty.test.py
index d6f89e0fb..f284e2046 100644
--- a/test/xlog-py/empty.test.py
+++ b/test/xlog-py/empty.test.py
@@ -20,7 +20,7 @@ f.close()
 server.start()
 server.stop()
 if os.access(filename, os.F_OK):
-    print ".xlog exists"
+    print(".xlog exists")
 # the server has started but is crippled since it
 # can't override an existing file
 server.start()
diff --git a/test/xlog-py/lsn_gap.test.py b/test/xlog-py/lsn_gap.test.py
index 7a503ff07..d16198756 100644
--- a/test/xlog-py/lsn_gap.test.py
+++ b/test/xlog-py/lsn_gap.test.py
@@ -28,11 +28,11 @@ os.unlink(wal)
 
 server.start()
 line="ignoring a gap in LSN"
-print "check log line for '%s'" % line
-print
+print("check log line for '%s'" % line)
+print('')
 if server.logfile_pos.seek_once(line) >= 0:
-    print "'%s' exists in server log" % line
-print
+    print("'%s' exists in server log" % line)
+print('')
 
 # missing tuple from removed xlog
 server.admin("box.space.test:select{}")
diff --git a/test/xlog-py/misc.test.py b/test/xlog-py/misc.test.py
index e39ae1495..8dd2e2516 100644
--- a/test/xlog-py/misc.test.py
+++ b/test/xlog-py/misc.test.py
@@ -11,9 +11,9 @@ server.stop()
 
 data_path = os.path.join(server.vardir, server.name)
 
-print """
+print("""
 # xlog file must exist after inserts.
-"""
+""")
 filename = str(lsn).zfill(20) + ".xlog"
 wal = os.path.join(data_path, filename)
 
@@ -21,16 +21,16 @@ server.start()
 
 server.admin("space = box.schema.space.create('tweedledum')")
 if os.access(wal, os.F_OK):
-  print ".xlog exists"
+  print(".xlog exists")
 
 server.admin("index = space:create_index('primary', { type = 'hash' })")
 
 server.stop()
 lsn += 2
 
-print """
+print("""
 # a new xlog must be opened after regular termination.
-"""
+""")
 filename = str(lsn).zfill(20) + ".xlog"
 server.start()
 
@@ -39,17 +39,17 @@ wal = os.path.join(data_path, filename)
 server.admin("box.space.tweedledum:insert{3, 'third tuple'}")
 
 if os.access(wal, os.F_OK):
-  print "a new .xlog exists"
+  print("a new .xlog exists")
 
 server.stop()
 
 if os.access(wal, os.F_OK):
-  print ".xlog stays around after sutdown"
+  print(".xlog stays around after sutdown")
 lsn += 1
 
-print """
+print("""
 # An xlog file with one record during recovery.
-"""
+""")
 
 server.start()
 filename = str(lsn).zfill(20) + ".xlog"
@@ -63,7 +63,7 @@ if pid > 0:
 server.stop()
 
 if os.access(wal, os.F_OK):
-    print ".xlog exists after kill -9"
+    print(".xlog exists after kill -9")
     # Remove last byte from xlog
     f = open(wal, "a")
     size = f.tell()
@@ -73,7 +73,7 @@ if os.access(wal, os.F_OK):
 server.start()
 
 if os.access(wal, os.F_OK):
-  print "corrupt .xlog exists after start"
+  print("corrupt .xlog exists after start")
 server.stop()
 lsn += 1
 
@@ -98,4 +98,4 @@ for f in os.listdir(data_path):
 server.start()
 lsn = int(yaml.safe_load(admin("box.info.lsn", silent=True))[0])
 if lsn == orig_lsn:
-    print ".snap.inprogress is ignored"
+    print(".snap.inprogress is ignored")
diff --git a/test/xlog-py/missing.test.py b/test/xlog-py/missing.test.py
index df35dc6d7..f30c331e5 100644
--- a/test/xlog-py/missing.test.py
+++ b/test/xlog-py/missing.test.py
@@ -34,11 +34,11 @@ os.unlink(wal)
 # this may lead to infinite recursion at start
 server.start()
 line="ignoring a gap in LSN"
-print "check log line for '%s'" % line
-print
+print("check log line for '%s'" % line)
+print('')
 if server.logfile_pos.seek_once(line) >= 0:
-    print "'%s' exists in server log" % line
-print
+    print("'%s' exists in server log" % line)
+print('')
 
 # missing tuples from removed xlog
 server.admin("box.space.test:select{}")
-- 
2.25.1

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-12-08 18:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-21  9:44 [Tarantool-patches] [PATCH v1] Support to run tests with Python 3 sergeyb
2020-12-01 17:03 ` Leonid Vasiliev
2020-12-06 17:43   ` Sergey Bronnikov
2020-12-08 18:04     ` Alexander Turenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox