diff options
author | Prashanth Pai <ppai@redhat.com> | 2016-03-03 17:25:48 +0530 |
---|---|---|
committer | Thiago da Silva <thiago@redhat.com> | 2016-03-08 11:01:38 -0800 |
commit | 25188ca49950267a74b35aab1359bd5d3b919fc7 (patch) | |
tree | b8b4ec27e3ddbf9a3ecf7c2ae75d28cf6bebc94b /test | |
parent | 7392f4626609da910a2c98c14b8380419613635d (diff) |
Fix dup fd leak
A fd was not being closed after it was duplicated. This code path can
be easily hit when doing a GET on a file that needs Etag (md5sum) to
be recalculated.
Change-Id: Ib2e10d990b9b2e1fa85d0079767892de8c8d4eec
Signed-off-by: Prashanth Pai <ppai@redhat.com>
Reviewed-on: http://review.gluster.org/13593
Reviewed-by: Thiago da Silva <thiago@redhat.com>
Tested-by: Thiago da Silva <thiago@redhat.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/functional_auth/common_conf/object-server.conf | 2 | ||||
-rw-r--r-- | test/unit/common/test_utils.py | 16 |
2 files changed, 16 insertions, 2 deletions
diff --git a/test/functional_auth/common_conf/object-server.conf b/test/functional_auth/common_conf/object-server.conf index 28076cd..2599c87 100644 --- a/test/functional_auth/common_conf/object-server.conf +++ b/test/functional_auth/common_conf/object-server.conf @@ -51,5 +51,3 @@ network_chunk_size = 65556 # across all conf files! auto_create_account_prefix = gs expiring_objects_account_name = expiring - -gluster_swift_mode = true diff --git a/test/unit/common/test_utils.py b/test/unit/common/test_utils.py index 5ab6f36..f88229a 100644 --- a/test/unit/common/test_utils.py +++ b/test/unit/common/test_utils.py @@ -439,6 +439,22 @@ class TestUtils(unittest.TestCase): md5.update(chunk) assert hd == md5.hexdigest() + def test_get_etag_dup_fd_closed(self): + fd, path = tempfile.mkstemp() + data = "It's not who we are underneath, but what we do that defines us" + os.write(fd, data) + os.lseek(fd, 0, os.SEEK_SET) + + mock_do_close = Mock() + with patch("gluster.swift.common.utils.do_close", mock_do_close): + etag = utils._get_etag(fd) + self.assertEqual(etag, hashlib.md5(data).hexdigest()) + self.assertTrue(mock_do_close.called) + + # We mocked out close, so we have to close the fd for real + os.close(mock_do_close.call_args[0][0]) + os.close(fd) + def test_get_object_metadata_dne(self): md = utils.get_object_metadata("/tmp/doesNotEx1st") assert md == {} |