summaryrefslogtreecommitdiffstats
path: root/swift/1.4.8/plugins/utils.py
diff options
context:
space:
mode:
authorPeter Portante <peter.portante@redhat.com>2012-10-16 23:27:21 -0400
committerAnand Avati <avati@redhat.com>2012-10-17 11:04:05 -0700
commitdbe793bcde5d0ba936eceb19bcb8a6f376a0dbc4 (patch)
treeff281eec3636f11366bc89ee2b82f865d54814b5 /swift/1.4.8/plugins/utils.py
parent59dfcf15578e08731f80c1f0c88cd4b7cd79d23d (diff)
object-storage: Refactor code to reduce Swift diffs carried
The upstream Swift code base contains the following commit which adds the ability to modify constraint values using the swift.conf file: https://github.com/openstack/swift/commit/a2ac5efaa64f57fbbe059066c6c4636dfd0715c2 These changes rely on the above commit being back-ported to Swift 1.4.8 (see https://github.com/portante/swift/commit/fc2421b04022ac6bbe9d5014362ec5f99f94c5e0). As a result, a good number of differences we carry can be removed, since the provided swift.conf file now contains the values we need. Along with these changes, we add middleware to get constraints loaded properly (via monkey patching) until subclassing is implemented in a future commit. We further simplify the diffs to a minimal set by storing the timestamp in file system metadata and moving new files to the plugins/middleware directory. Note that the original "gluster" middleware was in the swift.diff file, and has been renamed to "glusterfs" and moved to the new plugins/middleware directory. The "gluster" middleware is now a temporary way to get the constraints properly loaded (both of these middleware pieces should disappear in future commits when we refactor further to subclass the Swift objects instead of patching them). Change-Id: I9dc00d6b6cdd64e277896d75c2fb06431c3e69cb BUG: 862052 Signed-off-by: Peter Portante <peter.portante@redhat.com> Reviewed-on: http://review.gluster.org/4093 Tested-by: Peter Portante <pportant@redhat.com> Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'swift/1.4.8/plugins/utils.py')
-rw-r--r--swift/1.4.8/plugins/utils.py36
1 files changed, 31 insertions, 5 deletions
diff --git a/swift/1.4.8/plugins/utils.py b/swift/1.4.8/plugins/utils.py
index 1c7eeb92f..59e704702 100644
--- a/swift/1.4.8/plugins/utils.py
+++ b/swift/1.4.8/plugins/utils.py
@@ -18,8 +18,9 @@ import os
import errno
import xattr
from hashlib import md5
-from swift.common.utils import normalize_timestamp
+from swift.common.utils import normalize_timestamp, TRUE_VALUES
import cPickle as pickle
+from ConfigParser import ConfigParser, NoSectionError, NoOptionError
X_CONTENT_TYPE = 'Content-Type'
X_CONTENT_LENGTH = 'Content-Length'
@@ -174,6 +175,18 @@ def do_rename(old_path, new_path):
raise
return True
+def _add_timestamp(metadata_i):
+ # At this point we have a simple key/value dictionary, turn it into
+ # key/(value,timestamp) pairs.
+ timestamp = 0
+ metadata = {}
+ for key, value_i in metadata_i.iteritems():
+ if not isinstance(value_i, tuple):
+ metadata[key] = (value_i, timestamp)
+ else:
+ metadata[key] = value_i
+ return metadata
+
def read_metadata(path):
"""
Helper function to read the pickled metadata from a File/Directory .
@@ -301,7 +314,8 @@ def validate_container(metadata):
#logging.warn('validate_container: Metadata missing entries: %s' % metadata)
return False
- if metadata[X_TYPE] == CONTAINER:
+ (value, timestamp) = metadata[X_TYPE]
+ if value == CONTAINER:
return True
logging.warn('validate_container: metadata type is not CONTAINER (%r)' % (value,))
@@ -321,7 +335,8 @@ def validate_account(metadata):
#logging.warn('validate_account: Metadata missing entries: %s' % metadata)
return False
- if metadata[X_TYPE] == ACCOUNT:
+ (value, timestamp) = metadata[X_TYPE]
+ if value == ACCOUNT:
return True
logging.warn('validate_account: metadata type is not ACCOUNT (%r)' % (value,))
@@ -552,7 +567,7 @@ def get_container_metadata(cont_path, memcache=None):
X_PUT_TIMESTAMP: normalize_timestamp(os.path.getmtime(cont_path)),
X_OBJECTS_COUNT: object_count,
X_BYTES_USED: bytes_used}
- return metadata
+ return _add_timestamp(metadata)
def get_account_metadata(acc_path, memcache=None):
containers = []
@@ -564,7 +579,7 @@ def get_account_metadata(acc_path, memcache=None):
X_OBJECTS_COUNT: 0,
X_BYTES_USED: 0,
X_CONTAINER_COUNT: container_count}
- return metadata
+ return _add_timestamp(metadata)
def restore_object(obj_path, metadata):
meta = read_metadata(obj_path)
@@ -623,3 +638,14 @@ def get_account_list(fs_object):
def get_account_id(account):
return RESELLER_PREFIX + md5(account + HASH_PATH_SUFFIX).hexdigest()
+
+__swift_conf = ConfigParser()
+__swift_conf.read(os.path.join('/etc/swift', 'swift.conf'))
+try:
+ _plugin_enabled = __swift_conf.get('DEFAULT', 'Enable_plugin', 'no') in TRUE_VALUES
+except NoOptionError, NoSectionError:
+ _plugin_enabled = False
+del __swift_conf
+
+def plugin_enabled():
+ return _plugin_enabled