From d2528a5222bd76cdaa8f4ab826134e2f9fe14c15 Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Tue, 5 Feb 2013 16:15:13 +1300 Subject: [PATCH] Remove sendfile as a dependency. This is dead code anyway, since heat-cfn doesn't handle large binary files like glance. Fixes bug 1087530 Change-Id: Iaba7adce088b20136ece0828d4085679fcbab731 --- heat/common/client.py | 75 ++----------------------------------------- tools/pip-requires | 1 - 2 files changed, 2 insertions(+), 74 deletions(-) diff --git a/heat/common/client.py b/heat/common/client.py index b253194e..b9a9d8cb 100644 --- a/heat/common/client.py +++ b/heat/common/client.py @@ -32,12 +32,6 @@ except ImportError: import socket import ssl -try: - import sendfile - SENDFILE_SUPPORTED = True -except ImportError: - SENDFILE_SUPPORTED = False - from heat.common import auth from heat.common import exception, utils @@ -107,48 +101,6 @@ class ImageBodyIterator(object): break -class SendFileIterator: - """ - Emulate iterator pattern over sendfile, in order to allow - send progress be followed by wrapping the iteration. - """ - def __init__(self, connection, body): - self.connection = connection - self.body = body - self.offset = 0 - self.sending = True - - def __iter__(self): - class OfLength: - def __init__(self, len): - self.len = len - - def __len__(self): - return self.len - - while self.sending: - try: - sent = sendfile.sendfile(self.connection.sock.fileno(), - self.body.fileno(), - self.offset, - CHUNKSIZE) - except OSError as e: - # suprisingly, sendfile may fail transiently instead of - # blocking, in which case we select on the socket in order - # to wait on its return to a writeable state before resuming - # the send loop - if e.errno in (errno.EAGAIN, errno.EBUSY): - wlist = [self.connection.sock.fileno()] - rfds, wfds, efds = select.select([], wlist, []) - if wfds: - continue - raise - - self.sending = (sent != 0) - self.offset += sent - yield OfLength(sent) - - class HTTPSClientAuthConnection(httplib.HTTPSConnection): """ Class to make a HTTPS connection, with support for @@ -511,12 +463,7 @@ class BaseClient(object): iter = self.image_iterator(c, headers, body) - if self._sendable(body): - # send actual file without copying into userspace - _sendbody(c, iter) - else: - # otherwise iterate and chunk - _chunkbody(c, iter) + _chunkbody(c, iter) else: raise TypeError('Unsupported image type: %s' % body.__class__) @@ -557,29 +504,11 @@ class BaseClient(object): except (socket.error, IOError), e: raise exception.ClientConnectionError(e) - def _seekable(self, body): - # pipes are not seekable, avoids sendfile() failure on e.g. - # cat /path/to/image | heat add ... - # or where add command is launched via popen - try: - os.lseek(body.fileno(), 0, os.SEEK_SET) - return True - except OSError as e: - return (e.errno != errno.ESPIPE) - - def _sendable(self, body): - return (SENDFILE_SUPPORTED and - hasattr(body, 'fileno') and - self._seekable(body) and - not self.use_ssl) - def _iterable(self, body): return isinstance(body, collections.Iterable) def image_iterator(self, connection, headers, body): - if self._sendable(body): - return SendFileIterator(connection, body) - elif self._iterable(body): + if self._iterable(body): return utils.chunkreadable(body) else: return ImageBodyIterator(body) diff --git a/tools/pip-requires b/tools/pip-requires index ff25d544..62db800f 100644 --- a/tools/pip-requires +++ b/tools/pip-requires @@ -22,7 +22,6 @@ sqlalchemy-migrate>=0.7.2 python-novaclient PasteDeploy==1.5.0 routes==1.12.3 -pysendfile SQLAlchemy>=0.7.8,<=0.7.9 WebOb==1.0.8 python-keystoneclient -- 2.45.2