def test_throttled_call_timeout(self, mock_sleep):
     """Test throttle_call with timeout"""
     mock_func = MagicMock()
     boto_server_error = BotoServerError('error', None)
     boto_server_error.error_code = "Throttling"
     mock_func.side_effect = boto_server_error
     self.assertRaises(BotoServerError, throttled_call, mock_func)
 def test_throttled_call_error(self, mock_sleep):
     """Test throttle_call with error"""
     mock_func = MagicMock()
     boto_server_error = BotoServerError('error', None)
     boto_server_error.error_code = "MyError"
     mock_func.side_effect = boto_server_error
     self.assertRaises(BotoServerError, throttled_call, mock_func)
     self.assertEqual(1, mock_func.call_count)
 def test_throttled_call_noerr(self, mock_sleep):
     """Test throttle_call with no error"""
     mock_func = MagicMock()
     boto_server_error = BotoServerError('error', None)
     boto_server_error.error_code = "Throttling"
     mock_func.side_effect = [boto_server_error, boto_server_error, True]
     throttled_call(mock_func)
     self.assertEqual(3, mock_func.call_count)
예제 #4
0
    def test_check_access(self):
        elb = mock.Mock()
        botoerror = BotoServerError('Fail', 'Unit test')
        botoerror.error_code = 'AccessDenied'
        elb.set_listener_SSL_certificate = mock.Mock(side_effect=botoerror)

        actor = elb_actor.SetCert('Unit Test', {
            'name': 'unit-test',
            'region': 'us-east-1',
            'cert_name': 'unit-cert'
        })

        # AccessDenied means check has failed.
        with self.assertRaises(exceptions.UnrecoverableActorFailure):
            yield actor._check_access(elb)

        # Anything else means the check has passed.
        botoerror.error_code = 'Cert Not Found'
        yield actor._check_access(elb)
예제 #5
0
    def test_check_access(self):
        elb = mock.Mock()
        botoerror = BotoServerError('Fail', 'Unit test')
        botoerror.error_code = 'AccessDenied'
        elb.set_listener_SSL_certificate = mock.Mock(
            side_effect=botoerror)

        actor = elb_actor.SetCert(
            'Unit Test', {'name': 'unit-test',
                          'region': 'us-east-1',
                          'cert_name': 'unit-cert'}
        )

        # AccessDenied means check has failed.
        with self.assertRaises(exceptions.UnrecoverableActorFailure):
            yield actor._check_access(elb)

        # Anything else means the check has passed.
        botoerror.error_code = 'Cert Not Found'
        yield actor._check_access(elb)
예제 #6
0
def boto_error_handler(request, location=None, template="{0}"):
    try:
        yield
    except ClientError as err:
        old_err = BotoServerError(
            status=err.response.get('ResponseMetadata').get('HTTPStatusCode'),
            reason=err.response.get('Error').get('Code')
        )
        old_err.message = err.response.get('Error').get('Message')
        old_err.error_code = err.response.get('Error').get('Code')
        BaseView.handle_error(err=old_err, request=request, location=location, template=template)
    except BotoServerError as err:
        BaseView.handle_error(err=err, request=request, location=location, template=template)
    except socket.error as err:
        BaseView.handle_error(err=BotoServerError(504, str(err)), request=request, location=location, template=template)
예제 #7
0
def create_server_error(code):
    err = BotoServerError('', '', '')
    err.error_code = code
    return err