def _send_cmd(self, request_func, success_msgs, *args): """Run an XG request function, and retry as needed. The request will be retried until it returns a success message, a failure message, or the global request timeout is hit. This wrapper is meant to deal with backend requests that can fail for any variety of reasons, for instance, when the system is already busy handling other LUN requests. It is also smart enough to give up if clustering is down (eg no HA available), there is no space left, or other "fatal" errors are returned (see _fatal_error_code() for a list of all known error conditions). Arguments: request_func -- XG api method to call success_msgs -- Success messages expected from the backend *args -- argument array to be passed to the request_func Returns: The response dict from the last XG call. """ resp = {} start = time.time() done = False if isinstance(success_msgs, six.string_types): success_msgs = [success_msgs] while not done: if time.time() - start >= self.config.request_timeout: raise exception.ViolinRequestRetryTimeout( timeout=self.config.request_timeout) resp = request_func(*args) if not resp['message']: # XG requests will return None for a message if no message # string is passed in the raw response resp['message'] = '' for msg in success_msgs: if not resp['code'] and msg in resp['message']: done = True break self._fatal_error_code(resp) return resp
def _send_cmd(self, request_func, success_msgs, *args, **kwargs): """Run an XG request function, and retry as needed. The request will be retried until it returns a success message, a failure message, or the global request timeout is hit. This wrapper is meant to deal with backend requests that can fail for any variety of reasons, for instance, when the system is already busy handling other LUN requests. If there is no space left, or other "fatal" errors are returned (see _fatal_error_code() for a list of all known error conditions). :param request_func: XG api method to call :param success_msgs: Success messages expected from the backend :param *args: argument array to be passed to the request_func :param **kwargs: argument dictionary to be passed to request_func :returns: the response dict from the last XG call """ resp = {} start = time.time() done = False if isinstance(success_msgs, six.string_types): success_msgs = [success_msgs] while not done: if time.time() - start >= self.config.violin_request_timeout: raise exception.ViolinRequestRetryTimeout( timeout=self.config.violin_request_timeout) resp = request_func(*args, **kwargs) if not resp['msg']: # XG requests will return None for a message if no message # string is passed in the raw response resp['msg'] = '' for msg in success_msgs: if resp['success'] and msg in resp['msg']: done = True break if not resp['success']: self._check_error_code(resp) done = True break return resp
def _send_cmd_and_verify(self, request_func, verify_func, request_success_msgs, rargs=None, vargs=None): """Run an XG request function, retry if needed, and verify success. If the verification fails, then retry the request/verify cycle until both functions are successful, the request function returns a failure message, or the global request timeout is hit. This wrapper is meant to deal with backend requests that can fail for any variety of reasons, for instance, when the system is already busy handling other LUN requests. It is also smart enough to give up if clustering is down (eg no HA available), there is no space left, or other "fatal" errors are returned (see _fatal_error_code() for a list of all known error conditions). Arguments: request_func -- XG api method to call verify_func -- function to call to verify request was completed successfully (eg for export) request_success_msg -- Success message expected from the backend for the request_func rargs -- argument array to be passed to the request_func vargs -- argument array to be passed to the verify_func Returns: The response dict from the last XG call. """ resp = {} start = time.time() request_needed = True verify_needed = True if isinstance(request_success_msgs, six.string_types): request_success_msgs = [request_success_msgs] rargs = rargs if rargs else [] vargs = vargs if vargs else [] while request_needed or verify_needed: if time.time() - start >= self.config.request_timeout: raise exception.ViolinRequestRetryTimeout( timeout=self.config.request_timeout) if request_needed: resp = request_func(*rargs) if not resp['message']: # XG requests will return None for a message if no message # string is passed int the raw response resp['message'] = '' for msg in request_success_msgs: if not resp['code'] and msg in resp['message']: # XG request func was completed request_needed = False break self._fatal_error_code(resp) elif verify_needed: success = verify_func(*vargs) if success: # XG verify func was completed verify_needed = False else: # try sending the request again request_needed = True return resp