summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago da Silva <thiago@redhat.com>2014-03-21 16:02:36 -0400
committerLuis Pabon <lpabon@redhat.com>2014-03-26 13:30:22 -0700
commit09688dc594e9d82ba3a85b55fa569ccd2bb0b0df (patch)
treee07193b75a23b7c32c0d46961bfdcbbac2b00d01
parent972c252c41e516e7ce54406ac79b0a35adb88bca (diff)
fix __exit__ function not closing file descriptor
The file descriptor is not being closed because it is self._fd is None Change-Id: I7edc8a78b09bdd76d59ac8f3dbc809af652f9b0e Signed-off-by: Thiago da Silva <thiago@redhat.com> Reviewed-on: http://review.gluster.org/7315 Reviewed-by: Luis Pabon <lpabon@redhat.com> Tested-by: Luis Pabon <lpabon@redhat.com>
-rw-r--r--gluster/swift/obj/diskfile.py2
-rw-r--r--test/unit/obj/test_diskfile.py10
2 files changed, 11 insertions, 1 deletions
diff --git a/gluster/swift/obj/diskfile.py b/gluster/swift/obj/diskfile.py
index b3e91bc..1f8aa57 100644
--- a/gluster/swift/obj/diskfile.py
+++ b/gluster/swift/obj/diskfile.py
@@ -789,7 +789,7 @@ class DiskFile(object):
self._metadata = None
if self._fd is not None:
fd, self._fd = self._fd, None
- if self._fd > -1:
+ if fd > -1:
do_close(fd)
def get_metadata(self):
diff --git a/test/unit/obj/test_diskfile.py b/test/unit/obj/test_diskfile.py
index 64fa6e7..f8c26db 100644
--- a/test/unit/obj/test_diskfile.py
+++ b/test/unit/obj/test_diskfile.py
@@ -204,6 +204,16 @@ class TestDiskFile(unittest.TestCase):
self.assertRaises(DiskFileNotOpen, gdf.reader)
self.assertRaises(DiskFileNotOpen, gdf.__enter__)
+ def test_open_and_close(self):
+ mock_close = Mock()
+
+ with mock.patch("gluster.swift.obj.diskfile.do_close", mock_close):
+ gdf = self._create_and_get_diskfile("vol0", "p57", "ufo47",
+ "bar", "z")
+ with gdf.open():
+ assert gdf._fd is not None
+ self.assertTrue(mock_close.called)
+
def test_open_existing_metadata(self):
the_path = os.path.join(self.td, "vol0", "bar")
the_file = os.path.join(the_path, "z")