diff options
author | Anirudha Bose <ani07nov@gmail.com> | 2016-08-19 07:47:32 +0200 |
---|---|---|
committer | Anirudha Bose <ani07nov@gmail.com> | 2016-08-19 07:52:27 +0200 |
commit | 5d800fa47db5c7a77c0f55486154031502235904 (patch) | |
tree | 9aae98cbd760f04d75cd10041216cef11578ccdf /qa | |
parent | qa/workunits: Python 3 compat fixes for fs/misc/filelock_deadlock.py (diff) | |
download | ceph-5d800fa47db5c7a77c0f55486154031502235904.tar.xz ceph-5d800fa47db5c7a77c0f55486154031502235904.zip |
qa/workunits: Python 3 compat fixes for rest/test.py
Signed-off-by: Anirudha Bose <ani07nov@gmail.com>
Diffstat (limited to 'qa')
-rwxr-xr-x | qa/workunits/rest/test.py | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/qa/workunits/rest/test.py b/qa/workunits/rest/test.py index c93da1366e9..649e39005fa 100755 --- a/qa/workunits/rest/test.py +++ b/qa/workunits/rest/test.py @@ -1,6 +1,7 @@ #!/usr/bin/python -import exceptions +from __future__ import print_function + import json import os import requests @@ -12,13 +13,15 @@ import xml.etree.ElementTree BASEURL = os.environ.get('BASEURL', 'http://localhost:5000/api/v0.1') + def fail(r, msg): - print >> sys.stderr, 'FAILURE: url ', r.url - print >> sys.stderr, msg - print >> sys.stderr, 'Response content: ', r.content - print >> sys.stderr, 'Headers: ', r.headers + print('FAILURE: url ', r.url, file=sys.stderr) + print(msg, file=sys.stderr) + print('Response content: ', r.text, file=sys.stderr) + print('Headers: ', r.headers, file=sys.stderr) sys.exit(1) + def expect(url, method, respcode, contenttype, extra_hdrs=None, data=None): failmsg, r = expect_nofail(url, method, respcode, contenttype, extra_hdrs, data) @@ -33,7 +36,7 @@ def expect_nofail(url, method, respcode, contenttype, extra_hdrs=None, f = fdict[method.lower()] r = f(BASEURL + '/' + url, headers=extra_hdrs, data=data) - print '{0} {1}: {2} {3}'.format(method, url, contenttype, r.status_code) + print('{0} {1}: {2} {3}'.format(method, url, contenttype, r.status_code)) if r.status_code != respcode: return 'expected {0}, got {1}'.format(respcode, r.status_code), r @@ -52,15 +55,15 @@ def expect_nofail(url, method, respcode, contenttype, extra_hdrs=None, if r_contenttype == 'application/json': try: # older requests.py doesn't create r.myjson; create it myself - r.myjson = json.loads(r.content) - assert(r.myjson != None) + r.myjson = json.loads(r.text) + assert(r.myjson is not None) except Exception as e: return 'Invalid JSON returned: "{0}"'.format(str(e)), r if r_contenttype == 'application/xml': try: # if it's there, squirrel it away for use in the caller - r.tree = xml.etree.ElementTree.fromstring(r.content) + r.tree = xml.etree.ElementTree.fromstring(r.text) except Exception as e: return 'Invalid XML returned: "{0}"'.format(str(e)), r @@ -84,10 +87,10 @@ if __name__ == '__main__': r = expect('auth/export?entity=client.xx', 'GET', 200, 'plain') # must use text/plain; default is application/x-www-form-urlencoded expect('auth/add?entity=client.xx', 'PUT', 200, 'plain', - {'Content-Type':'text/plain'}, data=r.content) + {'Content-Type':'text/plain'}, data=r.text) r = expect('auth/list', 'GET', 200, 'plain') - assert('client.xx' in r.content) + assert('client.xx' in r.text) r = expect('auth/list.json', 'GET', 200, 'json') dictlist = r.myjson['output']['auth_dump'] @@ -114,21 +117,21 @@ if __name__ == '__main__': # export/import/export, compare r = expect('auth/export', 'GET', 200, 'plain') - exp1 = r.content + exp1 = r.text assert('client.xx' in exp1) r = expect('auth/import', 'PUT', 200, 'plain', - {'Content-Type':'text/plain'}, data=r.content) + {'Content-Type':'text/plain'}, data=r.text) r2 = expect('auth/export', 'GET', 200, 'plain') - assert(exp1 == r2.content) + assert(exp1 == r2.text) expect('auth/del?entity=client.xx', 'PUT', 200, 'json', JSONHDR) r = expect('osd/dump', 'GET', 200, 'json', JSONHDR) assert('epoch' in r.myjson['output']) - assert('GLOBAL' in expect('df', 'GET', 200, 'plain').content) - assert('CATEGORY' in expect('df?detail=detail', 'GET', 200, 'plain').content) + assert('GLOBAL' in expect('df', 'GET', 200, 'plain').text) + assert('CATEGORY' in expect('df?detail=detail', 'GET', 200, 'plain').text) # test param with no value (treated as param=param) - assert('CATEGORY' in expect('df?detail', 'GET', 200, 'plain').content) + assert('CATEGORY' in expect('df?detail', 'GET', 200, 'plain').text) r = expect('df', 'GET', 200, 'json', JSONHDR) assert('total_used_bytes' in r.myjson['output']['stats']) @@ -207,7 +210,7 @@ if __name__ == '__main__': expect('mon/dump.xml', 'GET', 200, 'xml') r = expect('mon/getmap', 'GET', 200, '') - assert(len(r.content) != 0) + assert(len(r.text) != 0) r = expect('mon_status.json', 'GET', 200, 'json') assert('name' in r.myjson['output']) r = expect('mon_status.xml', 'GET', 200, 'xml') @@ -243,7 +246,7 @@ if __name__ == '__main__': if r.myjson['output']['osds'][0]['up'] == 1: break else: - print >> sys.stderr, "waiting for osd.0 to come back up" + print("waiting for osd.0 to come back up", file=sys.stderr) time.sleep(10) r = expect('osd/dump', 'GET', 200, 'json', JSONHDR) @@ -340,7 +343,7 @@ if __name__ == '__main__': expect('pg/dump_stuck?stuckops=stale', 'GET', 200, '') r = expect('pg/getmap', 'GET', 200, '') - assert(len(r.content) != 0) + assert(len(r.text) != 0) r = expect('pg/map?pgid=0.0', 'GET', 200, 'json', JSONHDR) assert('acting' in r.myjson['output']) @@ -384,12 +387,12 @@ if __name__ == '__main__': assert(r.tree.find('output/status/osdmap') is not None) r = expect('tell/osd.0/version', 'GET', 200, '') - assert('ceph version' in r.content) + assert('ceph version' in r.text) expect('tell/osd.999/version', 'GET', 400, '') expect('tell/osd.foo/version', 'GET', 400, '') r = expect('tell/osd.0/dump_pg_recovery_stats', 'GET', 200, '') - assert('Started' in r.content) + assert('Started' in r.text) expect('osd/reweight?id=0&weight=0.9', 'PUT', 200, '') expect('osd/reweight?id=0&weight=-1', 'PUT', 400, '') @@ -414,4 +417,4 @@ if __name__ == '__main__': r = expect('osd/pool/get.json?pool=rbd&var=crush_ruleset', 'GET', 200, 'json') assert(r.myjson['output']['crush_ruleset'] == 0) - print 'OK' + print('OK') |