27
27
from contextlib import contextmanager
28
28
from eventlet.green import subprocess
29
29
from eventlet import Timeout, tpool
30
from test.unit import FakeLogger
30
from test.unit import FakeLogger, mock
31
31
from swift.common import utils
32
32
from swift.common.utils import hash_path, mkdirs, normalize_timestamp
33
33
from swift.common import ring
209
209
self.assertEquals(hashed, 1)
210
210
self.assert_('a83' in hashes)
212
def test_get_hashes_unmodified(self):
213
df = DiskFile(self.devices, 'sda', '0', 'a', 'c', 'o', FakeLogger())
215
with open(os.path.join(df.datadir, normalize_timestamp(
216
time.time()) + '.ts'), 'wb') as f:
217
f.write('1234567890')
218
part = os.path.join(self.objects, '0')
219
hashed, hashes = object_replicator.get_hashes(part)
221
def getmtime(filename):
224
with mock({'os.path.getmtime': getmtime}):
225
hashed, hashes = object_replicator.get_hashes(
226
part, recalculate=['a83'])
227
self.assertEquals(i[0], 2)
229
def test_get_hashes_modified(self):
230
df = DiskFile(self.devices, 'sda', '0', 'a', 'c', 'o', FakeLogger())
232
with open(os.path.join(df.datadir, normalize_timestamp(
233
time.time()) + '.ts'), 'wb') as f:
234
f.write('1234567890')
235
part = os.path.join(self.objects, '0')
236
hashed, hashes = object_replicator.get_hashes(part)
238
def getmtime(filename):
242
with mock({'os.path.getmtime': getmtime}):
243
hashed, hashes = object_replicator.get_hashes(
244
part, recalculate=['a83'])
245
self.assertEquals(i[0], 3)
212
247
def test_hash_suffix_hash_dir_is_file_quarantine(self):
213
248
df = DiskFile(self.devices, 'sda', '0', 'a', 'c', 'o', FakeLogger())
214
249
mkdirs(os.path.dirname(df.datadir))