From 7df54f2f243fd6bb50e71d43a0502db922a810db Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 12 Jun 2017 11:55:05 -0400 Subject: [PATCH] qa/workunits/rest/test_mgr_rest_api.py: tolerate old distros Work with older requests and/or missing urllib3. Signed-off-by: Sage Weil --- qa/workunits/rest/test_mgr_rest_api.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/qa/workunits/rest/test_mgr_rest_api.py b/qa/workunits/rest/test_mgr_rest_api.py index c3521b51664..d6a8f534898 100755 --- a/qa/workunits/rest/test_mgr_rest_api.py +++ b/qa/workunits/rest/test_mgr_rest_api.py @@ -3,10 +3,15 @@ import requests import time import sys +import json -# Do not show the stupid message about verify=False -from requests.packages.urllib3.exceptions import InsecureRequestWarning -requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning) +# Do not show the stupid message about verify=False. ignore exceptions bc +# this doesn't work on some distros. +try: + from requests.packages.urllib3.exceptions import InsecureRequestWarning + requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning) +except: + pass if len(sys.argv) < 3: print("Usage: %s " % sys.argv[0]) @@ -18,7 +23,11 @@ auth = ('admin', sys.argv[2]) request = None # Create a pool and get its id -request = requests.post(addr + '/pool?wait=yes', json={'name': 'supertestfriends', 'pg_num': 128}, verify=False, auth=auth) +request = requests.post( + addr + '/pool?wait=yes', + data=json.dumps({'name': 'supertestfriends', 'pg_num': 128}), + verify=False, + auth=auth) print(request.text) request = requests.get(addr + '/pool', verify=False, auth=auth) assert(request.json()[-1]['pool_name'] == 'supertestfriends') @@ -70,7 +79,11 @@ for method, endpoint, args in screenplay: continue url = addr + endpoint print("URL = " + url) - request = getattr(requests, method)(url, json=args, verify=False, auth=auth) + request = getattr(requests, method)( + url, + data=json.dumps(args), + verify=False, + auth=auth) print(request.text) if request.status_code != 200 or 'error' in request.json(): print('ERROR: %s request for URL "%s" failed' % (method, url)) -- 2.39.5