]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/rgw/rgw_multi/tools.py
4 def append_attr_value(d
, attr
, attrv
):
5 if attrv
and len(str(attrv
)) > 0:
8 def append_attr(d
, k
, attr
):
10 attrv
= getattr(k
, attr
)
13 append_attr_value(d
, attr
, attrv
)
15 def get_attrs(k
, attrs
):
22 def append_query_arg(s
, n
, v
):
25 nv
= '{n}={v}'.format(n
=n
, v
=v
)
28 return '{s}&{nv}'.format(s
=s
, nv
=nv
)
30 class KeyJSONEncoder(boto
.s3
.key
.Key
):
32 def default(k
, versioned
=False):
33 attrs
= ['bucket', 'name', 'size', 'last_modified', 'metadata', 'cache_control',
34 'content_type', 'content_disposition', 'content_language',
35 'owner', 'storage_class', 'md5', 'version_id', 'encrypted',
36 'delete_marker', 'expiry_date', 'VersionedEpoch', 'RgwxTag']
37 d
= get_attrs(k
, attrs
)
38 d
['etag'] = k
.etag
[1:-1]
40 d
['is_latest'] = k
.is_latest
43 class DeleteMarkerJSONEncoder(boto
.s3
.key
.Key
):
46 attrs
= ['name', 'version_id', 'last_modified', 'owner']
47 d
= get_attrs(k
, attrs
)
48 d
['delete_marker'] = True
49 d
['is_latest'] = k
.is_latest
52 class UserJSONEncoder(boto
.s3
.user
.User
):
55 attrs
= ['id', 'display_name']
56 return get_attrs(k
, attrs
)
58 class BucketJSONEncoder(boto
.s3
.bucket
.Bucket
):
61 attrs
= ['name', 'creation_date']
62 return get_attrs(k
, attrs
)
64 class BotoJSONEncoder(json
.JSONEncoder
):
65 def default(self
, obj
):
66 if isinstance(obj
, boto
.s3
.key
.Key
):
67 return KeyJSONEncoder
.default(obj
)
68 if isinstance(obj
, boto
.s3
.deletemarker
.DeleteMarker
):
69 return DeleteMarkerJSONEncoder
.default(obj
)
70 if isinstance(obj
, boto
.s3
.user
.User
):
71 return UserJSONEncoder
.default(obj
)
72 if isinstance(obj
, boto
.s3
.prefix
.Prefix
):
73 return (lambda x
: {'prefix': x
.name
})(obj
)
74 if isinstance(obj
, boto
.s3
.bucket
.Bucket
):
75 return BucketJSONEncoder
.default(obj
)
76 return json
.JSONEncoder
.default(self
, obj
)
79 def dump_json(o
, cls
=BotoJSONEncoder
):
80 return json
.dumps(o
, cls
=cls
, indent
=4)
82 def assert_raises(excClass
, callableObj
, *args
, **kwargs
):
84 Like unittest.TestCase.assertRaises, but returns the exception.
87 callableObj(*args
, **kwargs
)
91 if hasattr(excClass
, '__name__'):
92 excName
= excClass
.__name
__
94 excName
= str(excClass
)
95 raise AssertionError("%s not raised" % excName
)