Exemplo n.º 1
0
    def connect(*args, **ckwargs):
        if kwargs.get('slow_connect', False):
            eventlet.sleep(0.1)
        if 'give_content_type' in kwargs:
            if len(args) >= 7 and 'Content-Type' in args[6]:
                kwargs['give_content_type'](args[6]['Content-Type'])
            else:
                kwargs['give_content_type']('')
        i, status = next(conn_id_and_code_iter)
        if 'give_connect' in kwargs:
            give_conn_fn = kwargs['give_connect']
            argspec = inspect.getargspec(give_conn_fn)
            if argspec.keywords or 'connection_id' in argspec.args:
                ckwargs['connection_id'] = i
            give_conn_fn(*args, **ckwargs)
        etag = next(etag_iter)
        headers = next(headers_iter)
        expect_headers = next(expect_headers_iter)
        timestamp = next(timestamps_iter)

        if status <= 0:
            raise HTTPException()
        if body_iter is None:
            body = static_body or ''
        else:
            body = next(body_iter)
        return FakeConn(status,
                        etag,
                        body=body,
                        timestamp=timestamp,
                        headers=headers,
                        expect_headers=expect_headers,
                        connection_id=i,
                        give_send=kwargs.get('give_send'),
                        give_expect=kwargs.get('give_expect'))
Exemplo n.º 2
0
 def mock_direct_delete_object(node,
                               part,
                               account,
                               container,
                               obj,
                               conn_timeout=5,
                               response_timeout=15,
                               headers=None):
     resp = "Unable to delete object"
     raise HTTPException('Object', 'DELETE', resp)
Exemplo n.º 3
0
    def connect(*args, **ckwargs):
        if kwargs.get('slow_connect', False):
            eventlet.sleep(0.1)
        if 'give_content_type' in kwargs:
            if len(args) >= 7 and 'Content-Type' in args[6]:
                kwargs['give_content_type'](args[6]['Content-Type'])
            else:
                kwargs['give_content_type']('')
        try:
            i, status = next(conn_id_and_code_iter)
        except StopIteration:
            # the code under test may swallow the StopIteration, so by logging
            # unexpected requests here we allow the test framework to check for
            # them after the connect function has been used.
            unexpected_requests.append((args, ckwargs))
            raise

        if 'give_connect' in kwargs:
            give_conn_fn = kwargs['give_connect']
            argspec = inspect.getargspec(give_conn_fn)
            if argspec.keywords or 'connection_id' in argspec.args:
                ckwargs['connection_id'] = i
            give_conn_fn(*args, **ckwargs)
        etag = next(etag_iter)
        headers = next(headers_iter)
        expect_headers = next(expect_headers_iter)
        timestamp = next(timestamps_iter)

        if isinstance(status, int) and status <= 0:
            raise HTTPException()
        if body_iter is None:
            body = static_body or b''
        else:
            body = next(body_iter)
        conn = FakeConn(status,
                        etag,
                        body=body,
                        timestamp=timestamp,
                        headers=headers,
                        expect_headers=expect_headers,
                        connection_id=i,
                        give_send=kwargs.get('give_send'),
                        give_expect=kwargs.get('give_expect'))
        if 'capture_connections' in kwargs:
            kwargs['capture_connections'].append(conn)
        return conn
Exemplo n.º 4
0
    def test_retry_http_exception(self):
        logger = debug_logger('direct-client-test')

        with mock.patch('swift.common.direct_client.sleep') as mock_sleep, \
                mocked_http_conn(HTTPException('Kaboom!')) as conn:
            with self.assertRaises(HTTPException) as err_ctx:
                direct_client.retry(direct_client.direct_delete_object,
                                    self.node, self.part,
                                    self.account, self.container, self.obj,
                                    retries=2, error_log=logger.error)
        self.assertEqual('DELETE', conn.method)
        self.assertEqual('Kaboom!', str(err_ctx.exception))
        self.assertEqual([mock.call(1), mock.call(2)],
                         mock_sleep.call_args_list)
        error_lines = logger.get_lines_for_level('error')
        self.assertEqual(3, len(error_lines))
        for line in error_lines:
            self.assertIn('Kaboom!', line)