|
|
|
import sys
|
|
import rados
|
|
import threading
|
|
|
|
expected_blob = "my fancy blob"
|
|
object_name = "aio_read_test"
|
|
pool = "test_pool"
|
|
conffile = str(sys.argv[1])
|
|
|
|
# Use 10 minutes to ensure we will not reach it
|
|
timeout = 60 * 10
|
|
|
|
# Create the test object
|
|
with rados.Rados(conffile=conffile) as r:
|
|
try:
|
|
r.create_pool("test_pool")
|
|
except rados.ObjectExists:
|
|
pass
|
|
with r.open_ioctx(pool) as io:
|
|
io.write_full(object_name, expected_blob)
|
|
|
|
|
|
def do_sync_test(name, options):
|
|
with rados.Rados(conffile=conffile, conf=options) as r:
|
|
with r.open_ioctx(pool) as io:
|
|
blob = io.read(object_name)
|
|
print("%s read(): '%s' : %s" % (name, blob, blob == expected_blob))
|
|
|
|
|
|
def do_async_test(name, options):
|
|
with rados.Rados(conffile=conffile, conf=options) as r:
|
|
with r.open_ioctx(pool) as io:
|
|
waiter = threading.Event()
|
|
blob = {'data': "", "length_or_errno": None}
|
|
|
|
def read(comp, data):
|
|
blob['length_or_errno'] = comp.get_return_value()
|
|
blob['data'] = data
|
|
waiter.set()
|
|
|
|
io.aio_read(object_name, len(expected_blob), 0, read)
|
|
waiter.wait(timeout=30)
|
|
|
|
print("%s aio_read(): '%s' (length or errno: %s) : %s" % (
|
|
name, blob['data'], blob['length_or_errno'],
|
|
blob["data"] == expected_blob))
|
|
|
|
|
|
do_sync_test("no timeout", {})
|
|
do_sync_test("with timeout", {"rados_osd_op_timeout": str(timeout)})
|
|
do_async_test("no timeout", {})
|
|
do_async_test("with timeout", {"rados_osd_op_timeout": str(timeout)})
|
|
|
|
with rados.Rados(conffile=conffile) as r:
|
|
r.delete_pool("test_pool")
|