Merge "Adjust unit tests to clarify existing device usage"

This commit is contained in:
Jenkins 2014-01-22 02:05:47 +00:00 committed by Gerrit Code Review
commit 029790e8eb

View File

@ -83,8 +83,10 @@ class TestDiskFileModuleMethods(unittest.TestCase):
rmtree(self.testdir, ignore_errors=1)
os.mkdir(self.testdir)
os.mkdir(self.devices)
os.mkdir(os.path.join(self.devices, 'sda'))
self.objects = os.path.join(self.devices, 'sda', 'objects')
self.existing_device = 'sda'
os.mkdir(os.path.join(self.devices, self.existing_device))
self.objects = os.path.join(self.devices, self.existing_device,
'objects')
os.mkdir(self.objects)
self.parts = {}
for part in ['0', '1', '2', '3']:
@ -99,9 +101,13 @@ class TestDiskFileModuleMethods(unittest.TestCase):
def tearDown(self):
rmtree(self.testdir, ignore_errors=1)
def _create_diskfile(self):
return self.df_mgr.get_diskfile(self.existing_device,
'0', 'a', 'c', 'o')
def test_quarantine_renamer(self):
# we use this for convenience, not really about a diskfile layout
df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o')
df = self._create_diskfile()
mkdirs(df._datadir)
exp_dir = os.path.join(self.devices, 'quarantined', 'objects',
os.path.basename(df._datadir))
@ -125,7 +131,7 @@ class TestDiskFileModuleMethods(unittest.TestCase):
os.path.join(self.testdir, "doesnotexist"), 101)
def test_hash_suffix_hash_dir_is_file_quarantine(self):
df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o')
df = self._create_diskfile()
mkdirs(os.path.dirname(df._datadir))
open(df._datadir, 'wb').close()
ohash = hash_path('a', 'c', 'o')
@ -146,7 +152,7 @@ class TestDiskFileModuleMethods(unittest.TestCase):
self.assertTrue(called[0])
def test_hash_suffix_one_file(self):
df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o')
df = self._create_diskfile()
mkdirs(df._datadir)
f = open(
os.path.join(df._datadir,
@ -164,7 +170,7 @@ class TestDiskFileModuleMethods(unittest.TestCase):
self.assertEquals(len(os.listdir(self.parts['0'])), 0)
def test_hash_suffix_oserror_on_hcl(self):
df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o')
df = self._create_diskfile()
mkdirs(df._datadir)
f = open(
os.path.join(df._datadir,
@ -193,7 +199,7 @@ class TestDiskFileModuleMethods(unittest.TestCase):
101)
def test_hash_suffix_multi_file_one(self):
df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o')
df = self._create_diskfile()
mkdirs(df._datadir)
for tdiff in [1, 50, 100, 500]:
for suff in ['.meta', '.data', '.ts']:
@ -216,7 +222,7 @@ class TestDiskFileModuleMethods(unittest.TestCase):
self.assertEquals(len(os.listdir(whole_hsh_path)), 1)
def test_hash_suffix_multi_file_two(self):
df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o')
df = self._create_diskfile()
mkdirs(df._datadir)
for tdiff in [1, 50, 100, 500]:
suffs = ['.meta', '.data']
@ -266,7 +272,7 @@ class TestDiskFileModuleMethods(unittest.TestCase):
fdata = fp.read()
self.assertEquals(pickle.loads(fdata), pickle.loads(data))
df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o')
df = self._create_diskfile()
mkdirs(df._datadir)
ohash = hash_path('a', 'c', 'o')
data_dir = ohash[-3:]
@ -286,7 +292,7 @@ class TestDiskFileModuleMethods(unittest.TestCase):
assertFileData(hashes_file, check_pickle_data)
def test_invalidate_hash_bad_pickle(self):
df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o')
df = self._create_diskfile()
mkdirs(df._datadir)
ohash = hash_path('a', 'c', 'o')
data_dir = ohash[-3:]
@ -304,7 +310,7 @@ class TestDiskFileModuleMethods(unittest.TestCase):
pass
def test_get_hashes(self):
df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o')
df = self._create_diskfile()
mkdirs(df._datadir)
with open(
os.path.join(df._datadir,
@ -323,7 +329,7 @@ class TestDiskFileModuleMethods(unittest.TestCase):
self.assert_('a83' in hashes)
def test_get_hashes_bad_dir(self):
df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o')
df = self._create_diskfile()
mkdirs(df._datadir)
with open(os.path.join(self.objects, '0', 'bad'), 'wb') as f:
f.write('1234567890')
@ -334,7 +340,7 @@ class TestDiskFileModuleMethods(unittest.TestCase):
self.assert_('bad' not in hashes)
def test_get_hashes_unmodified(self):
df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o')
df = self._create_diskfile()
mkdirs(df._datadir)
with open(
os.path.join(df._datadir,
@ -354,7 +360,7 @@ class TestDiskFileModuleMethods(unittest.TestCase):
self.assertEquals(i[0], 2)
def test_get_hashes_unmodified_norecalc(self):
df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o')
df = self._create_diskfile()
mkdirs(df._datadir)
with open(
os.path.join(df._datadir,
@ -371,7 +377,7 @@ class TestDiskFileModuleMethods(unittest.TestCase):
self.assertEqual(hashes_1, hashes_0)
def test_get_hashes_hash_suffix_error(self):
df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o')
df = self._create_diskfile()
mkdirs(df._datadir)
with open(
os.path.join(df._datadir,
@ -387,7 +393,7 @@ class TestDiskFileModuleMethods(unittest.TestCase):
self.assertEqual(hashes, {'a83': None})
def test_get_hashes_unmodified_and_zero_bytes(self):
df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o')
df = self._create_diskfile()
mkdirs(df._datadir)
part = os.path.join(self.objects, '0')
open(os.path.join(part, diskfile.HASH_FILE), 'w')
@ -408,7 +414,7 @@ class TestDiskFileModuleMethods(unittest.TestCase):
self.assertTrue('a83' in hashes)
def test_get_hashes_modified(self):
df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o')
df = self._create_diskfile()
mkdirs(df._datadir)
with open(
os.path.join(df._datadir,
@ -700,8 +706,10 @@ class TestDiskFileManager(unittest.TestCase):
self.tmpdir = mkdtemp()
self.testdir = os.path.join(
self.tmpdir, 'tmp_test_obj_server_DiskFile')
mkdirs(os.path.join(self.testdir, 'sda1', 'tmp'))
mkdirs(os.path.join(self.testdir, 'sda2', 'tmp'))
self.existing_device1 = 'sda1'
self.existing_device2 = 'sda2'
mkdirs(os.path.join(self.testdir, self.existing_device1, 'tmp'))
mkdirs(os.path.join(self.testdir, self.existing_device2, 'tmp'))
self._orig_tpool_exc = tpool.execute
tpool.execute = lambda f, *args, **kwargs: f(*args, **kwargs)
self.conf = dict(devices=self.testdir, mount_check='false',
@ -719,9 +727,10 @@ class TestDiskFileManager(unittest.TestCase):
self.df_mgr.logger.increment = mock.MagicMock()
ts = normalize_timestamp(10000.0)
with mock.patch('swift.obj.diskfile.write_pickle') as wp:
self.df_mgr.pickle_async_update('sda1', 'a', 'c', 'o',
self.df_mgr.pickle_async_update(self.existing_device1,
'a', 'c', 'o',
dict(a=1, b=2), ts)
dp = self.df_mgr.construct_dev_path('sda1')
dp = self.df_mgr.construct_dev_path(self.existing_device1)
ohash = diskfile.hash_path('a', 'c', 'o')
wp.assert_called_with({'a': 1, 'b': 2},
os.path.join(dp, diskfile.ASYNCDIR,
@ -741,18 +750,18 @@ class TestDiskFileManager(unittest.TestCase):
self.df_mgr.get_hashes, 'sdb1', '0', '123')
def test_get_hashes_w_nothing(self):
hashes = self.df_mgr.get_hashes('sda1', '0', '123')
hashes = self.df_mgr.get_hashes(self.existing_device1, '0', '123')
self.assertEqual(hashes, {})
# get_hashes creates the partition path, so call again for code
# path coverage, ensuring the result is unchanged
hashes = self.df_mgr.get_hashes('sda1', '0', '123')
hashes = self.df_mgr.get_hashes(self.existing_device1, '0', '123')
self.assertEqual(hashes, {})
def test_replication_lock_on(self):
# Double check settings
self.df_mgr.replication_one_per_device = True
self.df_mgr.replication_lock_timeout = 0.1
dev_path = os.path.join(self.testdir, 'sda1')
dev_path = os.path.join(self.testdir, self.existing_device1)
with self.df_mgr.replication_lock(dev_path):
lock_exc = None
exc = None
@ -771,7 +780,7 @@ class TestDiskFileManager(unittest.TestCase):
# Double check settings
self.df_mgr.replication_one_per_device = False
self.df_mgr.replication_lock_timeout = 0.1
dev_path = os.path.join(self.testdir, 'sda1')
dev_path = os.path.join(self.testdir, self.existing_device1)
with self.df_mgr.replication_lock(dev_path):
lock_exc = None
exc = None
@ -790,8 +799,8 @@ class TestDiskFileManager(unittest.TestCase):
# Double check settings
self.df_mgr.replication_one_per_device = True
self.df_mgr.replication_lock_timeout = 0.1
dev_path = os.path.join(self.testdir, 'sda1')
dev_path2 = os.path.join(self.testdir, 'sda2')
dev_path = os.path.join(self.testdir, self.existing_device1)
dev_path2 = os.path.join(self.testdir, self.existing_device2)
with self.df_mgr.replication_lock(dev_path):
lock_exc = None
try:
@ -810,7 +819,8 @@ class TestDiskFile(unittest.TestCase):
self.tmpdir = mkdtemp()
self.testdir = os.path.join(
self.tmpdir, 'tmp_test_obj_server_DiskFile')
mkdirs(os.path.join(self.testdir, 'sda1', 'tmp'))
self.existing_device = 'sda1'
mkdirs(os.path.join(self.testdir, self.existing_device, 'tmp'))
self._orig_tpool_exc = tpool.execute
tpool.execute = lambda f, *args, **kwargs: f(*args, **kwargs)
self.conf = dict(devices=self.testdir, mount_check='false',
@ -846,19 +856,26 @@ class TestDiskFile(unittest.TestCase):
xattr.setxattr(f.fileno(), diskfile.METADATA_KEY,
pickle.dumps(metadata, diskfile.PICKLE_PROTOCOL))
def _simple_get_diskfile(self, partition='0', account='a', container='c',
obj='o'):
return self.df_mgr.get_diskfile(self.existing_device,
partition, account, container, obj)
def _create_test_file(self, data, timestamp=None, metadata=None,
account='a', container='c', obj='o'):
if metadata is None:
metadata = {}
metadata.setdefault('name', '/%s/%s/%s' % (account, container, obj))
df = self.df_mgr.get_diskfile('sda', '0', account, container, obj)
df = self._simple_get_diskfile(account=account, container=container,
obj=obj)
self._create_ondisk_file(df, data, timestamp, metadata)
df = self.df_mgr.get_diskfile('sda', '0', account, container, obj)
df = self._simple_get_diskfile(account=account, container=container,
obj=obj)
df.open()
return df
def test_open_not_exist(self):
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
self.assertRaises(DiskFileNotExist, df.open)
def test_open_expired(self):
@ -880,16 +897,16 @@ class TestDiskFile(unittest.TestCase):
def test_read_metadata(self):
self._create_test_file('1234567890', timestamp=42)
df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
md = df.read_metadata()
self.assertEqual(md['X-Timestamp'], normalize_timestamp(42))
def test_get_metadata_not_opened(self):
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
self.assertRaises(DiskFileNotOpen, df.get_metadata)
def test_not_opened(self):
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
try:
with df:
pass
@ -906,10 +923,10 @@ class TestDiskFile(unittest.TestCase):
with df.open():
self.assertEquals('1024', df._metadata['Content-Length'])
# write some new metadata (fast POST, don't send orig meta, ts 42)
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
df.write_metadata({'X-Timestamp': normalize_timestamp(42),
'X-Object-Meta-Key2': 'Value2'})
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
with df.open():
# non-fast-post updateable keys are preserved
self.assertEquals('text/garbage', df._metadata['Content-Type'])
@ -942,7 +959,7 @@ class TestDiskFile(unittest.TestCase):
self.assertEquals(''.join(reader.app_iter_range(0, None)),
'1234567890')
self.assertEquals(quarantine_msgs, [])
df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
with df.open():
reader = df.reader()
self.assertEqual(''.join(reader.app_iter_range(5, None)), '67890')
@ -1051,7 +1068,7 @@ class TestDiskFile(unittest.TestCase):
'\r\n--someheader\r\n', 100)
self.assertEqual(''.join(it), '')
df = self.df_mgr.get_diskfile('sda', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
with df.open():
reader = df.reader()
it = reader.app_iter_ranges(None, 'app/something',
@ -1060,9 +1077,9 @@ class TestDiskFile(unittest.TestCase):
self.assertEqual(quarantine_msgs, [])
def test_disk_file_mkstemp_creates_dir(self):
tmpdir = os.path.join(self.testdir, 'sda1', 'tmp')
tmpdir = os.path.join(self.testdir, self.existing_device, 'tmp')
os.rmdir(tmpdir)
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
with df.create():
self.assert_(os.path.exists(tmpdir))
@ -1070,7 +1087,7 @@ class TestDiskFile(unittest.TestCase):
csize=8, mark_deleted=False, prealloc=False,
ts=None, mount_check=False, extra_metadata=None):
'''returns a DiskFile'''
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', obj_name)
df = self._simple_get_diskfile(obj=obj_name)
data = '0' * fsize
etag = md5()
if ts:
@ -1141,7 +1158,7 @@ class TestDiskFile(unittest.TestCase):
self.conf['disk_chunk_size'] = csize
self.conf['mount_check'] = mount_check
self.df_mgr = diskfile.DiskFileManager(self.conf, FakeLogger())
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', obj_name)
df = self._simple_get_diskfile(obj=obj_name)
df.open()
if invalid_type == 'Zero-Byte':
fp = open(df._data_file, 'w')
@ -1367,7 +1384,8 @@ class TestDiskFile(unittest.TestCase):
with open(hashdir, 'w'):
pass
df = self.df_mgr.get_diskfile('sda', '0', 'abc', '123', 'xyz')
df = self.df_mgr.get_diskfile(self.existing_device, '0', 'abc', '123',
'xyz')
self.assertRaises(DiskFileQuarantined, df.open)
# make sure the right thing got quarantined; the suffix dir should not
@ -1376,14 +1394,16 @@ class TestDiskFile(unittest.TestCase):
self.assertTrue(os.path.exists(os.path.dirname(hashdir)))
def test_create_prealloc(self):
df = self.df_mgr.get_diskfile('sda', '0', 'abc', '123', 'xyz')
df = self.df_mgr.get_diskfile(self.existing_device, '0', 'abc', '123',
'xyz')
with mock.patch("swift.obj.diskfile.fallocate") as fa:
with df.create(size=200) as writer:
used_fd = writer._fd
fa.assert_called_with(used_fd, 200)
def test_create_prealloc_oserror(self):
df = self.df_mgr.get_diskfile('sda', '0', 'abc', '123', 'xyz')
df = self.df_mgr.get_diskfile(self.existing_device, '0', 'abc', '123',
'xyz')
with mock.patch("swift.obj.diskfile.fallocate",
mock.MagicMock(side_effect=OSError(
errno.EACCES, os.strerror(errno.EACCES)))):
@ -1396,7 +1416,8 @@ class TestDiskFile(unittest.TestCase):
self.fail("Expected exception DiskFileNoSpace")
def test_create_close_oserror(self):
df = self.df_mgr.get_diskfile('sda', '0', 'abc', '123', 'xyz')
df = self.df_mgr.get_diskfile(self.existing_device, '0', 'abc', '123',
'xyz')
with mock.patch("swift.obj.diskfile.os.close",
mock.MagicMock(side_effect=OSError(
errno.EACCES, os.strerror(errno.EACCES)))):
@ -1435,7 +1456,7 @@ class TestDiskFile(unittest.TestCase):
dl = os.listdir(df._datadir)
self.assertEquals(len(dl), 1)
self.assertTrue(exp_name in set(dl))
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
self.assertRaises(DiskFileDeleted, df.open)
def test_open_deleted_with_corrupt_tombstone(self):
@ -1453,7 +1474,7 @@ class TestDiskFile(unittest.TestCase):
meta_xattr = xattr.getxattr(ts_fullpath, "user.swift.metadata")
xattr.setxattr(ts_fullpath, "user.swift.metadata", meta_xattr[:-1])
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
self.assertRaises(DiskFileNotExist, df.open)
self.assertFalse(os.path.exists(ts_fullpath))
@ -1462,7 +1483,7 @@ class TestDiskFile(unittest.TestCase):
'blah blah',
account='three', container='blind', obj='mice')._datadir
df = self.df_mgr.get_diskfile_from_audit_location(
diskfile.AuditLocation(hashdir, 'sda1', '0'))
diskfile.AuditLocation(hashdir, self.existing_device, '0'))
df.open()
self.assertEqual(df._name, '/three/blind/mice')
@ -1477,7 +1498,7 @@ class TestDiskFile(unittest.TestCase):
diskfile.write_metadata(datafile, meta)
df = self.df_mgr.get_diskfile_from_audit_location(
diskfile.AuditLocation(hashdir, 'sda1', '0'))
diskfile.AuditLocation(hashdir, self.existing_device, '0'))
self.assertRaises(DiskFileQuarantined, df.open)
def test_close_error(self):
@ -1506,14 +1527,14 @@ class TestDiskFile(unittest.TestCase):
mount_check=True)
def test_ondisk_search_loop_ts_meta_data(self):
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
self._create_ondisk_file(df, '', ext='.ts', timestamp=10)
self._create_ondisk_file(df, '', ext='.ts', timestamp=9)
self._create_ondisk_file(df, '', ext='.meta', timestamp=8)
self._create_ondisk_file(df, '', ext='.meta', timestamp=7)
self._create_ondisk_file(df, 'B', ext='.data', timestamp=6)
self._create_ondisk_file(df, 'A', ext='.data', timestamp=5)
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
try:
df.open()
except DiskFileDeleted as d:
@ -1522,14 +1543,14 @@ class TestDiskFile(unittest.TestCase):
self.fail("Expected DiskFileDeleted exception")
def test_ondisk_search_loop_meta_ts_data(self):
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
self._create_ondisk_file(df, '', ext='.meta', timestamp=10)
self._create_ondisk_file(df, '', ext='.meta', timestamp=9)
self._create_ondisk_file(df, '', ext='.ts', timestamp=8)
self._create_ondisk_file(df, '', ext='.ts', timestamp=7)
self._create_ondisk_file(df, 'B', ext='.data', timestamp=6)
self._create_ondisk_file(df, 'A', ext='.data', timestamp=5)
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
try:
df.open()
except DiskFileDeleted as d:
@ -1538,14 +1559,14 @@ class TestDiskFile(unittest.TestCase):
self.fail("Expected DiskFileDeleted exception")
def test_ondisk_search_loop_meta_data_ts(self):
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
self._create_ondisk_file(df, '', ext='.meta', timestamp=10)
self._create_ondisk_file(df, '', ext='.meta', timestamp=9)
self._create_ondisk_file(df, 'B', ext='.data', timestamp=8)
self._create_ondisk_file(df, 'A', ext='.data', timestamp=7)
self._create_ondisk_file(df, '', ext='.ts', timestamp=6)
self._create_ondisk_file(df, '', ext='.ts', timestamp=5)
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
with df.open():
self.assertTrue('X-Timestamp' in df._metadata)
self.assertEquals(df._metadata['X-Timestamp'],
@ -1553,14 +1574,14 @@ class TestDiskFile(unittest.TestCase):
self.assertTrue('deleted' not in df._metadata)
def test_ondisk_search_loop_data_meta_ts(self):
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
self._create_ondisk_file(df, 'B', ext='.data', timestamp=10)
self._create_ondisk_file(df, 'A', ext='.data', timestamp=9)
self._create_ondisk_file(df, '', ext='.ts', timestamp=8)
self._create_ondisk_file(df, '', ext='.ts', timestamp=7)
self._create_ondisk_file(df, '', ext='.meta', timestamp=6)
self._create_ondisk_file(df, '', ext='.meta', timestamp=5)
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
with df.open():
self.assertTrue('X-Timestamp' in df._metadata)
self.assertEquals(df._metadata['X-Timestamp'],
@ -1568,7 +1589,7 @@ class TestDiskFile(unittest.TestCase):
self.assertTrue('deleted' not in df._metadata)
def test_ondisk_search_loop_wayward_files_ignored(self):
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
self._create_ondisk_file(df, 'X', ext='.bar', timestamp=11)
self._create_ondisk_file(df, 'B', ext='.data', timestamp=10)
self._create_ondisk_file(df, 'A', ext='.data', timestamp=9)
@ -1576,7 +1597,7 @@ class TestDiskFile(unittest.TestCase):
self._create_ondisk_file(df, '', ext='.ts', timestamp=7)
self._create_ondisk_file(df, '', ext='.meta', timestamp=6)
self._create_ondisk_file(df, '', ext='.meta', timestamp=5)
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
with df.open():
self.assertTrue('X-Timestamp' in df._metadata)
self.assertEquals(df._metadata['X-Timestamp'],
@ -1584,7 +1605,7 @@ class TestDiskFile(unittest.TestCase):
self.assertTrue('deleted' not in df._metadata)
def test_ondisk_search_loop_listdir_error(self):
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
def mock_listdir_exp(*args, **kwargs):
raise OSError(errno.EACCES, os.strerror(errno.EACCES))
@ -1597,7 +1618,7 @@ class TestDiskFile(unittest.TestCase):
self._create_ondisk_file(df, '', ext='.ts', timestamp=7)
self._create_ondisk_file(df, '', ext='.meta', timestamp=6)
self._create_ondisk_file(df, '', ext='.meta', timestamp=5)
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
self.assertRaises(DiskFileError, df.open)
def test_exception_in_handle_close_quarantine(self):
@ -1909,13 +1930,13 @@ class TestDiskFile(unittest.TestCase):
'9373a92d072897b136b3fc06595b7456', fresher_ts)])
def test_diskfile_names(self):
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
self.assertEqual(df.account, 'a')
self.assertEqual(df.container, 'c')
self.assertEqual(df.obj, 'o')
def test_diskfile_content_length_not_open(self):
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
exc = None
try:
df.content_length
@ -1931,7 +1952,7 @@ class TestDiskFile(unittest.TestCase):
dl = os.listdir(df._datadir)
self.assertEquals(len(dl), 1)
self.assertTrue(exp_name in set(dl))
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
exc = None
try:
with df.open():
@ -1942,12 +1963,12 @@ class TestDiskFile(unittest.TestCase):
def test_diskfile_content_length(self):
self._get_open_disk_file()
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
with df.open():
self.assertEqual(df.content_length, 1024)
def test_diskfile_timestamp_not_open(self):
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
exc = None
try:
df.timestamp
@ -1963,7 +1984,7 @@ class TestDiskFile(unittest.TestCase):
dl = os.listdir(df._datadir)
self.assertEquals(len(dl), 1)
self.assertTrue(exp_name in set(dl))
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
exc = None
try:
with df.open():
@ -1974,7 +1995,7 @@ class TestDiskFile(unittest.TestCase):
def test_diskfile_timestamp(self):
self._get_open_disk_file(ts='1383181759.12345')
df = self.df_mgr.get_diskfile('sda1', '0', 'a', 'c', 'o')
df = self._simple_get_diskfile()
with df.open():
self.assertEqual(df.timestamp, '1383181759.12345')