diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-09-13 18:37:30 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-09-13 18:37:30 +0000 |
commit | 047d62c4bbd01a951f77a1a4a75fb2b3d8ce23ee (patch) | |
tree | c8133e9ee7dccfdfbf61b9629040a8d7e9f5932d | |
parent | b492617f2d0e43a37ec4d71d7fa9369d886d910c (diff) | |
parent | 9a9649fea812dc69213627cc3a9044e3cf8ff295 (diff) | |
download | oslo-vmware-047d62c4bbd01a951f77a1a4a75fb2b3d8ce23ee.tar.gz |
Merge "Fix seek and tell in BlockingQueue"0.6.0
-rw-r--r-- | oslo/vmware/image_transfer.py | 19 | ||||
-rw-r--r-- | tests/test_image_transfer.py | 10 |
2 files changed, 15 insertions, 14 deletions
diff --git a/oslo/vmware/image_transfer.py b/oslo/vmware/image_transfer.py index 1e83874..12c920f 100644 --- a/oslo/vmware/image_transfer.py +++ b/oslo/vmware/image_transfer.py @@ -78,22 +78,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 969e4f4..6526c7c 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): |