2015-11-26 14:58:42 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2016-08-20 17:00:12 +00:00
|
|
|
import json
|
2015-11-26 14:58:42 +00:00
|
|
|
import mmap
|
2016-08-20 17:00:12 +00:00
|
|
|
import os
|
2015-11-26 14:58:42 +00:00
|
|
|
import subprocess
|
2016-08-20 17:00:12 +00:00
|
|
|
|
2015-11-26 14:58:42 +00:00
|
|
|
|
|
|
|
def get_data_pool():
|
|
|
|
cmd = ['ceph', 'fs', 'ls', '--format=json-pretty']
|
|
|
|
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
|
|
|
|
out = proc.communicate()[0]
|
|
|
|
return json.loads(out)[0]['data_pools'][0]
|
|
|
|
|
2016-08-20 17:00:12 +00:00
|
|
|
|
2015-11-26 14:58:42 +00:00
|
|
|
def main():
|
2016-08-20 17:00:12 +00:00
|
|
|
fd = os.open("testfile", os.O_RDWR | os.O_CREAT | os.O_TRUNC | os.O_DIRECT, 0o644)
|
2015-11-26 14:58:42 +00:00
|
|
|
|
|
|
|
ino = os.fstat(fd).st_ino
|
|
|
|
obj_name = "{ino:x}.00000000".format(ino=ino)
|
|
|
|
pool_name = get_data_pool()
|
|
|
|
|
2016-08-20 17:00:12 +00:00
|
|
|
buf = mmap.mmap(-1, 1)
|
|
|
|
buf.write('1')
|
|
|
|
os.write(fd, buf)
|
2015-11-26 14:58:42 +00:00
|
|
|
|
|
|
|
proc = subprocess.Popen(['rados', '-p', pool_name, 'get', obj_name, 'tmpfile'])
|
2016-08-20 17:00:12 +00:00
|
|
|
proc.wait()
|
2015-11-26 14:58:42 +00:00
|
|
|
|
|
|
|
with open('tmpfile', 'r') as tmpf:
|
|
|
|
out = tmpf.read()
|
|
|
|
if out != '1':
|
|
|
|
raise RuntimeError("data were not written to object store directly")
|
|
|
|
|
|
|
|
with open('tmpfile', 'w') as tmpf:
|
|
|
|
tmpf.write('2')
|
|
|
|
|
|
|
|
proc = subprocess.Popen(['rados', '-p', pool_name, 'put', obj_name, 'tmpfile'])
|
2016-08-20 17:00:12 +00:00
|
|
|
proc.wait()
|
2015-11-26 14:58:42 +00:00
|
|
|
|
|
|
|
os.lseek(fd, 0, os.SEEK_SET)
|
2016-08-20 17:00:12 +00:00
|
|
|
out = os.read(fd, 1)
|
2015-11-26 14:58:42 +00:00
|
|
|
if out != '2':
|
|
|
|
raise RuntimeError("data were not directly read from object store")
|
|
|
|
|
2016-08-20 17:00:12 +00:00
|
|
|
os.close(fd)
|
|
|
|
print('ok')
|
|
|
|
|
2015-11-26 14:58:42 +00:00
|
|
|
|
|
|
|
main()
|