py3: Fix http server request handler wfile write parameter
BaseHTTPServer.BaseHTTPRequestHandler.wfile.write requires encoded bytes. The purpose of this commit is to unblock sanity on centos8 branch. The main test was sysinv periodic audit function receiving the correct response when querying the software patching status. If there are any inconsistencies of encoding schemes between components they will be discovered and fixed later. Story: 2008454 Task: 42727 Signed-off-by: Dan Voiculeasa <dan.voiculeasa@windriver.com> Change-Id: I5f288cf85f42cb98b4211f6b9d836fafcf19e31b
This commit is contained in:
parent
0f9b521672
commit
56dfd11348
|
@ -816,7 +816,7 @@ class NFVIComputeAPI(nfvi.api.v1.NFVIComputeAPI):
|
|||
request_dispatch.send_header(key, value)
|
||||
request_dispatch.end_headers()
|
||||
if http_body is not None:
|
||||
request_dispatch.wfile.write(http_body)
|
||||
request_dispatch.wfile.write(http_body.encode())
|
||||
request_dispatch.done()
|
||||
DLOG.info("Sent response for request %s." % request_uuid)
|
||||
|
||||
|
|
|
@ -1005,7 +1005,7 @@ class NFVIGuestAPI(nfvi.api.v1.NFVIGuestAPI):
|
|||
if http_payload is not None:
|
||||
request_dispatch.send_header('Content-Type', 'application/json')
|
||||
request_dispatch.end_headers()
|
||||
request_dispatch.wfile.write(json.dumps(http_payload))
|
||||
request_dispatch.wfile.write(json.dumps(http_payload).encode())
|
||||
request_dispatch.done()
|
||||
|
||||
def guest_services_rest_api_get_handler(self, request_dispatch):
|
||||
|
@ -1051,7 +1051,7 @@ class NFVIGuestAPI(nfvi.api.v1.NFVIGuestAPI):
|
|||
if http_payload is not None:
|
||||
request_dispatch.send_header('Content-Type', 'application/json')
|
||||
request_dispatch.end_headers()
|
||||
request_dispatch.wfile.write(json.dumps(http_payload))
|
||||
request_dispatch.wfile.write(json.dumps(http_payload).encode())
|
||||
request_dispatch.done()
|
||||
|
||||
def guest_services_rest_api_patch_handler(self, request_dispatch):
|
||||
|
@ -1184,7 +1184,7 @@ class NFVIGuestAPI(nfvi.api.v1.NFVIGuestAPI):
|
|||
if http_payload is not None:
|
||||
request_dispatch.send_header('Content-Type', 'application/json')
|
||||
request_dispatch.end_headers()
|
||||
request_dispatch.wfile.write(json.dumps(http_payload))
|
||||
request_dispatch.wfile.write(json.dumps(http_payload).encode())
|
||||
request_dispatch.done()
|
||||
|
||||
def register_host_services_query_callback(self, callback):
|
||||
|
|
|
@ -3100,7 +3100,7 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI):
|
|||
if http_payload is not None:
|
||||
request_dispatch.send_header('Content-Type', 'application/json')
|
||||
request_dispatch.end_headers()
|
||||
request_dispatch.wfile.write(json.dumps(http_payload))
|
||||
request_dispatch.wfile.write(json.dumps(http_payload).encode())
|
||||
request_dispatch.done()
|
||||
|
||||
def host_rest_api_get_handler(self, request_dispatch):
|
||||
|
@ -3142,7 +3142,7 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI):
|
|||
if http_payload is not None:
|
||||
request_dispatch.send_header('Content-Type', 'application/json')
|
||||
request_dispatch.end_headers()
|
||||
request_dispatch.wfile.write(json.dumps(http_payload))
|
||||
request_dispatch.wfile.write(json.dumps(http_payload).encode())
|
||||
request_dispatch.done()
|
||||
|
||||
def host_rest_api_patch_handler(self, request_dispatch):
|
||||
|
@ -3274,7 +3274,7 @@ class NFVIInfrastructureAPI(nfvi.api.v1.NFVIInfrastructureAPI):
|
|||
if http_payload is not None:
|
||||
request_dispatch.send_header('Content-Type', 'application/json')
|
||||
request_dispatch.end_headers()
|
||||
request_dispatch.wfile.write(json.dumps(http_payload))
|
||||
request_dispatch.wfile.write(json.dumps(http_payload).encode())
|
||||
request_dispatch.done()
|
||||
|
||||
def host_rest_api_post_handler(self, request_dispatch):
|
||||
|
|
|
@ -51,13 +51,13 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
self.send_response(httplib.OK)
|
||||
self.send_header('Content-Type', 'text/html')
|
||||
self.end_headers()
|
||||
self.wfile.write(f.read())
|
||||
self.wfile.write(f.read().encode())
|
||||
elif self.path == '/StarlingX_Icon_RGB_Stacked_2color.png':
|
||||
with open(_webserver_src_dir + '/images' + self.path, 'r') as f:
|
||||
self.send_response(httplib.OK)
|
||||
self.send_header('Content-Type', 'image/x-icon')
|
||||
self.end_headers()
|
||||
self.wfile.write(f.read())
|
||||
self.wfile.write(f.read().encode())
|
||||
|
||||
elif re.search('/vim/overview', self.path) is not None:
|
||||
query_obj = re.match(".*?callback=(.*)&.*", self.path)
|
||||
|
@ -174,7 +174,7 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
self.send_header('Content-Type', 'application/json')
|
||||
self.end_headers()
|
||||
self.wfile.write(
|
||||
query_obj.group(1) + "(" +
|
||||
(query_obj.group(1) + "(" +
|
||||
json.dumps(
|
||||
{'locked_hosts': locked_hosts,
|
||||
'unlocked_hosts': unlocked_hosts,
|
||||
|
@ -204,7 +204,7 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
'deleted_instances': deleted_instances,
|
||||
'total_instances': total_instances,
|
||||
'datetime': str(datetime.datetime.now())[:-3]
|
||||
}) + ")")
|
||||
}) + ")").encode())
|
||||
else:
|
||||
self.send_response(httplib.BAD_REQUEST,
|
||||
'Bad Request: does not exist')
|
||||
|
@ -243,7 +243,7 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
self.send_header('Content-Type', 'application/json')
|
||||
self.end_headers()
|
||||
self.wfile.write(
|
||||
query_obj.group(1) + "(" +
|
||||
(query_obj.group(1) + "(" +
|
||||
json.dumps(
|
||||
{'critical_alarms': critical_alarms,
|
||||
'major_alarms': major_alarms,
|
||||
|
@ -251,7 +251,7 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
'warning_alarms': warning_alarms,
|
||||
'indeterminate_alarms': indeterminate_alarms,
|
||||
'datetime': str(datetime.datetime.now())[:-3]
|
||||
}) + ")")
|
||||
}) + ")").encode())
|
||||
else:
|
||||
self.send_response(httplib.BAD_REQUEST,
|
||||
'Bad Request: does not exist')
|
||||
|
@ -269,8 +269,9 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
self.send_response(httplib.OK)
|
||||
self.send_header('Content-Type', 'application/json')
|
||||
self.end_headers()
|
||||
self.wfile.write(query_obj.group(1) + "(" +
|
||||
json.dumps({'systems': system_list}) + ")")
|
||||
self.wfile.write((query_obj.group(1) + "(" +
|
||||
json.dumps({'systems': system_list}) +
|
||||
")").encode())
|
||||
else:
|
||||
self.send_response(httplib.BAD_REQUEST,
|
||||
'Bad Request: does not exist')
|
||||
|
@ -288,8 +289,9 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
self.send_response(httplib.OK)
|
||||
self.send_header('Content-Type', 'application/json')
|
||||
self.end_headers()
|
||||
self.wfile.write(query_obj.group(1) + "(" +
|
||||
json.dumps({'hosts': host_list}) + ")")
|
||||
self.wfile.write((query_obj.group(1) + "(" +
|
||||
json.dumps({'hosts': host_list}) +
|
||||
")").encode())
|
||||
else:
|
||||
self.send_response(httplib.BAD_REQUEST,
|
||||
'Bad Request: does not exist')
|
||||
|
@ -307,9 +309,9 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
self.send_response(httplib.OK)
|
||||
self.send_header('Content-Type', 'application/json')
|
||||
self.end_headers()
|
||||
self.wfile.write(query_obj.group(1) + "(" +
|
||||
self.wfile.write((query_obj.group(1) + "(" +
|
||||
json.dumps({'host_groups': host_group_list}) +
|
||||
")")
|
||||
")").encode())
|
||||
else:
|
||||
self.send_response(httplib.BAD_REQUEST,
|
||||
'Bad Request: does not exist')
|
||||
|
@ -327,10 +329,10 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
self.send_response(httplib.OK)
|
||||
self.send_header('Content-Type', 'application/json')
|
||||
self.end_headers()
|
||||
self.wfile.write(query_obj.group(1) + "(" +
|
||||
self.wfile.write((query_obj.group(1) + "(" +
|
||||
json.dumps({'host_aggregates':
|
||||
host_aggregate_list}) +
|
||||
")")
|
||||
")").encode())
|
||||
else:
|
||||
self.send_response(httplib.BAD_REQUEST,
|
||||
'Bad Request: does not exist')
|
||||
|
@ -348,9 +350,9 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
self.send_response(httplib.OK)
|
||||
self.send_header('Content-Type', 'application/json')
|
||||
self.end_headers()
|
||||
self.wfile.write(query_obj.group(1) + "(" +
|
||||
self.wfile.write((query_obj.group(1) + "(" +
|
||||
json.dumps({'hypervisors': hypervisor_list}) +
|
||||
")")
|
||||
")").encode())
|
||||
else:
|
||||
self.send_response(httplib.BAD_REQUEST,
|
||||
'Bad Request: does not exist')
|
||||
|
@ -368,9 +370,9 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
self.send_response(httplib.OK)
|
||||
self.send_header('Content-Type', 'application/json')
|
||||
self.end_headers()
|
||||
self.wfile.write(query_obj.group(1) + "(" +
|
||||
self.wfile.write((query_obj.group(1) + "(" +
|
||||
json.dumps({'instances': instance_list}) +
|
||||
")")
|
||||
")").encode())
|
||||
else:
|
||||
self.send_response(httplib.BAD_REQUEST,
|
||||
'Bad Request: does not exist')
|
||||
|
@ -388,10 +390,10 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
self.send_response(httplib.OK)
|
||||
self.send_header('Content-Type', 'application/json')
|
||||
self.end_headers()
|
||||
self.wfile.write(query_obj.group(1) + "(" +
|
||||
self.wfile.write((query_obj.group(1) + "(" +
|
||||
json.dumps({'instance_types':
|
||||
instance_type_list}) +
|
||||
")")
|
||||
")").encode())
|
||||
else:
|
||||
self.send_response(httplib.BAD_REQUEST,
|
||||
'Bad Request: does not exist')
|
||||
|
@ -409,10 +411,10 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
self.send_response(httplib.OK)
|
||||
self.send_header('Content-Type', 'application/json')
|
||||
self.end_headers()
|
||||
self.wfile.write(query_obj.group(1) + "(" +
|
||||
self.wfile.write((query_obj.group(1) + "(" +
|
||||
json.dumps({'instance_groups':
|
||||
instance_group_list}) +
|
||||
")")
|
||||
")").encode())
|
||||
else:
|
||||
self.send_response(httplib.BAD_REQUEST,
|
||||
'Bad Request: does not exist')
|
||||
|
@ -430,9 +432,9 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
self.send_response(httplib.OK)
|
||||
self.send_header('Content-Type', 'application/json')
|
||||
self.end_headers()
|
||||
self.wfile.write(query_obj.group(1) + "(" +
|
||||
self.wfile.write((query_obj.group(1) + "(" +
|
||||
json.dumps({'images': image_list}) +
|
||||
")")
|
||||
")").encode())
|
||||
else:
|
||||
self.send_response(httplib.BAD_REQUEST,
|
||||
'Bad Request: does not exist')
|
||||
|
@ -450,9 +452,9 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
self.send_response(httplib.OK)
|
||||
self.send_header('Content-Type', 'application/json')
|
||||
self.end_headers()
|
||||
self.wfile.write(query_obj.group(1) + "(" +
|
||||
self.wfile.write((query_obj.group(1) + "(" +
|
||||
json.dumps({'volumes': volume_list}) +
|
||||
")")
|
||||
")").encode())
|
||||
else:
|
||||
self.send_response(httplib.BAD_REQUEST,
|
||||
'Bad Request: does not exist')
|
||||
|
@ -470,10 +472,10 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
self.send_response(httplib.OK)
|
||||
self.send_header('Content-Type', 'application/json')
|
||||
self.end_headers()
|
||||
self.wfile.write(query_obj.group(1) + "(" +
|
||||
self.wfile.write((query_obj.group(1) + "(" +
|
||||
json.dumps({'volume_snapshots':
|
||||
volume_snapshot_list}) +
|
||||
")")
|
||||
")").encode())
|
||||
else:
|
||||
self.send_response(httplib.BAD_REQUEST,
|
||||
'Bad Request: does not exist')
|
||||
|
@ -491,9 +493,9 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
self.send_response(httplib.OK)
|
||||
self.send_header('Content-Type', 'application/json')
|
||||
self.end_headers()
|
||||
self.wfile.write(query_obj.group(1) + "(" +
|
||||
self.wfile.write((query_obj.group(1) + "(" +
|
||||
json.dumps({'subnets': subnet_list}) +
|
||||
")")
|
||||
")").encode())
|
||||
else:
|
||||
self.send_response(httplib.BAD_REQUEST,
|
||||
'Bad Request: does not exist')
|
||||
|
@ -511,9 +513,9 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
self.send_response(httplib.OK)
|
||||
self.send_header('Content-Type', 'application/json')
|
||||
self.end_headers()
|
||||
self.wfile.write(query_obj.group(1) + "(" +
|
||||
self.wfile.write((query_obj.group(1) + "(" +
|
||||
json.dumps({'networks': network_list}) +
|
||||
")")
|
||||
")").encode())
|
||||
else:
|
||||
self.send_response(httplib.BAD_REQUEST,
|
||||
'Bad Request: does not exist')
|
||||
|
@ -525,7 +527,7 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
self.send_response(httplib.OK)
|
||||
self.send_header('Content-Type', 'application/font-woff')
|
||||
self.end_headers()
|
||||
self.wfile.write(f.read())
|
||||
self.wfile.write(f.read().encode())
|
||||
|
||||
else:
|
||||
mime_type = 'unsupported'
|
||||
|
@ -563,7 +565,7 @@ class HTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||
self.send_response(httplib.OK)
|
||||
self.send_header('Content-Type', mime_type)
|
||||
self.end_headers()
|
||||
self.wfile.write(f.read())
|
||||
self.wfile.write(f.read().encode())
|
||||
|
||||
|
||||
class ThreadedHTTPServer(socketserver.ThreadingMixIn, BaseHTTPServer.HTTPServer):
|
||||
|
|
Loading…
Reference in New Issue