예제 #1
0
    def test_retry_with_max_retries(self):
        responses = [error_util.SessionOverLoadException(None),
                     error_util.SessionOverLoadException(None),
                     error_util.SessionOverLoadException(None)]

        def func(*args, **kwargs):
            response = responses.pop(0)
            if isinstance(response, Exception):
                raise response
            return response

        retry = api.Retry(2, 0, 0, (error_util.SessionOverLoadException,))
        self.assertRaises(error_util.SessionOverLoadException, retry(func))
        self.assertTrue(retry._retry_count == 2)
예제 #2
0
    def test_retry_with_expected_exceptions(self):
        result = "RESULT"
        responses = [error_util.SessionOverLoadException(None),
                     error_util.SessionOverLoadException(None),
                     result]

        def func(*args, **kwargs):
            response = responses.pop(0)
            if isinstance(response, Exception):
                raise response
            return response

        sleep_time_incr = 0.01
        retry_count = 2
        retry = api.Retry(10, sleep_time_incr, 10,
                          (error_util.SessionOverLoadException,))
        self.assertEqual(result, retry(func)())
        self.assertTrue(retry._retry_count == retry_count)
        self.assertEqual(retry_count * sleep_time_incr, retry._sleep_time)
예제 #3
0
        def vim_request_handler(managed_object, **kwargs):
            """Handler for VI SDK calls.

            Builds the SOAP message and parses the response for fault
            checking and other errors.

            :param managed_object:Managed object reference
            :param kwargs: Keyword arguments of the call
            :return: Response of the API call
            """

            try:
                if isinstance(managed_object, str):
                    # For strings use string value for value and type
                    # of the managed object.
                    managed_object = get_moref(managed_object, managed_object)
                request = getattr(self.client.service, attr_name)
                response = request(managed_object, **kwargs)
                if (attr_name.lower() == 'retrievepropertiesex'):
                    retrieve_properties_ex_fault_checker(response)
                return response

            except error_util.VimFaultException as excep:
                raise

            except suds.WebFault as excep:
                doc = excep.document
                detail = doc.childAtPath('/Envelope/Body/Fault/detail')
                fault_list = []
                for child in detail.getChildren():
                    fault_list.append(child.get('type'))
                raise error_util.VimFaultException(fault_list, excep)

            except AttributeError as excep:
                raise error_util.VimAttributeException(
                    _("No such SOAP method "
                      "%(attr)s. Detailed "
                      "error: %(excep)s.") % {
                          'attr': attr_name,
                          'excep': excep
                      })

            except (httplib.CannotSendRequest, httplib.ResponseNotReady,
                    httplib.CannotSendHeader) as excep:
                raise error_util.SessionOverLoadException(
                    _("httplib error in "
                      "%(attr)s: "
                      "%(excep)s.") % {
                          'attr': attr_name,
                          'excep': excep
                      })

            except (urllib2.URLError, urllib2.HTTPError) as excep:
                raise error_util.VimConnectionException(
                    _("urllib2 error in %(attr)s: %(excep)s.") % {
                        'attr': attr_name,
                        'excep': excep
                    })

            except Exception as excep:
                # Socket errors which need special handling for they
                # might be caused by server API call overload
                if (str(excep).find(ADDRESS_IN_USE_ERROR) != -1
                        or str(excep).find(CONN_ABORT_ERROR)) != -1:
                    raise error_util.SessionOverLoadException(
                        _("Socket error "
                          "in %(attr)s: "
                          "%(excep)s.") % {
                              'attr': attr_name,
                              'excep': excep
                          })
                # Type error that needs special handling for it might be
                # caused by server API call overload
                elif str(excep).find(RESP_NOT_XML_ERROR) != -1:
                    raise error_util.SessionOverLoadException(
                        _("Type error "
                          "in %(attr)s: "
                          "%(excep)s.") % {
                              'attr': attr_name,
                              'excep': excep
                          })
                else:
                    raise error_util.VimException(
                        _("Error in %(attr)s. "
                          "Detailed error: "
                          "%(excep)s.") % {
                              'attr': attr_name,
                              'excep': excep
                          })