Skip to content

Cover the RbdManager helper - #100

Merged
insatomcat merged 4 commits into
mainfrom
rbd-unit-coverage
Sep 14, 2026
Merged

insatomcat merged 4 commits into
mainfrom
rbd-unit-coverage

Conversation

@insatomcat

Copy link
Copy Markdown
Member

Second of three PRs on the helpers. helpers/rbd_manager.py goes from 17% to 100% statement and 100% branch coverage, in 114 unit tests, with no Ceph.

Every other test file replaces RbdManager as a whole, so the stubs in tests/ceph_stubs.py can keep raising on use: a test that reaches real Ceph code fails loudly rather than passing against a fake. This file is the exception, since testing the helper means running the code that builds Rados, RBD, Image and Group. Its fixture replaces those four names inside rbd_manager alone, for the duration of a test. Every other file keeps seeing the stubs that raise. The fakes share one state object that Image and Group reach through the I/O context they are handed, the way the real bindings do.

Three defects turned up while writing the tests, each fixed in its own commit.

rollback_image bound img_inst inside its try, so an image that cannot be opened raised UnboundLocalError from the finally and hid the real error. Same shape as the clone rollback fixed in #97.

_get_image and _get_group each tested their freshly built instance against None. A class constructor always returns an instance, so those branches could never run; rbd.Image and rbd.Group signal an absent object by raising, which the callers already propagate.

The constructor caught RbdException around the connection sequence. That is this module's own class, which the Ceph bindings never raise, so an init failure was never logged. It now catches what the bindings actually raise. This is the one behaviour change in the PR: a warning line now appears when a connection fails. The error itself still propagates unchanged.

Nineteen mutations of the module are all caught, among them the unit exponent in the size conversion, the overwrite and deep branches, the force branch of the snapshot purge, the group membership tests, and the pool name in the qemu-img destination.

Branch coverage of the whole project reaches 82% on this branch. Independent of #99, which touches a different module.

109 unit tests against fake Ceph bindings, no cluster.
helpers/rbd_manager.py goes from 17% to 98%.

The stubs in tests/ceph_stubs.py keep raising on use for every other
test file. This one replaces Rados, RBD, Image and Group inside
rbd_manager alone, because testing the helper means running the code
that builds them.

Signed-off-by: Florent Carli <florent.carli@rte-france.com>
img_inst was bound inside the try, so an image that cannot be opened
raised UnboundLocalError from the finally and masked the real error.
Bind it before, as the other methods do.

Signed-off-by: Florent Carli <florent.carli@rte-france.com>
A class constructor always returns an instance, so the "is None" branch
could never run. rbd.Image and rbd.Group signal an absent object by
raising, which the callers already propagate.

Signed-off-by: Florent Carli <florent.carli@rte-france.com>
The handler caught RbdException, which this module raises and the Ceph
bindings never do, so an init failure was never logged. Catch what the
bindings raise instead. The error still propagates unchanged.

Signed-off-by: Florent Carli <florent.carli@rte-france.com>
@sonarqubecloud

Copy link
Copy Markdown

@insatomcat
insatomcat merged commit 3d32c85 into main Sep 14, 2026
5 checks passed
@insatomcat
insatomcat deleted the rbd-unit-coverage branch September 14, 2026 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants