def test_api_version_is_not_null(self): api_version = api_versions.APIVersion("2.3") headers = {} api_versions.update_headers(headers, api_version) self.assertEqual( {"OpenStack-API-Version": "volume " + api_version.get_string()}, headers)
def request(self, url, method, **kwargs): kwargs.setdefault('headers', kwargs.get('headers', {})) kwargs['headers']['User-Agent'] = self.USER_AGENT kwargs['headers']['Accept'] = 'application/json' if osprofiler_web: kwargs['headers'].update(osprofiler_web.get_trace_id_headers()) if 'body' in kwargs: kwargs['headers']['Content-Type'] = 'application/json' kwargs['data'] = json.dumps(kwargs['body']) del kwargs['body'] api_versions.update_headers(kwargs["headers"], self.api_version) if self.timeout: kwargs.setdefault('timeout', self.timeout) self.http_log_req((url, method,), kwargs) resp = requests.request( method, url, verify=self.verify_cert, **kwargs) self.http_log_resp(resp) body = None if resp.text: try: body = json.loads(resp.text) except ValueError as e: self._logger.debug("Load http response text error: %s", e) if resp.status_code >= 400: raise exceptions.from_response(resp, body) return resp, body
def test_api_version_is_not_null(self): api_version = api_versions.APIVersion("2.3") headers = {} api_versions.update_headers(headers, api_version) self.assertEqual( {"OpenStack-API-Version": "volume " + api_version.get_string()}, headers)
def request(self, url, method, **kwargs): kwargs.setdefault('headers', kwargs.get('headers', {})) kwargs['headers']['User-Agent'] = self.USER_AGENT kwargs['headers']['Accept'] = 'application/json' if osprofiler_web: kwargs['headers'].update(osprofiler_web.get_trace_id_headers()) if 'body' in kwargs: kwargs['headers']['Content-Type'] = 'application/json' kwargs['data'] = json.dumps(kwargs.pop('body')) api_versions.update_headers(kwargs["headers"], self.api_version) if self.timeout: kwargs.setdefault('timeout', self.timeout) self.http_log_req(( url, method, ), kwargs) resp = requests.request(method, url, verify=self.verify_cert, **kwargs) self.http_log_resp(resp) body = None if resp.text: try: body = json.loads(resp.text) except ValueError as e: self._logger.debug("Load http response text error: %s", e) if resp.status_code >= 400: raise exceptions.from_response(resp, body) return resp, body
def request(self, url, method, **kwargs): kwargs.setdefault("headers", kwargs.get("headers", {})) kwargs["headers"]["User-Agent"] = self.USER_AGENT kwargs["headers"]["Accept"] = "application/json" if osprofiler_web: kwargs["headers"].update(osprofiler_web.get_trace_id_headers()) if "body" in kwargs: kwargs["headers"]["Content-Type"] = "application/json" kwargs["data"] = json.dumps(kwargs.pop("body")) api_versions.update_headers(kwargs["headers"], self.api_version) if self.timeout: kwargs.setdefault("timeout", self.timeout) self.http_log_req((url, method), kwargs) resp = requests.request(method, url, verify=self.verify_cert, **kwargs) self.http_log_resp(resp) body = None if resp.text: try: body = json.loads(resp.text) except ValueError as e: self._logger.debug("Load http response text error: %s", e) if resp.status_code >= 400: raise exceptions.from_response(resp, body) return resp, body
def request(self, *args, **kwargs): kwargs.setdefault('headers', kwargs.get('headers', {})) api_versions.update_headers(kwargs["headers"], self.api_version) kwargs.setdefault('authenticated', False) # Note(tpatil): The standard call raises errors from # keystoneclient, here we need to raise the cinderclient errors. raise_exc = kwargs.pop('raise_exc', True) resp, body = super(SessionClient, self).request(*args, raise_exc=False, **kwargs) if raise_exc and resp.status_code >= 400: raise exceptions.from_response(resp, body) return resp, body
def request(self, *args, **kwargs): kwargs.setdefault('headers', kwargs.get('headers', {})) api_versions.update_headers(kwargs["headers"], self.api_version) kwargs.setdefault('authenticated', False) # Note(tpatil): The standard call raises errors from # keystoneclient, here we need to raise the cinderclient errors. raise_exc = kwargs.pop('raise_exc', True) resp, body = super(SessionClient, self).request(*args, raise_exc=False, **kwargs) if raise_exc and resp.status_code >= 400: raise exceptions.from_response(resp, body) return resp, body
def request(self, *args, **kwargs): kwargs.setdefault("headers", kwargs.get("headers", {})) api_versions.update_headers(kwargs["headers"], self.api_version) kwargs.setdefault("authenticated", False) # Note(tpatil): The standard call raises errors from # keystoneauth, here we need to raise the cinderclient errors. raise_exc = kwargs.pop("raise_exc", True) resp, body = super(SessionClient, self).request(*args, raise_exc=False, **kwargs) # if service name is None then use service_type for logging service = self.service_name or self.service_type _log_request_id(self._logger, resp, service) if raise_exc and resp.status_code >= 400: raise exceptions.from_response(resp, body) return resp, body
def test_api_version_is_major(self): headers = {} api_versions.update_headers(headers, api_versions.APIVersion("7.0")) self.assertEqual({}, headers)
def test_api_version_is_null(self): headers = {} api_versions.update_headers(headers, api_versions.APIVersion()) self.assertEqual({}, headers)
def test_api_version_is_major(self): headers = {} api_versions.update_headers(headers, api_versions.APIVersion("7.0")) self.assertEqual({}, headers)
def test_api_version_is_null(self): headers = {} api_versions.update_headers(headers, api_versions.APIVersion()) self.assertEqual({}, headers)