From b46dc3ae9c500ec64b9a7f00c804152fa8e67ef8 Mon Sep 17 00:00:00 2001 From: Luis Pabon Date: Wed, 20 Nov 2013 15:51:55 -0500 Subject: Log only non-ENOENT errors in diskfile DiskFile.open() gets called for every PUT. The expected sideeffect is that if the file exists, the metadata in the object will be populated. DiskFile.open() was logging any errors it detected while trying to open() the file. Issue is that when we PUT a new file, there is no entry, and open() will return an error. The was incorrectly logging each one of these errors. Change-Id: I7d721df177761066fdaa46d278fff2d779924999 Signed-off-by: Luis Pabon Reviewed-on: http://review.gluster.org/6316 Reviewed-by: Thiago Da Silva Reviewed-by: Peter Portante Tested-by: Prashanth Pai --- test/unit/obj/test_diskfile.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/unit/obj/test_diskfile.py b/test/unit/obj/test_diskfile.py index bd34eb1..dc2c2fa 100644 --- a/test/unit/obj/test_diskfile.py +++ b/test/unit/obj/test_diskfile.py @@ -22,7 +22,7 @@ import unittest import tempfile import shutil import mock -from mock import patch +from mock import Mock, patch from hashlib import md5 from swift.common.utils import normalize_timestamp @@ -162,6 +162,31 @@ class TestDiskFile(unittest.TestCase): assert gdf.datadir == os.path.join(self.td, "vol0", "bar", "b", "a") assert gdf.device_path == os.path.join(self.td, "vol0") + def test_open_no_logging_on_enoent(self): + + def _mock_do_open(path, flags): + raise GlusterFileSystemOSError(errno.ENOENT, + os.strerror(errno.ENOENT)) + + with patch("gluster.swift.obj.diskfile.do_open", + _mock_do_open): + gdf = self._get_diskfile("vol0", "p57", "ufo47", "bar", "z") + gdf.logger = Mock() + gdf.open() + self.assertEqual(0, gdf.logger.exception.call_count) + + def test_open_logging_on_no_enoent(self): + def _mock_do_open(path, flags): + raise GlusterFileSystemOSError(errno.EIO, + os.strerror(errno.EIO)) + + with patch("gluster.swift.obj.diskfile.do_open", + _mock_do_open): + gdf = self._get_diskfile("vol0", "p57", "ufo47", "bar", "z") + gdf.logger = Mock() + gdf.open() + self.assertEqual(1, gdf.logger.exception.call_count) + def test_open_no_metadata(self): the_path = os.path.join(self.td, "vol0", "bar") the_file = os.path.join(the_path, "z") -- cgit