def test_get_hashes(self): df = diskfile.DiskFile(self.devices, "sda", "0", "a", "c", "o", FakeLogger()) mkdirs(df.datadir) with open(os.path.join(df.datadir, normalize_timestamp(time()) + ".ts"), "wb") as f: f.write("1234567890") part = os.path.join(self.objects, "0") hashed, hashes = diskfile.get_hashes(part) self.assertEquals(hashed, 1) self.assert_("a83" in hashes) hashed, hashes = diskfile.get_hashes(part, do_listdir=True) self.assertEquals(hashed, 0) self.assert_("a83" in hashes) hashed, hashes = diskfile.get_hashes(part, recalculate=["a83"]) self.assertEquals(hashed, 1) self.assert_("a83" in hashes)
def test_get_hashes_unmodified(self): df = diskfile.DiskFile(self.devices, "sda", "0", "a", "c", "o", FakeLogger()) mkdirs(df.datadir) with open(os.path.join(df.datadir, normalize_timestamp(time()) + ".ts"), "wb") as f: f.write("1234567890") part = os.path.join(self.objects, "0") hashed, hashes = diskfile.get_hashes(part) i = [0] def _getmtime(filename): i[0] += 1 return 1 with unit_mock({"swift.obj.diskfile.getmtime": _getmtime}): hashed, hashes = diskfile.get_hashes(part, recalculate=["a83"]) self.assertEquals(i[0], 2)
def test_get_hashes(self): df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o') mkdirs(df._datadir) with open( os.path.join(df._datadir, normalize_timestamp(time()) + '.ts'), 'wb') as f: f.write('1234567890') part = os.path.join(self.objects, '0') hashed, hashes = diskfile.get_hashes(part) self.assertEquals(hashed, 1) self.assert_('a83' in hashes) hashed, hashes = diskfile.get_hashes(part, do_listdir=True) self.assertEquals(hashed, 0) self.assert_('a83' in hashes) hashed, hashes = diskfile.get_hashes(part, recalculate=['a83']) self.assertEquals(hashed, 1) self.assert_('a83' in hashes)
def test_get_hashes_unmodified(self): df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o') mkdirs(df._datadir) with open( os.path.join(df._datadir, normalize_timestamp(time()) + '.ts'), 'wb') as f: f.write('1234567890') part = os.path.join(self.objects, '0') hashed, hashes = diskfile.get_hashes(part) i = [0] def _getmtime(filename): i[0] += 1 return 1 with unit_mock({'swift.obj.diskfile.getmtime': _getmtime}): hashed, hashes = diskfile.get_hashes(part, recalculate=['a83']) self.assertEquals(i[0], 2)
def test_get_hashes_bad_dir(self): df = diskfile.DiskFile(self.devices, "sda", "0", "a", "c", "o", FakeLogger()) mkdirs(df.datadir) with open(os.path.join(self.objects, "0", "bad"), "wb") as f: f.write("1234567890") part = os.path.join(self.objects, "0") hashed, hashes = diskfile.get_hashes(part) self.assertEquals(hashed, 1) self.assert_("a83" in hashes) self.assert_("bad" not in hashes)
def test_get_hashes_unmodified(self): df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o') mkdirs(df._datadir) with open( os.path.join(df._datadir, normalize_timestamp(time()) + '.ts'), 'wb') as f: f.write('1234567890') part = os.path.join(self.objects, '0') hashed, hashes = diskfile.get_hashes(part) i = [0] def _getmtime(filename): i[0] += 1 return 1 with unit_mock({'swift.obj.diskfile.getmtime': _getmtime}): hashed, hashes = diskfile.get_hashes( part, recalculate=['a83']) self.assertEquals(i[0], 2)
def test_get_hashes_bad_dir(self): df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o') mkdirs(df._datadir) with open(os.path.join(self.objects, '0', 'bad'), 'wb') as f: f.write('1234567890') part = os.path.join(self.objects, '0') hashed, hashes = diskfile.get_hashes(part) self.assertEquals(hashed, 1) self.assert_('a83' in hashes) self.assert_('bad' not in hashes)
def test_get_hashes_unmodified_and_zero_bytes(self): df = diskfile.DiskFile(self.devices, "sda", "0", "a", "c", "o", FakeLogger()) mkdirs(df.datadir) part = os.path.join(self.objects, "0") open(os.path.join(part, diskfile.HASH_FILE), "w") # Now the hash file is zero bytes. i = [0] def _getmtime(filename): i[0] += 1 return 1 with unit_mock({"swift.obj.diskfile.getmtime": _getmtime}): hashed, hashes = diskfile.get_hashes(part, recalculate=[]) # getmtime will actually not get called. Initially, the pickle.load # will raise an exception first and later, force_rewrite will # short-circuit the if clause to determine whether to write out a # fresh hashes_file. self.assertEquals(i[0], 0) self.assertTrue("a83" in hashes)
def test_get_hashes_unmodified_and_zero_bytes(self): df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o') mkdirs(df._datadir) part = os.path.join(self.objects, '0') open(os.path.join(part, diskfile.HASH_FILE), 'w') # Now the hash file is zero bytes. i = [0] def _getmtime(filename): i[0] += 1 return 1 with unit_mock({'swift.obj.diskfile.getmtime': _getmtime}): hashed, hashes = diskfile.get_hashes( part, recalculate=[]) # getmtime will actually not get called. Initially, the pickle.load # will raise an exception first and later, force_rewrite will # short-circuit the if clause to determine whether to write out a # fresh hashes_file. self.assertEquals(i[0], 0) self.assertTrue('a83' in hashes)
def test_get_hashes_unmodified_and_zero_bytes(self): df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o') mkdirs(df._datadir) part = os.path.join(self.objects, '0') open(os.path.join(part, diskfile.HASH_FILE), 'w') # Now the hash file is zero bytes. i = [0] def _getmtime(filename): i[0] += 1 return 1 with unit_mock({'swift.obj.diskfile.getmtime': _getmtime}): hashed, hashes = diskfile.get_hashes(part, recalculate=[]) # getmtime will actually not get called. Initially, the pickle.load # will raise an exception first and later, force_rewrite will # short-circuit the if clause to determine whether to write out a # fresh hashes_file. self.assertEquals(i[0], 0) self.assertTrue('a83' in hashes)