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
This commit is contained in:
Russell Bryant 2012-01-25 12:46:46 -05:00
parent 8ec2f81e59
commit aaa18a02a5
2 changed files with 4 additions and 7 deletions

View File

@ -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):

View File

@ -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