Merge "Ignore files in the devices directory when auditing objects"
This commit is contained in:
@@ -361,7 +361,15 @@ def object_audit_location_generator(devices, mount_check=True, logger=None,
|
|||||||
_('Skipping %s as it is not mounted'), device)
|
_('Skipping %s as it is not mounted'), device)
|
||||||
continue
|
continue
|
||||||
# loop through object dirs for all policies
|
# loop through object dirs for all policies
|
||||||
for dir_ in os.listdir(os.path.join(devices, device)):
|
device_dir = os.path.join(devices, device)
|
||||||
|
try:
|
||||||
|
dirs = os.listdir(device_dir)
|
||||||
|
except OSError as e:
|
||||||
|
if logger:
|
||||||
|
logger.debug(
|
||||||
|
_('Skipping %s: %s') % (device_dir, e.strerror))
|
||||||
|
continue
|
||||||
|
for dir_ in dirs:
|
||||||
if not dir_.startswith(DATADIR_BASE):
|
if not dir_.startswith(DATADIR_BASE):
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
|
@@ -405,6 +405,36 @@ class TestObjectAuditLocationGenerator(unittest.TestCase):
|
|||||||
'Skipping %s as it is not mounted',
|
'Skipping %s as it is not mounted',
|
||||||
'sdq')
|
'sdq')
|
||||||
|
|
||||||
|
def test_skipping_files(self):
|
||||||
|
with temptree([]) as tmpdir:
|
||||||
|
os.makedirs(os.path.join(tmpdir, "sdp", "objects",
|
||||||
|
"2607", "df3",
|
||||||
|
"ec2871fe724411f91787462f97d30df3"))
|
||||||
|
with open(os.path.join(tmpdir, "garbage"), "wb") as fh:
|
||||||
|
fh.write('')
|
||||||
|
|
||||||
|
locations = [
|
||||||
|
(loc.path, loc.device, loc.partition, loc.policy)
|
||||||
|
for loc in diskfile.object_audit_location_generator(
|
||||||
|
devices=tmpdir, mount_check=False)]
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
locations,
|
||||||
|
[(os.path.join(tmpdir, "sdp", "objects",
|
||||||
|
"2607", "df3",
|
||||||
|
"ec2871fe724411f91787462f97d30df3"),
|
||||||
|
"sdp", "2607", POLICIES[0])])
|
||||||
|
|
||||||
|
# Do it again, this time with a logger.
|
||||||
|
ml = mock.MagicMock()
|
||||||
|
locations = [
|
||||||
|
(loc.path, loc.device, loc.partition, loc.policy)
|
||||||
|
for loc in diskfile.object_audit_location_generator(
|
||||||
|
devices=tmpdir, mount_check=False, logger=ml)]
|
||||||
|
ml.debug.assert_called_once_with(
|
||||||
|
'Skipping %s: Not a directory' %
|
||||||
|
os.path.join(tmpdir, "garbage"))
|
||||||
|
|
||||||
def test_only_catch_expected_errors(self):
|
def test_only_catch_expected_errors(self):
|
||||||
# Crazy exceptions should still escape object_audit_location_generator
|
# Crazy exceptions should still escape object_audit_location_generator
|
||||||
# so that errors get logged and a human can see what's going wrong;
|
# so that errors get logged and a human can see what's going wrong;
|
||||||
|
Reference in New Issue
Block a user