def handle_end_of_body(self, stream): HttpClient.handle_end_of_body(self, stream) context = stream.opaque extra = context.extra if extra['requests'] <= 0: raise RuntimeError('runner_mlabns: unexpected response') extra['requests'] -= 1 tmp = context.headers.get(CONTENT_TYPE) if context.code != CODE200 or tmp != APPLICATION_JSON: logging.error('runner_mlabns: bad response') stream.close() return content = six.bytes_to_string(context.body.getvalue(), 'utf-8') response = json.loads(content) http_utils.prettyprint_json(response, '<') if extra['policy'] == 'random': RUNNER_HOSTS.set_random_host(response) else: RUNNER_HOSTS.set_closest_host(response) stream.close()
def handle_end_of_body(self, stream): # Note: this function MUST be callable multiple times HttpClient.handle_end_of_body(self, stream) context = stream.opaque extra = context.extra if extra['requests'] <= 0: raise RuntimeError('raw_negotiate: unexpected response') extra['requests'] -= 1 tmp = context.headers.get(CONTENT_TYPE) if context.code != CODE200 or tmp != APPLICATION_JSON: logging.error('raw_negotiate: bad response') stream.close() return response = json.loads(six.u(context.body.getvalue())) http_utils.prettyprint_json(response, '<') if STATE.current == 'negotiate': self._process_negotiate_response(stream, response) elif STATE.current == 'collect': self._process_collect_response(stream, response) else: raise RuntimeError('raw_negotiate: internal error')