summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVipin Balachandran <vbala@vmware.com>2014-07-16 15:13:36 +0530
committerVipin Balachandran <vbala@vmware.com>2014-07-16 16:15:46 +0530
commit9a9649fea812dc69213627cc3a9044e3cf8ff295 (patch)
tree18abb1c30de12b506f63c9cf16e87fb557939596
parentf6a7ea926663dd20f1e92a086967c4fd3748b2e8 (diff)
downloadoslo-vmware-9a9649fea812dc69213627cc3a9044e3cf8ff295.tar.gz
Fix seek and tell in BlockingQueue
Currently seek() throws IOError conditionally and tell() returns the maximum transfer size. This patch fixes these problems. Change-Id: Ie8bf359457de975a8ae6373a73b5a835e53f2410
-rw-r--r--oslo/vmware/image_transfer.py19
-rw-r--r--tests/test_image_transfer.py10
2 files changed, 15 insertions, 14 deletions
diff --git a/oslo/vmware/image_transfer.py b/oslo/vmware/image_transfer.py
index a86773d..d05ad6c 100644
--- a/oslo/vmware/image_transfer.py
+++ b/oslo/vmware/image_transfer.py
@@ -79,22 +79,17 @@ class BlockingQueue(queue.LightQueue):
# Below methods are provided in order to enable treating the queue
# as a file handle.
- # Note(vui): When file transfer size is not specified, we raise IOError to
- # prevent incorrect predetermination of file length by readers.
def seek(self, offset, whence=0):
- if self._max_transfer_size is 0:
- raise IOError(errno.ESPIPE, "Illegal seek")
+ """Set the file's current position at the offset.
- def tell(self):
- """Get size of the file to be read.
-
- We interpret _max_transfer_size=0 as stream mode and raise IOError
- to prevent incorrect predetermination of file length by readers.
+ This method throws IOError since seek cannot be supported for a pipe.
"""
- if self._max_transfer_size is 0:
- raise IOError(errno.ESPIPE, "Illegal seek")
- return self._max_transfer_size
+ raise IOError(errno.ESPIPE, "Illegal seek")
+
+ def tell(self):
+ """Get the current file position."""
+ return self._transferred
def close(self):
pass
diff --git a/tests/test_image_transfer.py b/tests/test_image_transfer.py
index 1965cd9..6d81513 100644
--- a/tests/test_image_transfer.py
+++ b/tests/test_image_transfer.py
@@ -61,10 +61,16 @@ class BlockingQueueTest(base.TestCase):
exp_calls = [mock.call([1])] * write_count
self.assertEqual(exp_calls, queue.put.call_args_list)
+ def test_seek(self):
+ queue = image_transfer.BlockingQueue(10, 30)
+ self.assertRaises(IOError, queue.seek, 5)
+
def test_tell(self):
- max_transfer_size = 30
queue = image_transfer.BlockingQueue(10, 30)
- self.assertEqual(max_transfer_size, queue.tell())
+ self.assertEqual(0, queue.tell())
+ queue.get = mock.Mock(return_value=[1] * 10)
+ queue.read(10)
+ self.assertEqual(10, queue.tell())
class ImageWriterTest(base.TestCase):