def _eval_response(self, response): """Evaluates response before passing result to invoker.""" status_code = int(response.status_code) # codes >= 300 are not ok and to be treated as errors if status_code >= 300: # Response code 422 returns error code and message if status_code == 422: msg = _("Response error - %s.") % response.text else: msg = _("Response error code - %s.") % status_code raise es_exception.WebServiceException(msg, status_code=status_code)
def test_list_volume_v2_failure(self): status_code = http_client.UNPROCESSABLE_ENTITY url = client.RestClient.RESOURCE_PATHS['ssc_volume'] self.my_client.features = mock.Mock() self.my_client.features.SSC_API_V2 = na_utils.FeatureState( supported=True) msg = "Response error code - %s." % status_code self.my_client._invoke = mock.Mock( side_effect=es_exception.WebServiceException( message=msg, status_code=status_code)) self.assertRaises(es_exception.WebServiceException, client.RestClient.list_volume, self.my_client, 'fakeId') self.my_client._invoke.assert_called_once_with( 'GET', url, **{'object-id': mock.ANY})
def _eval_response(self, response): """Evaluates response before passing result to invoker.""" status_code = int(response.status_code) # codes >= 300 are not ok and to be treated as errors if status_code >= 300: # Response code 422 returns error code and message if status_code == 422: msg = _("Response error - %s.") % response.text json_response = response.json() if json_response is not None: ret_code = json_response.get('retcode', '') if ret_code == '30' or ret_code == 'authFailPassword': msg = _("The storage array password for %s is " "incorrect, please update the configured " "password.") % self._system_id else: msg = _("Response error code - %s.") % status_code raise es_exception.WebServiceException(msg, status_code=status_code)