Skip to content

Testing RBD Python Bindings

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.

  1. Make sure that you have the latest code checked out
  2. 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
<...>
  1. Once compiled, start the vstart cluster
bash-5.1# cd /ceph/build/
bash-5.1# source ./vstart_environment.sh
bash-5.1# ../src/vstart.sh -n -d --without-dashboard
  1. 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                                                                              
  1. 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']
  1. 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!')
"

Output

Mirror group methods: ['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']
Mirror info: {'global_id': '', 'image_mode': 1, 'state': 3, 'primary': False}
Done!
bash-5.1# 

Clone this wiki locally