From 533943d08f58c5da918adf473123357f85b341d5 Mon Sep 17 00:00:00 2001 From: Ilya Dryomov Date: Sun, 9 Jun 2024 10:08:00 +0200 Subject: [PATCH] pybind/rbd: expand what get_parent_image_spec() returns Propagate everything there is in rbd_linked_image_spec_t and rbd_snap_spec_t structures returned by the C API. Signed-off-by: Ilya Dryomov --- qa/tasks/mgr/dashboard/test_rbd.py | 14 ++++++++++++-- src/pybind/rbd/rbd.pyx | 21 ++++++++++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/qa/tasks/mgr/dashboard/test_rbd.py b/qa/tasks/mgr/dashboard/test_rbd.py index c2ffbd48e8a..a872645e33e 100644 --- a/qa/tasks/mgr/dashboard/test_rbd.py +++ b/qa/tasks/mgr/dashboard/test_rbd.py @@ -236,9 +236,14 @@ class RbdTest(DashboardTestCase): 'features_name': JList(JLeaf(str)), 'stripe_count': JLeaf(int, none=True), 'stripe_unit': JLeaf(int, none=True), - 'parent': JObj(sub_elems={'pool_name': JLeaf(str), + 'parent': JObj(sub_elems={'pool_id': JLeaf(int), + 'pool_name': JLeaf(str), 'pool_namespace': JLeaf(str, none=True), + 'image_id': JLeaf(str), 'image_name': JLeaf(str), + 'trash': JLeaf(bool), + 'snap_id': JLeaf(int), + 'snap_namespace_type': JLeaf(int), 'snap_name': JLeaf(str)}, none=True), 'data_pool': JLeaf(str, none=True), 'snapshots': JList(JLeaf(dict)), @@ -256,7 +261,12 @@ class RbdTest(DashboardTestCase): self.assertSchema(img, schema) for k, v in kwargs.items(): - if isinstance(v, list): + if k == 'parent' and v is not None: + # check that img['parent'] contains (is a superset of) v + actual = {pk: img['parent'][pk] + for pk in v.keys() if pk in img['parent']} + self.assertEqual(actual, v) + elif isinstance(v, list): self.assertSetEqual(set(img[k]), set(v)) else: self.assertEqual(img[k], v) diff --git a/src/pybind/rbd/rbd.pyx b/src/pybind/rbd/rbd.pyx index 0b0b64670ec..6650b08c935 100644 --- a/src/pybind/rbd/rbd.pyx +++ b/src/pybind/rbd/rbd.pyx @@ -3187,9 +3187,23 @@ cdef class Image(object): Get spec of the cloned image's parent :returns: dict - contains the following keys: + + * ``pool_id`` (int) - parent pool id + * ``pool_name`` (str) - parent pool name + * ``pool_namespace`` (str) - parent pool namespace + + * ``image_id`` (str) - parent image id + * ``image_name`` (str) - parent image name + + * ``trash`` (bool) - True if parent image is in trash bin + + * ``snap_id`` (int) - parent snapshot id + + * ``snap_namespace_type`` (int) - parent snapshot namespace type + * ``snap_name`` (str) - parent snapshot name :raises: :class:`ImageNotFound` if the image doesn't have a parent @@ -3202,9 +3216,14 @@ cdef class Image(object): if ret != 0: raise make_ex(ret, 'error getting parent info for image %s' % self.name) - result = {'pool_name': decode_cstr(parent_spec.pool_name), + result = {'pool_id': parent_spec.pool_id, + 'pool_name': decode_cstr(parent_spec.pool_name), 'pool_namespace': decode_cstr(parent_spec.pool_namespace), + 'image_id': decode_cstr(parent_spec.image_id), 'image_name': decode_cstr(parent_spec.image_name), + 'trash': parent_spec.trash, + 'snap_id': snap_spec.id, + 'snap_namespace_type': snap_spec.namespace_type, 'snap_name': decode_cstr(snap_spec.name)} rbd_linked_image_spec_cleanup(&parent_spec) -- 2.39.5