From aaa18a02a5351365804a95349176666cf3602889 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Wed, 25 Jan 2012 12:46:46 -0500 Subject: [PATCH] Change xattr usage to be more broadly compatible. This patch updates the xattr image cache driver to use methods that are more broadly compatible. The issue here is that there is more than one xattr Python module out there. Specifically, there are: https://github.com/xattr/xattr http://git.k1024.org/pyxattr.git/ The previous glance code expected an interface available in the first version. This patch changes the code to use an interface that is common to both of these. This makes all of the image cache tests working against the current pyxattr package in Fedora. Change-Id: I1fca66cfe914364c921408b676a06387d1de5c2a --- glance/image_cache/drivers/xattr.py | 8 +++----- glance/tests/utils.py | 3 +-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/glance/image_cache/drivers/xattr.py b/glance/image_cache/drivers/xattr.py index bf5fe45a44..abae7208ee 100644 --- a/glance/image_cache/drivers/xattr.py +++ b/glance/image_cache/drivers/xattr.py @@ -461,10 +461,9 @@ def get_xattr(path, key, **kwargs): default using kwargs. """ namespaced_key = _make_namespaced_xattr_key(key) - entry_xattr = xattr.xattr(path) try: - return entry_xattr[namespaced_key] - except KeyError: + return xattr.getxattr(path, namespaced_key) + except IOError: if 'default' in kwargs: return kwargs['default'] else: @@ -477,8 +476,7 @@ def set_xattr(path, key, value): If xattrs aren't supported by the file-system, we skip setting the value. """ namespaced_key = _make_namespaced_xattr_key(key) - entry_xattr = xattr.xattr(path) - entry_xattr.set(namespaced_key, str(value)) + xattr.setxattr(path, namespaced_key, str(value)) def inc_xattr(path, key, n=1): diff --git a/glance/tests/utils.py b/glance/tests/utils.py index 1986ea38c5..5b94bfa273 100644 --- a/glance/tests/utils.py +++ b/glance/tests/utils.py @@ -277,8 +277,7 @@ def xattr_writes_supported(path): return False def set_xattr(path, key, value): - entry_xattr = xattr.xattr(path) - entry_xattr.set("user.%s" % key, str(value)) + xattr.setxattr(path, "user.%s" % key, str(value)) # We do a quick attempt to write a user xattr to a temporary file # to check that the filesystem is even enabled to support xattrs