1
|
|
2
|
import sys
|
3
|
import rados
|
4
|
import threading
|
5
|
|
6
|
expected_blob = "my fancy blob"
|
7
|
object_name = "aio_read_test"
|
8
|
pool = "test_pool"
|
9
|
conffile = str(sys.argv[1])
|
10
|
|
11
|
|
12
|
timeout = 60 * 10
|
13
|
|
14
|
|
15
|
with rados.Rados(conffile=conffile) as r:
|
16
|
try:
|
17
|
r.create_pool("test_pool")
|
18
|
except rados.ObjectExists:
|
19
|
pass
|
20
|
with r.open_ioctx(pool) as io:
|
21
|
io.write_full(object_name, expected_blob)
|
22
|
|
23
|
|
24
|
def do_sync_test(name, options):
|
25
|
with rados.Rados(conffile=conffile, conf=options) as r:
|
26
|
with r.open_ioctx(pool) as io:
|
27
|
blob = io.read(object_name)
|
28
|
print("%s read(): '%s' : %s" % (name, blob, blob == expected_blob))
|
29
|
|
30
|
|
31
|
def do_async_test(name, options):
|
32
|
with rados.Rados(conffile=conffile, conf=options) as r:
|
33
|
with r.open_ioctx(pool) as io:
|
34
|
waiter = threading.Event()
|
35
|
blob = {'data': "", "length_or_errno": None}
|
36
|
|
37
|
def read(comp, data):
|
38
|
blob['length_or_errno'] = comp.get_return_value()
|
39
|
blob['data'] = data
|
40
|
waiter.set()
|
41
|
|
42
|
io.aio_read(object_name, len(expected_blob), 0, read)
|
43
|
waiter.wait(timeout=30)
|
44
|
|
45
|
print("%s aio_read(): '%s' (length or errno: %s) : %s" % (
|
46
|
name, blob['data'], blob['length_or_errno'],
|
47
|
blob["data"] == expected_blob))
|
48
|
|
49
|
|
50
|
do_sync_test("no timeout", {})
|
51
|
do_sync_test("with timeout", {"rados_osd_op_timeout": str(timeout)})
|
52
|
do_async_test("no timeout", {})
|
53
|
do_async_test("with timeout", {"rados_osd_op_timeout": str(timeout)})
|
54
|
|
55
|
with rados.Rados(conffile=conffile) as r:
|
56
|
r.delete_pool("test_pool")
|