Skip to content

test/mgr: Improve unit-test coverage for ceph-mgr - #66432

Merged
stzuraski898 merged 11 commits into
ceph:mainfrom
stzuraski898:unittests-mgr
Apr 23, 2026
Merged

stzuraski898 merged 11 commits into
ceph:mainfrom
stzuraski898:unittests-mgr

Conversation

@stzuraski898

Copy link
Copy Markdown
Contributor

The current test coverage and the unit-test coverage for ceph-mgr are not enough; changes that have been made sometimes can break the core functions of the mgr
We need to expand the test coverage for classes under src/mgr directory and expand the tests for the mgr modules.

Fixes: https://tracker.ceph.com/issues/72938

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@NitzanMordhai NitzanMordhai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stzuraski898, please check my comments

Comment thread src/test/mgr/CMakeLists.txt Resolved
Comment thread src/test/mgr/CMakeLists.txt Resolved
Comment thread src/test/mgr/CMakeLists.txt Resolved
Comment thread src/test/mgr/test_clusterstate.cc Resolved
Comment thread src/test/mgr/test_clusterstate.cc Resolved
Comment thread src/test/mgr/test_daemonstate.cc Resolved
Comment thread src/test/mgr/test_mgrcap.cc Resolved
Comment thread src/test/mgr/test_pyformatter.cc Resolved
Comment thread src/test/mgr/test_pyformatter.cc Resolved
Comment thread src/test/mgr/test_pyformatter.cc Resolved

@NitzanMordhai NitzanMordhai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check my comments

Comment thread src/test/mgr/test_clusterstate.cc Resolved
Comment thread src/test/mgr/test_clusterstate.cc Resolved
Comment thread src/test/mgr/test_clusterstate.cc Outdated
digest->mon_status_json.append("status");
cs.load_digest(digest.get());

SUCCEED();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test that we are setting them correctly

Comment thread src/test/mgr/TestMgr.h Resolved

@NitzanMordhai NitzanMordhai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stzuraski898, please see my comments. Can you also make sure that other comparisons use existing variables? There are a few more that i didnt commented.
lets also make sure that the we are using TestMgr to reduce the amount of repeated code, like objects that we use all over the tests.

Comment thread src/test/mgr/test_mgrcap.cc Outdated

/* Begin Negative Tests */

TEST(MgrCap, ParseEmptyString)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stzuraski898, why not update the existing tests that we already have for parse? TEST(MgrCap, ParseIdentity)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which tests should be merged? I believe I merged all the negative tests that could be here.

ParseGood, ParseBad, ParseIdentity all just check if the string parses.
The tests I haven't merged are making is_capable calls, which checks the description of an operation against capability. In the negative tests doing this, I'm sending descriptions that should fail, hence the ASSERT_FALSEs

Comment thread src/test/mgr/test_clusterstate.cc Resolved
Comment thread src/test/mgr/test_clusterstate.cc Resolved
Comment thread src/test/mgr/test_clusterstate.cc Resolved
Comment thread src/test/mgr/test_clusterstate.cc Resolved
Comment thread src/test/mgr/test_clusterstate.cc Resolved
Comment thread src/test/mgr/test_clusterstate.cc Resolved
Comment thread src/test/mgr/test_clusterstate.cc Resolved
Comment thread src/test/mgr/test_clusterstate.cc Resolved

@NitzanMordhai NitzanMordhai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks much better!

@stzuraski898
stzuraski898 marked this pull request as ready for review December 31, 2025 19:43
@stzuraski898
stzuraski898 requested a review from a team as a code owner December 31, 2025 19:43

@ronen-fr ronen-fr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically - looks good.
I made some style comments, requesting changes that should be made in all the files (not just where I noted). These include:

  • delay declaring variables to where they are needed. In many cases - that would allow you to mark them as const, too.
  • clang-format (using the approved conf file ((or my conf file, which is better...)))
  • use the RAII constructs of the Formatter(s) where appropiate.
  • use 'contains' instead of fins!=npos
  • ... a few more

Comment thread src/mgr/ClusterState.h Outdated
{
return existing_pools;
}
const PGMap test_get_pg_map() const

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the PGMap copied, while the others above are returned as const-ref?
(and - if copied, the first 'const' shouldn't be there)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this, good catch!

Comment thread src/test/mgr/TestMgr.h Resolved
Comment thread src/test/mgr/TestMgr.h Outdated
void SetUp() override
{
icp = new ca::io_context_pool(1);
mc = new MonClient(g_ceph_context, *icp);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use a unique_ptr instead of most of the 'new's?
(and - not sure that in our case using SetUp/TearDown is better than using the constructor/destructor)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use a unique_ptr instead of most of the 'new's?

I would vote for unique_ptr (and make_unique too) for sure!

(and - not sure that in our case using SetUp/TearDown is better than using the constructor/destructor)

I guess most of our test go that way. It's not so bad from the grep users' perspective.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was using tests' scaffolding as a guildeline, after changing to unique_ptr it looks like everything is still working as expected

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, I made an intrusive_ptr for the CephContext following src/neorados/RADOSImpl.cc as an example. This allowed me to pull context initialization out of test_clusterstate.cc and into SetUpTestSuite inside TestMgr.h, as well as properly initialize the Messenger.

Comment thread src/test/mgr/TestMgr.h Outdated
mc = new MonClient(g_ceph_context, *icp);
objecter = new Objecter(g_ceph_context, messenger, mc, *icp);

assert(objecter != nullptr);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regular assert? you have used SetUp(), which means, I think, you can use ASSERT here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conceptually it looks like a part of the testing program's logic, not necessarily of the logic being tested.

Anyway, ceph_assert is preferable.

Comment thread src/test/mgr/TestMgr.h Outdated

protected:
static inline ca::io_context_pool *icp;
Messenger* messenger = nullptr;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my unique_ptr question above

Comment thread src/test/mgr/test_servicemap.cc Outdated
std::string expected = R"({"epoch":123,"modified":"0.000000","services":{"svc":{"daemons":{"summary":"testSummary"}}}})";
std::ostringstream oss;
std::string json_str;
JSONFormatter f;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for the Formatter and elsewhere: always declate objects just where needed.

Comment thread src/test/mgr/test_servicemap.cc Outdated
d.gid = 123;
f.dump_object("daemon", d);
f.flush(oss);
std::string output = oss.str();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider making 'output' const. Reduces the mental load on the reader.

Comment thread src/test/mgr/test_servicemap.cc Resolved
EXPECT_NE(output.find("\"metadata\": {}"), std::string::npos);
}

TEST(ServiceMapService, GetSummaryEmptyString)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move upwards, near the other get_summary() test?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was organizing by grouping positive / negative tests then sorting by function order in the file being tested. Open to reordering, there'd be a lot more changes to be made if sorting strictly by function order is preferred

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Didn't notice the +/- ordering. Your call.

Comment thread src/test/mgr/test_pyformatter.cc Resolved
@ronen-fr

ronen-fr commented Jan 7, 2026

Copy link
Copy Markdown
Contributor

NB - one additional comment:
I don't think the change in cluster_state.h is required. It is better to derive from cluster-state, and add the getters in the derivative.

@stzuraski898

Copy link
Copy Markdown
Contributor Author

NB - one additional comment: I don't think the change in cluster_state.h is required. It is better to derive from cluster-state, and add the getters in the derivative.

Agreed, I pulled these additions out and have created a ClusterStateTestHelper class which holds the getters instead

@stzuraski898

Copy link
Copy Markdown
Contributor Author

I think I got to everything else, but I'm not sure what you meant by:

  • use the RAII constructs of the Formatter(s) where appropiate.

@rzarzynski rzarzynski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review-in-progress.

Comment thread src/test/mgr/TestMgr.h Outdated
void SetUp() override
{
icp = new ca::io_context_pool(1);
mc = new MonClient(g_ceph_context, *icp);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use a unique_ptr instead of most of the 'new's?

I would vote for unique_ptr (and make_unique too) for sure!

(and - not sure that in our case using SetUp/TearDown is better than using the constructor/destructor)

I guess most of our test go that way. It's not so bad from the grep users' perspective.

Comment thread src/test/mgr/TestMgr.h Outdated
mc = new MonClient(g_ceph_context, *icp);
objecter = new Objecter(g_ceph_context, messenger, mc, *icp);

assert(objecter != nullptr);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conceptually it looks like a part of the testing program's logic, not necessarily of the logic being tested.

Anyway, ceph_assert is preferable.

Comment thread src/test/mgr/TestMgr.h Outdated
Comment on lines +42 to +51
assert(objecter != nullptr);
assert(mc != nullptr);
delete cs;
cs = nullptr;
objecter->shutdown();
mc->shutdown();
delete objecter;
objecter = nullptr;
delete mc;
mc = nullptr;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty much of boring boilerplate that a smart pointer would deduplicate & hide.

Comment thread src/test/mgr/TestMgr.h Outdated
class ClusterStateTest : public TestMgr
{
public:
ceph::ref_t<DeviceState> device;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, an intrusive pointer. (I'm making the "ACK notes" just to the record).

Comment thread src/test/mgr/TestMgr.h Outdated
protected:
ceph::ref_t<MPGStats> stats = ceph::make_ref<MPGStats>();
const mempool::osdmap::map<int64_t, pg_pool_t>& pools = osd_map.get_pools();
OSDMap::Incremental osd_inc{osd_map.get_epoch() + 1};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's be consistent and initialize with = or {} but without mixing the styles.

Comment thread src/test/mgr/test_clusterstate.cc Outdated
TEST_F(TestMgr, ClusterState_Setters)
{
Objecter* original_objecter = objecter;
Objecter* new_objecter = new Objecter(g_ceph_context, messenger, mc, *icp);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why to allocate on the heap? It seems the instance's life time fits the life-time of the stack frame.

@ronen-fr ronen-fr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - apart of some 'C' style code.
See nits and comments.
A question: which .clang-format conf file did you use?

Comment thread src/mgr/ClusterState.h Resolved
Comment thread src/test/mgr/test_daemonstate.cc Resolved
Comment thread src/test/mgr/test_daemonstate.cc Resolved
Comment thread src/test/mgr/test_mgrcap.cc Resolved
Comment thread src/test/mgr/test_mgrcap.cc Resolved
Comment thread src/test/mgr/test_mgrcap.cc Resolved
@stzuraski898

Copy link
Copy Markdown
Contributor Author

LGTM - apart of some 'C' style code. See nits and comments. A question: which .clang-format conf file did you use?

I initially ran with the default one in Ceph, which did some odd things, so I ran with yours as you recommended. The file I used is here: https://github.com/ronen-fr/format/blob/master/.clang-format

@ronen-fr

Copy link
Copy Markdown
Contributor

LGTM - apart of some 'C' style code. See nits and comments. A question: which .clang-format conf file did you use?

I initially ran with the default one in Ceph, which did some odd things, so I ran with yours as you recommended. The file I used is here: https://github.com/ronen-fr/format/blob/master/.clang-format

My apologies for being unclear. The one you used is an old Ceph version, and Ceph has a new one now (using blanks instead of tabs). I won't confuse you further - please use the current Ceph approved conf.

@ronen-fr

Copy link
Copy Markdown
Contributor

And - good work!

Comment thread qa/valgrind.supp
Memcheck:Leak
match-leak-kinds: all
...
fun:UnknownInlinedFun

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a function (as I think its attribute says) or is it an error designation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A function, specifically an inlined function that Valgrind cannot access the original function name of as a result of compiler optimizations from what I've read. In this case it is a CPython function being inlined. I may have generalized too far from the Valgrind flag --gen-suppressions=all, which was overly specific.

Comment on lines +81 to +85
const bufferlist mon_status_bl = [] {
bufferlist bl;
bl.append("{\"monmap\":{\"epoch\":1}}");
return bl;
}();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reminds me bufferlist lacks a constructor for the cases like this one.
Anyway, nice workaround.

Comment thread src/test/mgr/test_clusterstate.cc Outdated

OSDMap::Incremental notify_inc(osd_map.get_epoch() + 1);
notify_inc.new_pool_max = 2;
notify_inc.new_pools[1] = pool1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to the record; new_pools it's a map, not a vector or an array.

mempool::osdmap::map<int64_t,pg_pool_t> new_pools

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed this to use emplace for clarity

PyFormatter py_f;
PyObject* py_obj = py_f.get();
ASSERT_NE(py_obj, nullptr);
Py_DECREF(py_obj);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Just to the record:

  PyObject *get()
  {
    finish_pending_streams();

    Py_INCREF(root);
    return root;
  }

Comment thread src/test/mgr/test_pyutil.cc Outdated
Comment on lines +84 to +93
/*Commented out until Tracker 74181 is resolved
Causes a segfault since there is no guard against bad input
TEST(PyUtil, IntTypeMismatch)
{
PyObject* int_obj = get_python_typed_option_value(Option::TYPE_INT, "abc");
ASSERT_TRUE(PyLong_Check(int_obj));
Py_DECREF(int_obj);
}
*/
/* End Negative Tests */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO.

"profile crash network 1.2.3.4/32",
"allow profile crash network 1.2.3.4/32",
0
const std::vector<std::string> parse_good = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this only a pure refactor.

@yaarith

yaarith commented Feb 23, 2026

Copy link
Copy Markdown
Contributor

jenkins test api

@yaarith

yaarith commented Feb 23, 2026

Copy link
Copy Markdown
Contributor

jenkins test make check

@github-actions

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@stzuraski898

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

2 similar comments
@stzuraski898

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

@stzuraski898

Copy link
Copy Markdown
Contributor Author

jenkins test make check arm64

…stemming from CPython in mgr

Fixes: https://tracker.ceph.com/issues/72938
Signed-off-by: szuraski898 <[email protected]>

Conflicts:
  qa/valgrind.supp

The qa/valgrind.supp file had a conflict with an extra curly brace at the EOF as a result of changes adding CPython suppressions in the unittest-mgr branch, as well as additions coming form main.
Resolved by keeping both: the CPython suppressions for the mgr unit tests and all the rocky10 suppressions from main (rocky10_gcc14_mismatch_delete_map_erase
and rocky10 still reachable rocksdb leak), and removing the extra curly brace after merging.
@stzuraski898

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@stzuraski898

Copy link
Copy Markdown
Contributor Author

jenkins test docs

@stzuraski898
stzuraski898 merged commit 3f1ff1a into ceph:main Apr 23, 2026
6 checks passed
@stzuraski898
stzuraski898 deleted the unittests-mgr branch July 6, 2026 20:18
@stzuraski898 stzuraski898 mentioned this pull request Aug 25, 2026
4 of 14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants