You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Imran Imtiaz edited this page Feb 5, 2026
·
3 revisions
Testing RBD Python Bindings
When adding new API endpoints, it's likely that you'll need the underlying Python bindings that you can then invoke in the API controller. This guide provides a very high level overview how you can sanity check any new bindings that you add. In this guide we focus on the RBD mirroring component, however the steps will be valid for any component.
Make sure that you have the latest code checked out
If you are making changes to the C/C++ files then you'll have to first compile the Ceph code so you can create the Python binding, however, as in our case the C/C++ symbols are already exposed, so we just add bindings to the pyx files e.g. src/pybind/rbd/rbd.pyx then we build the Python modules with ninja e.g. cd /build; ninja -j20 cython_rbd
Note: These steps will not work in ceph-dev as the ninja command may not have all the dependencies, so these are general steps that you'd run on a machine where you build Ceph.
imrani@hroor ~ podman exec -it 1195129f900d /bin/bash
bash-5.1# cd /ceph/build
bash-5.1# ninja -j 20 cython_rbd
[0/1] Re-running CMake...
-- BUILD_TYPE is Debug
-- Building with ccache: /usr/bin/ccache, CCACHE_DIR=
-- allocator selected: tcmalloc
-- CPM: Adding package Catch2@3.8.1 (v3.8.1)
-- Enabled Catch2 support
<...>
Setup RBD mirroring on the pool, so we can check if the rbd methods (Pythong binding) we added are available:
bash-5.1# ./bin/ceph osd pool create rbd
pool 'rbd' created
bash-5.1# ./bin/rbd pool init rbd
bash-5.1# ./bin/rbd mirror pool enable rbd image
Finally verify that the Python methods exist
bash-5.1# python3
Python 3.9.18 (main, Jan 4 2024, 00:00:00)
[GCC 11.4.1 20231218 (Red Hat 11.4.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import rbd
>>> print([m for m in dir(rbd.Group) if 'mirror_group' in m])
['aio_mirror_group_create_snapshot', 'aio_mirror_group_get_info', 'mirror_group_create_snapshot', 'mirror_group_demote', 'mirror_group_disable', 'mirror_group_enable', 'mirror_group_get_global_status', 'mirror_group_get_info', 'mirror_group_get_instance_id', 'mirror_group_promote', 'mirror_group_resync']
At this point we are ready to thoroughly test the newly added Python bindings e.g.
python3 -c "
import rados, rbd
cluster = rados.Rados(conffile='/ceph/build/ceph.conf')
cluster.connect()
ioctx = cluster.open_ioctx('rbd')
print('Mirror group methods:', [m for m in dir(rbd.Group) if 'mirror_group' in m])
try: rbd.RBD().group_remove(ioctx, 'test_group')
except: pass
rbd.RBD().group_create(ioctx, 'test_group')
with rbd.Group(ioctx, 'test_group') as group:
print('Mirror info:', group.mirror_group_get_info())
rbd.RBD().group_remove(ioctx, 'test_group')
ioctx.close()
cluster.shutdown()
print('Done!')
"