Ejemplo n.º 1
0
    def resp_exception(self, resp):
        """If we encounter an exception in our upload.

        we will look at how we can attempt to resolve the exception.

        :param resp:
        """

        # Check to make sure we have all the bits needed
        if not hasattr(resp, 'status_code'):
            raise turbo.SystemProblem('No Status to check.')
        elif resp is None:
            raise turbo.SystemProblem('No response information.')
        elif resp.status_code == 401:
            report.reporter(
                msg=('Turbolift experienced an Authentication issue.'
                     ' STATUS %s REASON %s REQUEST %s. Turbolift will retry' %
                     (resp.status_code, resp.reason, resp.request)),
                lvl='warn',
                log=True,
                prt=False)

            # This was done in this manor due to how manager dicts are proxied
            # related : http://bugs.python.org/issue6766
            headers = self.payload['headers']
            headers['X-Auth-Token'] = get_new_token()
            self.payload['headers'] = headers

            raise turbo.AuthenticationProblem(
                'Attempting to resolve the Authentication issue.')
        elif resp.status_code == 404:
            report.reporter(
                msg=('Not found STATUS: %s, REASON: %s, MESSAGE: %s' %
                     (resp.status_code, resp.reason, resp.request)),
                prt=False,
                lvl='debug')
        elif resp.status_code == 413:
            _di = resp.headers
            basic.stupid_hack(wait=_di.get('retry_after', 10))
            raise turbo.SystemProblem(
                'The System encountered an API limitation and will'
                ' continue in "%s" Seconds' % _di.get('retry_after'))
        elif resp.status_code == 502:
            raise turbo.SystemProblem('Failure making Connection')
        elif resp.status_code == 503:
            basic.stupid_hack(wait=10)
            raise turbo.SystemProblem('SWIFT-API FAILURE')
        elif resp.status_code == 504:
            basic.stupid_hack(wait=10)
            raise turbo.SystemProblem('Gateway Time-out')
        elif resp.status_code >= 300:
            raise turbo.SystemProblem(
                'SWIFT-API FAILURE -> REASON %s REQUEST %s' %
                (resp.reason, resp.request))
        else:
            report.reporter(
                msg=('MESSAGE %s %s %s' %
                     (resp.status_code, resp.reason, resp.request)),
                prt=False,
                lvl='debug')
Ejemplo n.º 2
0
    def resp_exception(self, resp):
        """If we encounter an exception in our upload.

        we will look at how we can attempt to resolve the exception.

        :param resp:
        """

        # Check to make sure we have all the bits needed
        if not hasattr(resp, "status_code"):
            raise turbo.SystemProblem("No Status to check.")
        elif resp is None:
            raise turbo.SystemProblem("No response information.")
        elif resp.status_code == 401:
            report.reporter(
                msg=(
                    "Turbolift experienced an Authentication issue."
                    " STATUS %s REASON %s REQUEST %s. Turbolift will retry"
                    % (resp.status_code, resp.reason, resp.request)
                ),
                lvl="warn",
                log=True,
                prt=False,
            )

            # This was done in this manor due to how manager dicts are proxied
            # related : http://bugs.python.org/issue6766
            headers = self.payload["headers"]
            headers["X-Auth-Token"] = get_new_token()
            self.payload["headers"] = headers

            raise turbo.AuthenticationProblem("Attempting to resolve the Authentication issue.")
        elif resp.status_code == 404:
            report.reporter(
                msg=("Not found STATUS: %s, REASON: %s, MESSAGE: %s" % (resp.status_code, resp.reason, resp.request)),
                prt=False,
                lvl="debug",
            )
        elif resp.status_code == 413:
            _di = resp.headers
            basic.stupid_hack(wait=_di.get("retry_after", 10))
            raise turbo.SystemProblem(
                "The System encountered an API limitation and will" ' continue in "%s" Seconds' % _di.get("retry_after")
            )
        elif resp.status_code == 502:
            raise turbo.SystemProblem("Failure making Connection")
        elif resp.status_code == 503:
            basic.stupid_hack(wait=10)
            raise turbo.SystemProblem("SWIFT-API FAILURE")
        elif resp.status_code == 504:
            basic.stupid_hack(wait=10)
            raise turbo.SystemProblem("Gateway Time-out")
        elif resp.status_code >= 300:
            raise turbo.SystemProblem("SWIFT-API FAILURE -> REASON %s REQUEST %s" % (resp.reason, resp.request))
        else:
            report.reporter(
                msg=("MESSAGE %s %s %s" % (resp.status_code, resp.reason, resp.request)), prt=False, lvl="debug"
            )
Ejemplo n.º 3
0
    def resp_exception(self, resp, rty):
        """If we encounter an exception in our upload.

        we will look at how we can attempt to resolve the exception.

        :param resp:
        :param rty:
        """

        try:
            if resp.status == 401:
                report.reporter(
                    msg='MESSAGE: Forced Re-authentication is happening.',
                    lvl='error',
                    log=True
                )
                basic.stupid_hack()
                self.payload['headers']['X-Auth-Token'] = get_new_token()
                rty()
            elif resp.status == 404:
                report.reporter(
                    msg=('Not found STATUS: %s, REASON: %s, MESSAGE: %s'
                         % (resp.status, resp.reason, resp.msg)),
                    prt=False,
                    lvl='debug'
                )
            elif resp.status == 413:
                _di = dict(resp.getheaders())
                basic.stupid_hack(wait=_di.get('retry_after', 10))
                raise turbo.SystemProblem(
                    'The System encountered an API limitation and will'
                    ' continue in "%s" Seconds' % _di.get('retry_after')
                )
            elif resp.status == 502:
                raise turbo.SystemProblem('Failure making Connection')
            elif resp.status == 503:
                basic.stupid_hack(wait=10)
                raise turbo.SystemProblem('SWIFT-API FAILURE')
            elif resp.status == 504:
                basic.stupid_hack(wait=10)
                raise turbo.SystemProblem('Gateway Time-out')
            elif resp.status >= 300:
                raise turbo.SystemProblem('SWIFT-API FAILURE -> REQUEST')
        except turbo.SystemProblem as exp:
            report.reporter(
                msg=('FAIL-MESSAGE %s FAILURE STATUS %s FAILURE REASON %s '
                     'TYPE %s MESSAGE %s' % (exp, resp.status, resp.reason,
                                             resp._method, resp.msg)),
                prt=True,
                lvl='warn',
                log=True
            )
            rty()