Refactor DiskDir and DiskAccount to use DiskCommon
We have refactored DiskDir and DiskAccount so that truly common, shared functions live in the base class DiskCommon, and each of these then sub-class that. This allows us to isolate unique behaviors. We have also enabled all the skipped unit tests in test_diskdir.py that we could, removing a few that we don't need right now. Change-Id: I48d9c915108df8cc92c3e9a764563e1d10c50050 Signed-off-by: Peter Portante <peter.portante@redhat.com> Reviewed-on: http://review.gluster.org/5148 Reviewed-by: Mohammed Junaid <junaid@redhat.com> Reviewed-by: Luis Pabon <lpabon@redhat.com> Tested-by: Luis Pabon <lpabon@redhat.com>
This commit is contained in:
parent
f80872e852
commit
a88accbe27
@ -77,8 +77,6 @@ def filter_delimiter(objects, delimiter, prefix, marker, path=None):
|
|||||||
1. begin with "prefix" (empty string matches all)
|
1. begin with "prefix" (empty string matches all)
|
||||||
2. does not match the "path" argument
|
2. does not match the "path" argument
|
||||||
3. does not contain the delimiter in the given prefix length
|
3. does not contain the delimiter in the given prefix length
|
||||||
4.
|
|
||||||
be those that start with the prefix.
|
|
||||||
"""
|
"""
|
||||||
assert delimiter
|
assert delimiter
|
||||||
assert prefix is not None
|
assert prefix is not None
|
||||||
@ -148,9 +146,55 @@ def filter_end_marker(objects, end_marker):
|
|||||||
|
|
||||||
|
|
||||||
class DiskCommon(object):
|
class DiskCommon(object):
|
||||||
|
"""
|
||||||
|
Common fields and methods shared between DiskDir and DiskAccount classes.
|
||||||
|
"""
|
||||||
|
def __init__(self, root, drive, account, logger):
|
||||||
|
# WARNING: The following four fields are referenced as fields by our
|
||||||
|
# callers outside of this module, do not remove.
|
||||||
|
# Create a dummy db_file in Glusterfs.RUN_DIR
|
||||||
|
global _db_file
|
||||||
|
if not _db_file:
|
||||||
|
_db_file = os.path.join(Glusterfs.RUN_DIR, 'db_file.db')
|
||||||
|
if not os.path.exists(_db_file):
|
||||||
|
file(_db_file, 'w+')
|
||||||
|
self.db_file = _db_file
|
||||||
|
self.metadata = {}
|
||||||
|
self.pending_timeout = 0
|
||||||
|
self.stale_reads_ok = False
|
||||||
|
# The following fields are common
|
||||||
|
self.root = root
|
||||||
|
assert logger is not None
|
||||||
|
self.logger = logger
|
||||||
|
self.account = account
|
||||||
|
self.datadir = os.path.join(root, drive)
|
||||||
|
self._dir_exists = None
|
||||||
|
|
||||||
|
def _dir_exists_read_metadata(self):
|
||||||
|
self._dir_exists = os_path.exists(self.datadir)
|
||||||
|
if self._dir_exists:
|
||||||
|
self.metadata = _read_metadata(self.datadir)
|
||||||
|
return self._dir_exists
|
||||||
|
|
||||||
def is_deleted(self):
|
def is_deleted(self):
|
||||||
|
# The intention of this method is to check the file system to see if
|
||||||
|
# the directory actually exists.
|
||||||
return not os_path.exists(self.datadir)
|
return not os_path.exists(self.datadir)
|
||||||
|
|
||||||
|
def empty(self):
|
||||||
|
# FIXME: Common because ported swift AccountBroker unit tests use it.
|
||||||
|
return dir_empty(self.datadir)
|
||||||
|
|
||||||
|
def update_metadata(self, metadata):
|
||||||
|
assert self.metadata, "Valid container/account metadata should have " \
|
||||||
|
"been created by now"
|
||||||
|
if metadata:
|
||||||
|
new_metadata = self.metadata.copy()
|
||||||
|
new_metadata.update(metadata)
|
||||||
|
if new_metadata != self.metadata:
|
||||||
|
write_metadata(self.datadir, new_metadata)
|
||||||
|
self.metadata = new_metadata
|
||||||
|
|
||||||
|
|
||||||
class DiskDir(DiskCommon):
|
class DiskDir(DiskCommon):
|
||||||
"""
|
"""
|
||||||
@ -236,53 +280,24 @@ class DiskDir(DiskCommon):
|
|||||||
|
|
||||||
def __init__(self, path, drive, account, container, logger,
|
def __init__(self, path, drive, account, container, logger,
|
||||||
uid=DEFAULT_UID, gid=DEFAULT_GID):
|
uid=DEFAULT_UID, gid=DEFAULT_GID):
|
||||||
self.root = path
|
super(DiskDir, self).__init__(path, drive, account, logger)
|
||||||
if container:
|
|
||||||
self.container = container
|
|
||||||
else:
|
|
||||||
self.container = None
|
|
||||||
if self.container:
|
|
||||||
self.datadir = os.path.join(path, drive, self.container)
|
|
||||||
else:
|
|
||||||
self.datadir = os.path.join(path, drive)
|
|
||||||
self.account = account
|
|
||||||
assert logger is not None
|
|
||||||
self.logger = logger
|
|
||||||
self.metadata = {}
|
|
||||||
self.container_info = None
|
|
||||||
self.uid = int(uid)
|
self.uid = int(uid)
|
||||||
self.gid = int(gid)
|
self.gid = int(gid)
|
||||||
# Create a dummy db_file in Glusterfs.RUN_DIR
|
|
||||||
global _db_file
|
self.container = container
|
||||||
if not _db_file:
|
self.datadir = os.path.join(self.datadir, self.container)
|
||||||
_db_file = os.path.join(Glusterfs.RUN_DIR, 'db_file.db')
|
|
||||||
if not os.path.exists(_db_file):
|
if not self._dir_exists_read_metadata():
|
||||||
file(_db_file, 'w+')
|
return
|
||||||
self.db_file = _db_file
|
|
||||||
self.dir_exists = os_path.exists(self.datadir)
|
if not self.metadata:
|
||||||
if self.dir_exists:
|
create_container_metadata(self.datadir)
|
||||||
self.metadata = _read_metadata(self.datadir)
|
self.metadata = _read_metadata(self.datadir)
|
||||||
else:
|
else:
|
||||||
return
|
if not validate_container(self.metadata):
|
||||||
if self.container:
|
|
||||||
if not self.metadata:
|
|
||||||
create_container_metadata(self.datadir)
|
create_container_metadata(self.datadir)
|
||||||
self.metadata = _read_metadata(self.datadir)
|
self.metadata = _read_metadata(self.datadir)
|
||||||
else:
|
|
||||||
if not validate_container(self.metadata):
|
|
||||||
create_container_metadata(self.datadir)
|
|
||||||
self.metadata = _read_metadata(self.datadir)
|
|
||||||
else:
|
|
||||||
if not self.metadata:
|
|
||||||
create_account_metadata(self.datadir)
|
|
||||||
self.metadata = _read_metadata(self.datadir)
|
|
||||||
else:
|
|
||||||
if not validate_account(self.metadata):
|
|
||||||
create_account_metadata(self.datadir)
|
|
||||||
self.metadata = _read_metadata(self.datadir)
|
|
||||||
|
|
||||||
def empty(self):
|
|
||||||
return dir_empty(self.datadir)
|
|
||||||
|
|
||||||
def list_objects_iter(self, limit, marker, end_marker,
|
def list_objects_iter(self, limit, marker, end_marker,
|
||||||
prefix, delimiter, path=None):
|
prefix, delimiter, path=None):
|
||||||
@ -303,7 +318,7 @@ class DiskDir(DiskCommon):
|
|||||||
|
|
||||||
container_list = []
|
container_list = []
|
||||||
|
|
||||||
objects = self.update_object_count()
|
objects = self._update_object_count()
|
||||||
if objects:
|
if objects:
|
||||||
objects.sort()
|
objects.sort()
|
||||||
else:
|
else:
|
||||||
@ -368,7 +383,7 @@ class DiskDir(DiskCommon):
|
|||||||
|
|
||||||
return container_list
|
return container_list
|
||||||
|
|
||||||
def update_object_count(self):
|
def _update_object_count(self):
|
||||||
objects, object_count, bytes_used = get_container_details(self.datadir)
|
objects, object_count, bytes_used = get_container_details(self.datadir)
|
||||||
|
|
||||||
if X_OBJECTS_COUNT not in self.metadata \
|
if X_OBJECTS_COUNT not in self.metadata \
|
||||||
@ -381,33 +396,21 @@ class DiskDir(DiskCommon):
|
|||||||
|
|
||||||
return objects
|
return objects
|
||||||
|
|
||||||
def update_container_count(self):
|
def get_info(self):
|
||||||
containers, container_count = get_account_details(self.datadir)
|
|
||||||
|
|
||||||
if X_CONTAINER_COUNT not in self.metadata \
|
|
||||||
or int(self.metadata[X_CONTAINER_COUNT][0]) != container_count:
|
|
||||||
self.metadata[X_CONTAINER_COUNT] = (container_count, 0)
|
|
||||||
write_metadata(self.datadir, self.metadata)
|
|
||||||
|
|
||||||
return containers
|
|
||||||
|
|
||||||
def get_info(self, include_metadata=False):
|
|
||||||
"""
|
"""
|
||||||
Get global data for the container.
|
Get global data for the container.
|
||||||
:returns: dict with keys: account, container, object_count, bytes_used,
|
:returns: dict with keys: account, container, object_count, bytes_used,
|
||||||
hash, id, created_at, put_timestamp, delete_timestamp,
|
hash, id, created_at, put_timestamp, delete_timestamp,
|
||||||
reported_put_timestamp, reported_delete_timestamp,
|
reported_put_timestamp, reported_delete_timestamp,
|
||||||
reported_object_count, and reported_bytes_used.
|
reported_object_count, and reported_bytes_used.
|
||||||
If include_metadata is set, metadata is included as a key
|
|
||||||
pointing to a dict of tuples of the metadata
|
|
||||||
"""
|
"""
|
||||||
if not Glusterfs.OBJECT_ONLY:
|
if not Glusterfs.OBJECT_ONLY:
|
||||||
# If we are not configured for object only environments, we should
|
# If we are not configured for object only environments, we should
|
||||||
# update the object counts in case they changed behind our back.
|
# update the object counts in case they changed behind our back.
|
||||||
self.update_object_count()
|
self._update_object_count()
|
||||||
else:
|
else:
|
||||||
# FIXME: to facilitate testing, we need to update all the time
|
# FIXME: to facilitate testing, we need to update all the time
|
||||||
self.update_object_count()
|
self._update_object_count()
|
||||||
|
|
||||||
data = {'account': self.account, 'container': self.container,
|
data = {'account': self.account, 'container': self.container,
|
||||||
'object_count': self.metadata.get(
|
'object_count': self.metadata.get(
|
||||||
@ -425,8 +428,6 @@ class DiskDir(DiskCommon):
|
|||||||
'x_container_sync_point2': self.metadata.get(
|
'x_container_sync_point2': self.metadata.get(
|
||||||
'x_container_sync_point2', -1),
|
'x_container_sync_point2', -1),
|
||||||
}
|
}
|
||||||
if include_metadata:
|
|
||||||
data['metadata'] = self.metadata
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def put_object(self, name, timestamp, size, content_type, etag, deleted=0):
|
def put_object(self, name, timestamp, size, content_type, etag, deleted=0):
|
||||||
@ -439,7 +440,7 @@ class DiskDir(DiskCommon):
|
|||||||
Create and write metatdata to directory/container.
|
Create and write metatdata to directory/container.
|
||||||
:param metadata: Metadata to write.
|
:param metadata: Metadata to write.
|
||||||
"""
|
"""
|
||||||
if not self.dir_exists:
|
if not self._dir_exists:
|
||||||
mkdirs(self.datadir)
|
mkdirs(self.datadir)
|
||||||
# If we create it, ensure we own it.
|
# If we create it, ensure we own it.
|
||||||
os.chown(self.datadir, self.uid, self.gid)
|
os.chown(self.datadir, self.uid, self.gid)
|
||||||
@ -447,48 +448,47 @@ class DiskDir(DiskCommon):
|
|||||||
metadata[X_TIMESTAMP] = timestamp
|
metadata[X_TIMESTAMP] = timestamp
|
||||||
write_metadata(self.datadir, metadata)
|
write_metadata(self.datadir, metadata)
|
||||||
self.metadata = metadata
|
self.metadata = metadata
|
||||||
self.dir_exists = True
|
self._dir_exists = True
|
||||||
|
|
||||||
def update_put_timestamp(self, timestamp):
|
def update_put_timestamp(self, timestamp):
|
||||||
"""
|
"""
|
||||||
Create the container if it doesn't exist and update the timestamp
|
Update the PUT timestamp for the container.
|
||||||
|
|
||||||
|
If the container does not exist, create it using a PUT timestamp of
|
||||||
|
the given value.
|
||||||
|
|
||||||
|
If the container does exist, update the PUT timestamp only if it is
|
||||||
|
later than the existing value.
|
||||||
"""
|
"""
|
||||||
if not os_path.exists(self.datadir):
|
if not os_path.exists(self.datadir):
|
||||||
self.initialize(timestamp)
|
self.initialize(timestamp)
|
||||||
else:
|
else:
|
||||||
self.metadata[X_PUT_TIMESTAMP] = timestamp
|
if timestamp > self.metadata[X_PUT_TIMESTAMP]:
|
||||||
write_metadata(self.datadir, self.metadata)
|
self.metadata[X_PUT_TIMESTAMP] = (timestamp, 0)
|
||||||
|
write_metadata(self.datadir, self.metadata)
|
||||||
|
|
||||||
def delete_object(self, name, timestamp):
|
def delete_object(self, name, timestamp):
|
||||||
# NOOP - should never be called since object file removal occurs
|
# NOOP - should never be called since object file removal occurs
|
||||||
# within a directory implicitly.
|
# within a directory implicitly.
|
||||||
pass
|
return
|
||||||
|
|
||||||
def delete_db(self, timestamp):
|
def delete_db(self, timestamp):
|
||||||
"""
|
"""
|
||||||
Delete the container
|
Delete the container (directory) if empty.
|
||||||
|
|
||||||
:param timestamp: delete timestamp
|
:param timestamp: delete timestamp
|
||||||
"""
|
"""
|
||||||
if dir_empty(self.datadir):
|
if not dir_empty(self.datadir):
|
||||||
rmdirs(self.datadir)
|
# FIXME: This is a failure condition here, isn't it?
|
||||||
|
return
|
||||||
def update_metadata(self, metadata):
|
rmdirs(self.datadir)
|
||||||
assert self.metadata, "Valid container/account metadata should have" \
|
|
||||||
" been created by now"
|
|
||||||
if metadata:
|
|
||||||
new_metadata = self.metadata.copy()
|
|
||||||
new_metadata.update(metadata)
|
|
||||||
if new_metadata != self.metadata:
|
|
||||||
write_metadata(self.datadir, new_metadata)
|
|
||||||
self.metadata = new_metadata
|
|
||||||
|
|
||||||
def set_x_container_sync_points(self, sync_point1, sync_point2):
|
def set_x_container_sync_points(self, sync_point1, sync_point2):
|
||||||
self.metadata['x_container_sync_point1'] = sync_point1
|
self.metadata['x_container_sync_point1'] = sync_point1
|
||||||
self.metadata['x_container_sync_point2'] = sync_point2
|
self.metadata['x_container_sync_point2'] = sync_point2
|
||||||
|
|
||||||
|
|
||||||
class DiskAccount(DiskDir):
|
class DiskAccount(DiskCommon):
|
||||||
"""
|
"""
|
||||||
Usage pattern from account/server.py (Havana, 1.8.0+):
|
Usage pattern from account/server.py (Havana, 1.8.0+):
|
||||||
DELETE:
|
DELETE:
|
||||||
@ -528,11 +528,26 @@ class DiskAccount(DiskDir):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, root, drive, account, logger):
|
def __init__(self, root, drive, account, logger):
|
||||||
super(DiskAccount, self).__init__(root, drive, account, None, logger)
|
super(DiskAccount, self).__init__(root, drive, account, logger)
|
||||||
assert self.dir_exists
|
|
||||||
|
# Since accounts should always exist (given an account maps to a
|
||||||
|
# gluster volume directly, and the mount has already been checked at
|
||||||
|
# the beginning of the REST API handling), just assert that that
|
||||||
|
# assumption still holds.
|
||||||
|
assert self._dir_exists_read_metadata()
|
||||||
|
assert self._dir_exists
|
||||||
|
|
||||||
|
if not self.metadata or not validate_account(self.metadata):
|
||||||
|
create_account_metadata(self.datadir)
|
||||||
|
self.metadata = _read_metadata(self.datadir)
|
||||||
|
|
||||||
def is_status_deleted(self):
|
def is_status_deleted(self):
|
||||||
"""Only returns true if the status field is set to DELETED."""
|
"""
|
||||||
|
Only returns true if the status field is set to DELETED.
|
||||||
|
"""
|
||||||
|
# This function should always return False. Accounts are not created
|
||||||
|
# and deleted, they exist if a Gluster volume can be mounted. There is
|
||||||
|
# no way to delete accounts, so this could never return True.
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def initialize(self, timestamp):
|
def initialize(self, timestamp):
|
||||||
@ -545,14 +560,30 @@ class DiskAccount(DiskDir):
|
|||||||
write_metadata(self.datadir, metadata)
|
write_metadata(self.datadir, metadata)
|
||||||
self.metadata = metadata
|
self.metadata = metadata
|
||||||
|
|
||||||
|
def update_put_timestamp(self, timestamp):
|
||||||
|
# Since accounts always exists at this point, just update the account
|
||||||
|
# PUT timestamp if this given timestamp is later than what we already
|
||||||
|
# know.
|
||||||
|
assert self._dir_exists
|
||||||
|
|
||||||
|
if timestamp > self.metadata[X_PUT_TIMESTAMP][0]:
|
||||||
|
self.metadata[X_PUT_TIMESTAMP] = (timestamp, 0)
|
||||||
|
write_metadata(self.datadir, self.metadata)
|
||||||
|
|
||||||
def delete_db(self, timestamp):
|
def delete_db(self, timestamp):
|
||||||
"""
|
"""
|
||||||
Mark the account as deleted
|
Mark the account as deleted
|
||||||
|
|
||||||
:param timestamp: delete timestamp
|
:param timestamp: delete timestamp
|
||||||
"""
|
"""
|
||||||
# NOOP - Accounts map to gluster volumes, and so they cannot be
|
# Deleting an account is a no-op, since accounts are one-to-one
|
||||||
# deleted.
|
# mappings to gluster volumes.
|
||||||
|
#
|
||||||
|
# FIXME: This means the caller will end up returning a success status
|
||||||
|
# code for an operation that really should not be allowed. Instead, we
|
||||||
|
# should modify the account server to not allow the DELETE method, and
|
||||||
|
# should probably modify the proxy account controller to not allow the
|
||||||
|
# DELETE method as well.
|
||||||
return
|
return
|
||||||
|
|
||||||
def put_container(self, container, put_timestamp, del_timestamp,
|
def put_container(self, container, put_timestamp, del_timestamp,
|
||||||
@ -570,6 +601,16 @@ class DiskAccount(DiskDir):
|
|||||||
# occurs from within the account directory implicitly.
|
# occurs from within the account directory implicitly.
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def _update_container_count(self):
|
||||||
|
containers, container_count = get_account_details(self.datadir)
|
||||||
|
|
||||||
|
if X_CONTAINER_COUNT not in self.metadata \
|
||||||
|
or int(self.metadata[X_CONTAINER_COUNT][0]) != container_count:
|
||||||
|
self.metadata[X_CONTAINER_COUNT] = (container_count, 0)
|
||||||
|
write_metadata(self.datadir, self.metadata)
|
||||||
|
|
||||||
|
return containers
|
||||||
|
|
||||||
def list_containers_iter(self, limit, marker, end_marker,
|
def list_containers_iter(self, limit, marker, end_marker,
|
||||||
prefix, delimiter):
|
prefix, delimiter):
|
||||||
"""
|
"""
|
||||||
@ -580,7 +621,7 @@ class DiskAccount(DiskDir):
|
|||||||
prefix = ''
|
prefix = ''
|
||||||
|
|
||||||
account_list = []
|
account_list = []
|
||||||
containers = self.update_container_count()
|
containers = self._update_container_count()
|
||||||
if containers:
|
if containers:
|
||||||
containers.sort()
|
containers.sort()
|
||||||
else:
|
else:
|
||||||
@ -623,8 +664,8 @@ class DiskAccount(DiskDir):
|
|||||||
try:
|
try:
|
||||||
metadata = create_container_metadata(cont_path)
|
metadata = create_container_metadata(cont_path)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
# FIXME - total hack to get port unit test cases
|
# FIXME - total hack to get upstream swift ported unit
|
||||||
# working for now.
|
# test cases working for now.
|
||||||
if e.errno != errno.ENOENT:
|
if e.errno != errno.ENOENT:
|
||||||
raise
|
raise
|
||||||
if metadata:
|
if metadata:
|
||||||
@ -638,7 +679,7 @@ class DiskAccount(DiskDir):
|
|||||||
|
|
||||||
return account_list
|
return account_list
|
||||||
|
|
||||||
def get_info(self, include_metadata=False):
|
def get_info(self):
|
||||||
"""
|
"""
|
||||||
Get global data for the account.
|
Get global data for the account.
|
||||||
:returns: dict with keys: account, created_at, put_timestamp,
|
:returns: dict with keys: account, created_at, put_timestamp,
|
||||||
@ -648,10 +689,10 @@ class DiskAccount(DiskDir):
|
|||||||
if not Glusterfs.OBJECT_ONLY:
|
if not Glusterfs.OBJECT_ONLY:
|
||||||
# If we are not configured for object only environments, we should
|
# If we are not configured for object only environments, we should
|
||||||
# update the container counts in case they changed behind our back.
|
# update the container counts in case they changed behind our back.
|
||||||
self.update_container_count()
|
self._update_container_count()
|
||||||
else:
|
else:
|
||||||
# FIXME: to facilitate testing, we need to update all the time
|
# FIXME: to facilitate testing, we need to update all the time
|
||||||
self.update_container_count()
|
self._update_container_count()
|
||||||
|
|
||||||
data = {'account': self.account, 'created_at': '1',
|
data = {'account': self.account, 'created_at': '1',
|
||||||
'put_timestamp': '1', 'delete_timestamp': '1',
|
'put_timestamp': '1', 'delete_timestamp': '1',
|
||||||
@ -660,7 +701,4 @@ class DiskAccount(DiskDir):
|
|||||||
'object_count': self.metadata.get(X_OBJECTS_COUNT, (0, 0))[0],
|
'object_count': self.metadata.get(X_OBJECTS_COUNT, (0, 0))[0],
|
||||||
'bytes_used': self.metadata.get(X_BYTES_USED, (0, 0))[0],
|
'bytes_used': self.metadata.get(X_BYTES_USED, (0, 0))[0],
|
||||||
'hash': '', 'id': ''}
|
'hash': '', 'id': ''}
|
||||||
|
|
||||||
if include_metadata:
|
|
||||||
data['metadata'] = self.metadata
|
|
||||||
return data
|
return data
|
||||||
|
@ -24,7 +24,6 @@ import shutil
|
|||||||
import tarfile
|
import tarfile
|
||||||
import hashlib
|
import hashlib
|
||||||
from time import time
|
from time import time
|
||||||
from nose import SkipTest
|
|
||||||
from swift.common.utils import normalize_timestamp
|
from swift.common.utils import normalize_timestamp
|
||||||
from gluster.swift.common import utils
|
from gluster.swift.common import utils
|
||||||
import gluster.swift.common.Glusterfs
|
import gluster.swift.common.Glusterfs
|
||||||
@ -64,9 +63,6 @@ def timestamp_in_range(ts, base):
|
|||||||
class TestDiskDirModuleFunctions(unittest.TestCase):
|
class TestDiskDirModuleFunctions(unittest.TestCase):
|
||||||
""" Tests for gluster.swift.common.DiskDir module functions """
|
""" Tests for gluster.swift.common.DiskDir module functions """
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
raise SkipTest
|
|
||||||
|
|
||||||
def test__read_metadata(self):
|
def test__read_metadata(self):
|
||||||
def fake_read_metadata(p):
|
def fake_read_metadata(p):
|
||||||
return { 'a': 1, 'b': ('c', 5) }
|
return { 'a': 1, 'b': ('c', 5) }
|
||||||
@ -180,90 +176,83 @@ class TestDiskDirModuleFunctions(unittest.TestCase):
|
|||||||
out_objs = dd.filter_prefix(in_objs, prefix)
|
out_objs = dd.filter_prefix(in_objs, prefix)
|
||||||
assert list(out_objs) == ['abc_123', 'abc_456', 'abc_789']
|
assert list(out_objs) == ['abc_123', 'abc_456', 'abc_789']
|
||||||
|
|
||||||
|
in_objs, prefix = ['ABC_123', 'ABC_456', 'abc_123', 'abc_456', 'abc_789', 'def_101'], 'abc'
|
||||||
|
out_objs = dd.filter_prefix(in_objs, prefix)
|
||||||
|
assert list(out_objs) == ['abc_123', 'abc_456', 'abc_789']
|
||||||
|
|
||||||
in_objs, prefix = ['abc_123', 'def_101', 'abc_456', 'abc_789'], 'abc'
|
in_objs, prefix = ['abc_123', 'def_101', 'abc_456', 'abc_789'], 'abc'
|
||||||
out_objs = dd.filter_prefix(in_objs, prefix)
|
out_objs = dd.filter_prefix(in_objs, prefix)
|
||||||
assert list(out_objs) == ['abc_123',]
|
assert list(out_objs) == ['abc_123',]
|
||||||
|
|
||||||
def test_filter_delimiter(self):
|
def test_filter_delimiter(self):
|
||||||
in_objs, delimiter, prefix = [], None, ''
|
in_objs, delimiter, prefix, marker = [], None, '', ''
|
||||||
try:
|
try:
|
||||||
out_objs = dd.filter_delimiter(in_objs, delimiter, prefix)
|
out_objs = dd.filter_delimiter(in_objs, delimiter, prefix, marker)
|
||||||
except AssertionError:
|
|
||||||
pass
|
|
||||||
except Exception:
|
|
||||||
raise SkipTest
|
|
||||||
self.fail("Failed to raise assertion")
|
|
||||||
|
|
||||||
in_objs, delimiter, prefix = [], '', ''
|
|
||||||
try:
|
|
||||||
out_objs = dd.filter_delimiter(in_objs, delimiter, prefix)
|
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
pass
|
pass
|
||||||
except Exception:
|
except Exception:
|
||||||
self.fail("Failed to raise assertion")
|
self.fail("Failed to raise assertion")
|
||||||
|
|
||||||
in_objs, delimiter, prefix = [], str(255), ''
|
in_objs, delimiter, prefix, marker = [], '', '', ''
|
||||||
try:
|
try:
|
||||||
out_objs = dd.filter_delimiter(in_objs, delimiter, prefix)
|
out_objs = dd.filter_delimiter(in_objs, delimiter, prefix, marker)
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
pass
|
pass
|
||||||
except Exception:
|
except Exception:
|
||||||
self.fail("Failed to raise assertion")
|
self.fail("Failed to raise assertion")
|
||||||
|
|
||||||
in_objs, delimiter, prefix = [], '_', ''
|
in_objs, delimiter, prefix, marker = [], str(255), '', ''
|
||||||
out_objs = dd.filter_delimiter(in_objs, delimiter, prefix)
|
try:
|
||||||
|
out_objs = dd.filter_delimiter(in_objs, delimiter, prefix, marker)
|
||||||
|
except AssertionError:
|
||||||
|
pass
|
||||||
|
except Exception:
|
||||||
|
self.fail("Failed to raise assertion")
|
||||||
|
|
||||||
|
in_objs, delimiter, prefix, marker = [], '_', '', ''
|
||||||
|
out_objs = dd.filter_delimiter(in_objs, delimiter, prefix, marker)
|
||||||
assert list(out_objs) == []
|
assert list(out_objs) == []
|
||||||
|
|
||||||
in_objs, delimiter, prefix = ['abc_'], '_', ''
|
in_objs, delimiter, prefix, marker = ['abc_'], '_', '', ''
|
||||||
out_objs = dd.filter_delimiter(in_objs, delimiter, prefix)
|
out_objs = dd.filter_delimiter(in_objs, delimiter, prefix, marker)
|
||||||
assert list(out_objs) == in_objs
|
assert list(out_objs) == in_objs
|
||||||
|
|
||||||
in_objs, delimiter, prefix = ['abc_123', 'abc_456'], '_', ''
|
in_objs, delimiter, prefix, marker = ['abc_123', 'abc_456'], '_', '', ''
|
||||||
out_objs = dd.filter_delimiter(in_objs, delimiter, prefix)
|
out_objs = dd.filter_delimiter(in_objs, delimiter, prefix, marker)
|
||||||
assert list(out_objs) == ['abc_']
|
assert list(out_objs) == ['abc_']
|
||||||
|
|
||||||
in_objs, delimiter, prefix = ['abc_123', 'abc_456', 'def_123', 'def_456'], '_', ''
|
in_objs, delimiter, prefix, marker = ['abc_123', 'abc_456', 'def_123', 'def_456'], '_', '', ''
|
||||||
out_objs = dd.filter_delimiter(in_objs, delimiter, prefix)
|
out_objs = dd.filter_delimiter(in_objs, delimiter, prefix, marker)
|
||||||
assert list(out_objs) == ['abc_', 'def_']
|
assert list(out_objs) == ['abc_', 'def_']
|
||||||
|
|
||||||
in_objs, delimiter, prefix = ['abc_123', 'abc_456', 'abc_789', 'def_101'], '_', 'abc_'
|
in_objs, delimiter, prefix, marker = ['abc_123', 'abc_456', 'abc_789', 'def_101'], '_', 'abc_', ''
|
||||||
out_objs = dd.filter_delimiter(in_objs, delimiter, prefix)
|
out_objs = dd.filter_delimiter(in_objs, delimiter, prefix, marker)
|
||||||
l = list(out_objs)
|
l = list(out_objs)
|
||||||
assert l == ['abc_123', 'abc_456', 'abc_789'], repr(l)
|
assert l == ['abc_123', 'abc_456', 'abc_789'], repr(l)
|
||||||
|
|
||||||
in_objs, delimiter, prefix = ['abc_123_a', 'abc_456', 'abc_789_', 'def_101'], '_', 'abc_'
|
in_objs, delimiter, prefix, marker = ['abc_123_a', 'abc_456', 'abc_789_', 'def_101'], '_', 'abc_', ''
|
||||||
out_objs = dd.filter_delimiter(in_objs, delimiter, prefix)
|
out_objs = dd.filter_delimiter(in_objs, delimiter, prefix, marker)
|
||||||
assert list(out_objs) == ['abc_123_a', 'abc_789_']
|
l = list(out_objs)
|
||||||
|
assert l == ['abc_123_', 'abc_456', 'abc_789_'], repr(l)
|
||||||
|
|
||||||
def test_filter_limit(self):
|
in_objs, delimiter, prefix, marker, path = ['abc_123_a', 'abc_456', 'abc_789_', 'def_101'], '_', 'abc_', '', ''
|
||||||
try:
|
out_objs = dd.filter_delimiter(in_objs, delimiter, prefix, marker, path)
|
||||||
l = list(dd.filter_limit([], 0))
|
l = list(out_objs)
|
||||||
except AssertionError:
|
# FIXME: This appears to be a bug due to this upstream swift reference
|
||||||
pass
|
# implementation of list_objects_iter, where the presence of a path
|
||||||
else:
|
# forces a code path that does not add the match on a delimiter
|
||||||
self.fail("Accepted a zero limit")
|
assert l == ['abc_456', 'abc_789_'], repr(l)
|
||||||
|
|
||||||
l = list(dd.filter_limit([], 1))
|
in_objs, delimiter, prefix, marker, path = ['abc/123', 'abc/456', 'def/123', 'def/456'], '/', 'abc/', '', ''
|
||||||
assert l == []
|
out_objs = dd.filter_delimiter(in_objs, delimiter, prefix, marker, path)
|
||||||
l = list(dd.filter_limit([1,], 1))
|
l = list(out_objs)
|
||||||
assert l == [1,]
|
assert l == ['abc/123', 'abc/456'], repr(l)
|
||||||
l = list(dd.filter_limit([1,], 10))
|
|
||||||
assert l == [1,]
|
|
||||||
l = list(dd.filter_limit([1,2,3], 1))
|
|
||||||
assert l == [1,]
|
|
||||||
l = list(dd.filter_limit([1,2,3], 2))
|
|
||||||
assert l == [1,2]
|
|
||||||
l = list(dd.filter_limit([1,2,3], 3))
|
|
||||||
assert l == [1,2,3]
|
|
||||||
l = list(dd.filter_limit([1,2,3], 4))
|
|
||||||
assert l == [1,2,3]
|
|
||||||
|
|
||||||
|
|
||||||
class TestDiskCommon(unittest.TestCase):
|
class TestDiskCommon(unittest.TestCase):
|
||||||
""" Tests for gluster.swift.common.DiskDir.DiskCommon """
|
""" Tests for gluster.swift.common.DiskDir.DiskCommon """
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
raise SkipTest
|
|
||||||
_initxattr()
|
_initxattr()
|
||||||
self.fake_logger = FakeLogger()
|
self.fake_logger = FakeLogger()
|
||||||
self.td = tempfile.mkdtemp()
|
self.td = tempfile.mkdtemp()
|
||||||
@ -322,20 +311,6 @@ class TestDiskCommon(unittest.TestCase):
|
|||||||
assert dc.datadir == os.path.join(self.td, "dne0")
|
assert dc.datadir == os.path.join(self.td, "dne0")
|
||||||
assert dc._dir_exists is False
|
assert dc._dir_exists is False
|
||||||
|
|
||||||
def test_initialize(self):
|
|
||||||
dc = dd.DiskCommon(self.td, self.fake_drives[0],
|
|
||||||
self.fake_accounts[0], self.fake_logger)
|
|
||||||
dc.initialize('12345')
|
|
||||||
assert dc.metadata == {}
|
|
||||||
assert dc.db_file == dd._db_file
|
|
||||||
assert dc.pending_timeout == 0
|
|
||||||
assert dc.stale_reads_ok == False
|
|
||||||
assert dc.root == self.td
|
|
||||||
assert dc.logger == self.fake_logger
|
|
||||||
assert dc.account == self.fake_accounts[0]
|
|
||||||
assert dc.datadir == os.path.join(self.td, self.fake_drives[0])
|
|
||||||
assert dc._dir_exists is None
|
|
||||||
|
|
||||||
def test_is_deleted(self):
|
def test_is_deleted(self):
|
||||||
dc = dd.DiskCommon(self.td, self.fake_drives[0],
|
dc = dd.DiskCommon(self.td, self.fake_drives[0],
|
||||||
self.fake_accounts[0], self.fake_logger)
|
self.fake_accounts[0], self.fake_logger)
|
||||||
@ -370,45 +345,6 @@ class TestDiskCommon(unittest.TestCase):
|
|||||||
assert dc.metadata == md_copy
|
assert dc.metadata == md_copy
|
||||||
|
|
||||||
|
|
||||||
class TestDiskDir(unittest.TestCase):
|
|
||||||
""" Tests for gluster.swift.common.DiskDir.DiskDir """
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
_initxattr()
|
|
||||||
self.fake_logger = FakeLogger()
|
|
||||||
self.td = tempfile.mkdtemp()
|
|
||||||
self.fake_drives = []
|
|
||||||
self.fake_accounts = []
|
|
||||||
for i in range(0,3):
|
|
||||||
self.fake_drives.append("drv%d" % i)
|
|
||||||
os.makedirs(os.path.join(self.td, self.fake_drives[i]))
|
|
||||||
self.fake_accounts.append(self.fake_drives[i])
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
_destroyxattr()
|
|
||||||
shutil.rmtree(self.td)
|
|
||||||
|
|
||||||
def test_constructor(self):
|
|
||||||
raise SkipTest
|
|
||||||
self.fail("Implement me")
|
|
||||||
|
|
||||||
def test_empty(self):
|
|
||||||
raise SkipTest
|
|
||||||
self.fail("Implement me")
|
|
||||||
|
|
||||||
def test_list_objects_iter(self):
|
|
||||||
raise SkipTest
|
|
||||||
self.fail("Implement me")
|
|
||||||
|
|
||||||
def test_get_info(self):
|
|
||||||
raise SkipTest
|
|
||||||
self.fail("Implement me")
|
|
||||||
|
|
||||||
def test_delete_db(self):
|
|
||||||
raise SkipTest
|
|
||||||
self.fail("Implement me")
|
|
||||||
|
|
||||||
|
|
||||||
class TestContainerBroker(unittest.TestCase):
|
class TestContainerBroker(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
Tests for DiskDir.DiskDir class (duck-typed
|
Tests for DiskDir.DiskDir class (duck-typed
|
||||||
@ -1281,8 +1217,6 @@ class TestDiskAccount(unittest.TestCase):
|
|||||||
def test_constructor_no_metadata(self):
|
def test_constructor_no_metadata(self):
|
||||||
da = dd.DiskAccount(self.td, self.fake_drives[0],
|
da = dd.DiskAccount(self.td, self.fake_drives[0],
|
||||||
self.fake_accounts[0], self.fake_logger)
|
self.fake_accounts[0], self.fake_logger)
|
||||||
raise SkipTest
|
|
||||||
assert da._container_info is None
|
|
||||||
assert da._dir_exists is True
|
assert da._dir_exists is True
|
||||||
ctime = os.path.getctime(da.datadir)
|
ctime = os.path.getctime(da.datadir)
|
||||||
mtime = os.path.getmtime(da.datadir)
|
mtime = os.path.getmtime(da.datadir)
|
||||||
@ -1298,8 +1232,6 @@ class TestDiskAccount(unittest.TestCase):
|
|||||||
def test_constructor_metadata_not_valid(self):
|
def test_constructor_metadata_not_valid(self):
|
||||||
da = dd.DiskAccount(self.td, self.fake_drives[1],
|
da = dd.DiskAccount(self.td, self.fake_drives[1],
|
||||||
self.fake_accounts[1], self.fake_logger)
|
self.fake_accounts[1], self.fake_logger)
|
||||||
raise SkipTest
|
|
||||||
assert da._container_info is None
|
|
||||||
assert da._dir_exists is True
|
assert da._dir_exists is True
|
||||||
ctime = os.path.getctime(da.datadir)
|
ctime = os.path.getctime(da.datadir)
|
||||||
mtime = os.path.getmtime(da.datadir)
|
mtime = os.path.getmtime(da.datadir)
|
||||||
@ -1316,8 +1248,6 @@ class TestDiskAccount(unittest.TestCase):
|
|||||||
def test_constructor_metadata_valid(self):
|
def test_constructor_metadata_valid(self):
|
||||||
da = dd.DiskAccount(self.td, self.fake_drives[2],
|
da = dd.DiskAccount(self.td, self.fake_drives[2],
|
||||||
self.fake_accounts[2], self.fake_logger)
|
self.fake_accounts[2], self.fake_logger)
|
||||||
raise SkipTest
|
|
||||||
assert da._container_info is None
|
|
||||||
assert da._dir_exists is True
|
assert da._dir_exists is True
|
||||||
ctime = os.path.getctime(da.datadir)
|
ctime = os.path.getctime(da.datadir)
|
||||||
mtime = os.path.getmtime(da.datadir)
|
mtime = os.path.getmtime(da.datadir)
|
||||||
@ -1330,12 +1260,6 @@ class TestDiskAccount(unittest.TestCase):
|
|||||||
'X-Container-Count': (0, 0)}
|
'X-Container-Count': (0, 0)}
|
||||||
assert da.metadata == exp_md, repr(da.metadata)
|
assert da.metadata == exp_md, repr(da.metadata)
|
||||||
|
|
||||||
def test_list_containers_iter(self):
|
|
||||||
da = dd.DiskAccount(self.td, self.fake_drives[0],
|
|
||||||
self.fake_accounts[0], self.fake_logger)
|
|
||||||
raise SkipTest
|
|
||||||
self.fail("Implement me")
|
|
||||||
|
|
||||||
get_info_keys = set(['account', 'created_at', 'put_timestamp',
|
get_info_keys = set(['account', 'created_at', 'put_timestamp',
|
||||||
'delete_timestamp', 'container_count',
|
'delete_timestamp', 'container_count',
|
||||||
'object_count', 'bytes_used', 'hash', 'id'])
|
'object_count', 'bytes_used', 'hash', 'id'])
|
||||||
@ -1380,7 +1304,6 @@ class TestDiskAccount(unittest.TestCase):
|
|||||||
def test_update_put_timestamp_not_updated(self):
|
def test_update_put_timestamp_not_updated(self):
|
||||||
da = dd.DiskAccount(self.td, self.fake_drives[0],
|
da = dd.DiskAccount(self.td, self.fake_drives[0],
|
||||||
self.fake_accounts[0], self.fake_logger)
|
self.fake_accounts[0], self.fake_logger)
|
||||||
raise SkipTest
|
|
||||||
da.update_put_timestamp('12345')
|
da.update_put_timestamp('12345')
|
||||||
assert da.metadata['X-PUT-Timestamp'][0] != '12345', repr(da.metadata)
|
assert da.metadata['X-PUT-Timestamp'][0] != '12345', repr(da.metadata)
|
||||||
|
|
||||||
@ -1389,23 +1312,16 @@ class TestDiskAccount(unittest.TestCase):
|
|||||||
self.fake_accounts[0], self.fake_logger)
|
self.fake_accounts[0], self.fake_logger)
|
||||||
exp_pts = str(float(da.metadata['X-PUT-Timestamp'][0]) + 100)
|
exp_pts = str(float(da.metadata['X-PUT-Timestamp'][0]) + 100)
|
||||||
da.update_put_timestamp(exp_pts)
|
da.update_put_timestamp(exp_pts)
|
||||||
raise SkipTest
|
|
||||||
assert da.metadata['X-PUT-Timestamp'][0] == exp_pts, repr(da.metadata)
|
assert da.metadata['X-PUT-Timestamp'][0] == exp_pts, repr(da.metadata)
|
||||||
|
|
||||||
def test_delete_db(self):
|
def test_delete_db(self):
|
||||||
da = dd.DiskAccount(self.td, self.fake_drives[0],
|
da = dd.DiskAccount(self.td, self.fake_drives[0],
|
||||||
self.fake_accounts[0], self.fake_logger)
|
self.fake_accounts[0], self.fake_logger)
|
||||||
raise SkipTest
|
|
||||||
assert da._dir_exists == True
|
assert da._dir_exists == True
|
||||||
da.delete_db('12345')
|
da.delete_db('12345')
|
||||||
assert da._dir_exists == True
|
assert da._dir_exists == True
|
||||||
|
|
||||||
def test_put_container(self):
|
|
||||||
raise SkipTest
|
|
||||||
self.fail("Implement me")
|
|
||||||
|
|
||||||
def test_is_status_deleted(self):
|
def test_is_status_deleted(self):
|
||||||
da = dd.DiskAccount(self.td, self.fake_drives[0],
|
da = dd.DiskAccount(self.td, self.fake_drives[0],
|
||||||
self.fake_accounts[0], self.fake_logger)
|
self.fake_accounts[0], self.fake_logger)
|
||||||
raise SkipTest
|
|
||||||
assert da.is_status_deleted() == False
|
assert da.is_status_deleted() == False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user