test/(functional/probe):Replace python print operator with print function (pep H233, py33)

'print' function is compatible with 2.x and 3.x python versions
Link : https://www.python.org/dev/peps/pep-3105/

Python 2.6 has a __future__ import that removes print as language syntax,
letting you use the functional form instead

Change-Id: I416c6ac21ccbfb91ec328ffb1ed21e492ef52d58
This commit is contained in:
janonymous 2015-07-28 20:35:25 +05:30 committed by Hisashi Osanai
parent a19443de3b
commit 923238aa1b
4 changed files with 36 additions and 38 deletions

View File

@ -15,7 +15,7 @@
# See http://code.google.com/p/python-nose/issues/detail?id=373 # See http://code.google.com/p/python-nose/issues/detail?id=373
# The code below enables nosetests to work with i18n _() blocks # The code below enables nosetests to work with i18n _() blocks
from __future__ import print_function
import sys import sys
import os import os
try: try:
@ -63,15 +63,12 @@ def get_config(section_name=None, defaults=None):
config = readconf(config_file, section_name) config = readconf(config_file, section_name)
except SystemExit: except SystemExit:
if not os.path.exists(config_file): if not os.path.exists(config_file):
print >>sys.stderr, \ print('Unable to read test config %s - file not found'
'Unable to read test config %s - file not found' \ % config_file, file=sys.stderr)
% config_file
elif not os.access(config_file, os.R_OK): elif not os.access(config_file, os.R_OK):
print >>sys.stderr, \ print('Unable to read test config %s - permission denied'
'Unable to read test config %s - permission denied' \ % config_file, file=sys.stderr)
% config_file
else: else:
print >>sys.stderr, \ print('Unable to read test config %s - section %s not found'
'Unable to read test config %s - section %s not found' \ % (config_file, section_name), file=sys.stderr)
% (config_file, section_name)
return config return config

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from __future__ import print_function
import mock import mock
import os import os
import sys import sys
@ -128,7 +129,7 @@ class InProcessException(BaseException):
def _info(msg): def _info(msg):
print >> sys.stderr, msg print(msg, file=sys.stderr)
def _debug(msg): def _debug(msg):
@ -501,7 +502,7 @@ def get_cluster_info():
# Most likely the swift cluster has "expose_info = false" set # Most likely the swift cluster has "expose_info = false" set
# in its proxy-server.conf file, so we'll just do the best we # in its proxy-server.conf file, so we'll just do the best we
# can. # can.
print >>sys.stderr, "** Swift Cluster not exposing /info **" print("** Swift Cluster not exposing /info **", file=sys.stderr)
# Finally, we'll allow any constraint present in the swift-constraints # Finally, we'll allow any constraint present in the swift-constraints
# section of test.conf to override everything. Note that only those # section of test.conf to override everything. Note that only those
@ -513,8 +514,8 @@ def get_cluster_info():
except KeyError: except KeyError:
pass pass
except ValueError: except ValueError:
print >>sys.stderr, "Invalid constraint value: %s = %s" % ( print("Invalid constraint value: %s = %s" % (
k, test_constraints[k]) k, test_constraints[k]), file=sys.stderr)
eff_constraints.update(test_constraints) eff_constraints.update(test_constraints)
# Just make it look like these constraints were loaded from a /info call, # Just make it look like these constraints were loaded from a /info call,
@ -564,8 +565,8 @@ def setup_package():
in_process_setup(the_object_server=( in_process_setup(the_object_server=(
mem_object_server if in_mem_obj else object_server)) mem_object_server if in_mem_obj else object_server))
except InProcessException as exc: except InProcessException as exc:
print >> sys.stderr, ('Exception during in-process setup: %s' print(('Exception during in-process setup: %s'
% str(exc)) % str(exc)), file=sys.stderr)
raise raise
global web_front_end global web_front_end
@ -674,20 +675,19 @@ def setup_package():
global skip global skip
skip = not all([swift_test_auth, swift_test_user[0], swift_test_key[0]]) skip = not all([swift_test_auth, swift_test_user[0], swift_test_key[0]])
if skip: if skip:
print >>sys.stderr, 'SKIPPING FUNCTIONAL TESTS DUE TO NO CONFIG' print('SKIPPING FUNCTIONAL TESTS DUE TO NO CONFIG', file=sys.stderr)
global skip2 global skip2
skip2 = not all([not skip, swift_test_user[1], swift_test_key[1]]) skip2 = not all([not skip, swift_test_user[1], swift_test_key[1]])
if not skip and skip2: if not skip and skip2:
print >>sys.stderr, \ print('SKIPPING SECOND ACCOUNT FUNCTIONAL TESTS '
'SKIPPING SECOND ACCOUNT FUNCTIONAL TESTS' \ 'DUE TO NO CONFIG FOR THEM', file=sys.stderr)
' DUE TO NO CONFIG FOR THEM'
global skip3 global skip3
skip3 = not all([not skip, swift_test_user[2], swift_test_key[2]]) skip3 = not all([not skip, swift_test_user[2], swift_test_key[2]])
if not skip and skip3: if not skip and skip3:
print >>sys.stderr, \ print('SKIPPING THIRD ACCOUNT FUNCTIONAL TESTS'
'SKIPPING THIRD ACCOUNT FUNCTIONAL TESTS DUE TO NO CONFIG FOR THEM' 'DUE TO NO CONFIG FOR THEM', file=sys.stderr)
global skip_if_not_v3 global skip_if_not_v3
skip_if_not_v3 = (swift_test_auth_version != '3' skip_if_not_v3 = (swift_test_auth_version != '3'
@ -695,16 +695,17 @@ def setup_package():
swift_test_user[3], swift_test_user[3],
swift_test_key[3]])) swift_test_key[3]]))
if not skip and skip_if_not_v3: if not skip and skip_if_not_v3:
print >>sys.stderr, \ print('SKIPPING FUNCTIONAL TESTS SPECIFIC TO AUTH VERSION 3',
'SKIPPING FUNCTIONAL TESTS SPECIFIC TO AUTH VERSION 3' file=sys.stderr)
global skip_service_tokens global skip_service_tokens
skip_service_tokens = not all([not skip, swift_test_user[4], skip_service_tokens = not all([not skip, swift_test_user[4],
swift_test_key[4], swift_test_tenant[4], swift_test_key[4], swift_test_tenant[4],
swift_test_service_prefix]) swift_test_service_prefix])
if not skip and skip_service_tokens: if not skip and skip_service_tokens:
print >>sys.stderr, \ print(
'SKIPPING FUNCTIONAL TESTS SPECIFIC TO SERVICE TOKENS' 'SKIPPING FUNCTIONAL TESTS SPECIFIC TO SERVICE TOKENS',
file=sys.stderr)
if policy_specified: if policy_specified:
policies = FunctionalStoragePolicyCollection.from_info() policies = FunctionalStoragePolicyCollection.from_info()

View File

@ -11,7 +11,7 @@
# implied. # implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from __future__ import print_function
import sys import sys
import itertools import itertools
import uuid import uuid
@ -226,8 +226,8 @@ def main():
try: try:
brain.run(command, *args) brain.run(command, *args)
except ClientException as e: except ClientException as e:
print '**WARNING**: %s raised %s' % (command, e) print('**WARNING**: %s raised %s' % (command, e))
print 'STATUS'.join(['*' * 25] * 2) print('STATUS'.join(['*' * 25] * 2))
brain.servers.status() brain.servers.status()
sys.exit() sys.exit()

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from __future__ import print_function
import os import os
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
import sys import sys
@ -86,9 +86,9 @@ def check_server(ipport, ipport2server, pids, timeout=CHECK_SERVER_TIMEOUT):
break break
except Exception as err: except Exception as err:
if time() > try_until: if time() > try_until:
print err print(err)
print 'Giving up on %s:%s after %s seconds.' % ( print('Giving up on %s:%s after %s seconds.' % (
server, ipport, timeout) server, ipport, timeout))
raise err raise err
sleep(0.1) sleep(0.1)
else: else:
@ -102,8 +102,8 @@ def check_server(ipport, ipport2server, pids, timeout=CHECK_SERVER_TIMEOUT):
return url, token, account return url, token, account
except Exception as err: except Exception as err:
if time() > try_until: if time() > try_until:
print err print(err)
print 'Giving up on proxy:8080 after 30 seconds.' print('Giving up on proxy:8080 after 30 seconds.')
raise err raise err
sleep(0.1) sleep(0.1)
return None return None
@ -258,7 +258,7 @@ def get_policy(**kwargs):
def resetswift(): def resetswift():
p = Popen("resetswift 2>&1", shell=True, stdout=PIPE) p = Popen("resetswift 2>&1", shell=True, stdout=PIPE)
stdout, _stderr = p.communicate() stdout, _stderr = p.communicate()
print stdout print(stdout)
Manager(['all']).stop() Manager(['all']).stop()
@ -407,11 +407,11 @@ if __name__ == "__main__":
force_validate=True) force_validate=True)
except SkipTest as err: except SkipTest as err:
sys.exit('%s ERROR: %s' % (server, err)) sys.exit('%s ERROR: %s' % (server, err))
print '%s OK' % server print('%s OK' % server)
for policy in POLICIES: for policy in POLICIES:
try: try:
get_ring(policy.ring_name, 3, 4, get_ring(policy.ring_name, 3, 4,
server='object', force_validate=True) server='object', force_validate=True)
except SkipTest as err: except SkipTest as err:
sys.exit('object ERROR (%s): %s' % (policy.name, err)) sys.exit('object ERROR (%s): %s' % (policy.name, err))
print 'object OK (%s)' % policy.name print('object OK (%s)' % policy.name)