Skip to content

Commit

Permalink
Ignore files in the devices directory when auditing objects
Browse files Browse the repository at this point in the history
The object auditor raises an exception if there are some files in
/srv/node (or any other defined "devices" directory). This change
simply skips any file in the devices directory when generating
locations for the object auditor.

Change-Id: I934594994adc577799723edb6c5648685682a9e7
  • Loading branch information
cschwede committed Mar 23, 2016
1 parent a537684 commit 51bea39
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
10 changes: 9 additions & 1 deletion swift/obj/diskfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,15 @@ def object_audit_location_generator(devices, mount_check=True, logger=None,
_('Skipping %s as it is not mounted'), device)
continue
# 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):
continue
try:
Expand Down
30 changes: 30 additions & 0 deletions test/unit/obj/test_diskfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,36 @@ def mock_ismount(path):
'Skipping %s as it is not mounted',
'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):
# Crazy exceptions should still escape object_audit_location_generator
# so that errors get logged and a human can see what's going wrong;
Expand Down

0 comments on commit 51bea39

Please sign in to comment.