Skip to content

test/mgr: Add scaffolding and surface level tests to various objects within the Mgr - #71237

Open
stzuraski898 wants to merge 15 commits into
ceph:mainfrom
stzuraski898:wip-sz-77389-wideMgrScaffolding
Open

stzuraski898 wants to merge 15 commits into
ceph:mainfrom
stzuraski898:wip-sz-77389-wideMgrScaffolding

Conversation

@stzuraski898

@stzuraski898 stzuraski898 commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

So far, unit testing of the Mgr has been focused on writing tests for specific objects, adding scaffolding to TestMgr.h as needed. This PR introduces scaffolding needed to test objects within the Mgr so that parallel testing efforts can be undertaken, with a consistent starting point.

Each test file contains at minimum one SetUp/TearDown round trip, verifying that the object can be constructed and destroyed without crashing. PerfCounterInstance and PyModuleRegistry have deeper coverage of their public APIs (circular-buffer behaviour, client registration/replace semantics, module query methods).

These tests in these commits are meant to be a starting point to enable future testing efforts, and are by no means a complete or comprehensive testing effort.

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

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 i added some comments

Comment thread src/test/mgr/TestMgr.h Resolved
Comment thread src/test/mgr/CMakeLists.txt Resolved
Comment thread src/test/mgr/TestMgr.h Resolved
Comment thread src/test/mgr/test_standbypymodules.cc Resolved
@stzuraski898
stzuraski898 force-pushed the wip-sz-77389-wideMgrScaffolding branch from a3f8d29 to e643a1e Compare August 24, 2026 17:27
@stzuraski898

Copy link
Copy Markdown
Contributor Author

@NitzanMordhai I've pushed changes that should resolve the issues stated, going to look further into the finish function. The changes have introduced a warning, which I'm not sure should be fixed as part of this effort:

[313/372] Building CXX object src/test/mgr/CMakeFiles/unittest_mgr_map_cache_obj.dir/__/__/mgr/MgrMapCache.cc.o In file included from /usr/include/python3.14/pyconfig.h:6, from /usr/include/python3.14/Python.h:14, from /home/szuraski/ceph/src/mgr/PyUtil.h:8, from /home/szuraski/ceph/src/mgr/MgrMapCache.h:28, from /home/szuraski/ceph/src/mgr/MgrMapCache.cc:16: /usr/include/python3.14/pyconfig-64.h:340:9: warning: ‘HAVE_EVENTFD’ redefined 340 | #define HAVE_EVENTFD 1 | ^~~~~~~~~~~~ In file included from /home/szuraski/ceph/src/include/ceph_assert.h:23, from /home/szuraski/ceph/src/common/perf_histogram.h:26, from /home/szuraski/ceph/src/common/perf_counters.h:31, from /home/szuraski/ceph/src/mgr/MgrMapCache.h:26: /home/szuraski/ceph/build/include/acconfig.h:278:9: note: this is the location of the previous definition 278 | #define HAVE_EVENTFD | ^~~~~~~~~~~~ /usr/include/python3.14/pyconfig-64.h:485:9: warning: ‘HAVE_GETENTROPY’ redefined 485 | #define HAVE_GETENTROPY 1 | ^~~~~~~~~~~~~~~ /home/szuraski/ceph/build/include/acconfig.h:346:9: note: this is the location of the previous definition 346 | #define HAVE_GETENTROPY | ^~~~~~~~~~~~~~~ [314/372] Building CXX object src/test/mgr/CMakeFiles/unittest_mgr_common_obj.dir/__/__/mgr/MgrMapCache.cc.o In file included from /usr/include/python3.14/pyconfig.h:6, from /usr/include/python3.14/Python.h:14, from /home/szuraski/ceph/src/mgr/PyUtil.h:8, from /home/szuraski/ceph/src/mgr/MgrMapCache.h:28, from /home/szuraski/ceph/src/mgr/MgrMapCache.cc:16: /usr/include/python3.14/pyconfig-64.h:340:9: warning: ‘HAVE_EVENTFD’ redefined 340 | #define HAVE_EVENTFD 1 | ^~~~~~~~~~~~ In file included from /home/szuraski/ceph/src/include/ceph_assert.h:23, from /home/szuraski/ceph/src/common/perf_histogram.h:26, from /home/szuraski/ceph/src/common/perf_counters.h:31, from /home/szuraski/ceph/src/mgr/MgrMapCache.h:26: /home/szuraski/ceph/build/include/acconfig.h:278:9: note: this is the location of the previous definition 278 | #define HAVE_EVENTFD | ^~~~~~~~~~~~ /usr/include/python3.14/pyconfig-64.h:485:9: warning: ‘HAVE_GETENTROPY’ redefined 485 | #define HAVE_GETENTROPY 1 | ^~~~~~~~~~~~~~~ /home/szuraski/ceph/build/include/acconfig.h:346:9: note: this is the location of the previous definition 346 | #define HAVE_GETENTROPY | ^~~~~~~~~~~~~~~ [315/372] Building CXX object src/test/mgr/CMakeFiles/unittest_mgr_common_obj.dir/__/__/mgr/PyModuleRegistry.cc.o In file included from /usr/include/python3.14/pyconfig.h:6, from /usr/include/python3.14/Python.h:14, from /home/szuraski/ceph/src/mgr/PyModule.h:25, from /home/szuraski/ceph/src/mgr/PyModuleRegistry.h:19, from /home/szuraski/ceph/src/mgr/PyModuleRegistry.cc:15: /usr/include/python3.14/pyconfig-64.h:340:9: warning: ‘HAVE_EVENTFD’ redefined 340 | #define HAVE_EVENTFD 1 | ^~~~~~~~~~~~ In file included from /home/szuraski/ceph/src/include/compat.h:15, from /home/szuraski/ceph/src/common/ceph_context.h:33, from /home/szuraski/ceph/src/mgr/PyModule.h:22: /home/szuraski/ceph/build/include/acconfig.h:278:9: note: this is the location of the previous definition 278 | #define HAVE_EVENTFD | ^~~~~~~~~~~~ /usr/include/python3.14/pyconfig-64.h:485:9: warning: ‘HAVE_GETENTROPY’ redefined 485 | #define HAVE_GETENTROPY 1 | ^~~~~~~~~~~~~~~ /home/szuraski/ceph/build/include/acconfig.h:346:9: note: this is the location of the previous definition 346 | #define HAVE_GETENTROPY | ^~~~~~~~~~~~~~~ [316/372] Building CXX object src/test/mgr/CMakeFiles/unittest_mgr_common_obj.dir/__/__/mgr/ThreadMonitor.cc.o In file included from /usr/include/python3.14/pyconfig.h:6, from /usr/include/python3.14/Python.h:14, from /home/szuraski/ceph/src/mgr/PyModule.h:25, from /home/szuraski/ceph/src/mgr/ThreadMonitor.h:16, from /home/szuraski/ceph/src/mgr/ThreadMonitor.cc:14: /usr/include/python3.14/pyconfig-64.h:340:9: warning: ‘HAVE_EVENTFD’ redefined 340 | #define HAVE_EVENTFD 1 | ^~~~~~~~~~~~ In file included from /home/szuraski/ceph/src/include/compat.h:15, from /home/szuraski/ceph/src/common/ceph_context.h:33, from /home/szuraski/ceph/src/mgr/PyModule.h:22: /home/szuraski/ceph/build/include/acconfig.h:278:9: note: this is the location of the previous definition 278 | #define HAVE_EVENTFD | ^~~~~~~~~~~~ /usr/include/python3.14/pyconfig-64.h:485:9: warning: ‘HAVE_GETENTROPY’ redefined 485 | #define HAVE_GETENTROPY 1 | ^~~~~~~~~~~~~~~ /home/szuraski/ceph/build/include/acconfig.h:346:9: note: this is the location of the previous definition 346 | #define HAVE_GETENTROPY | ^~~~~~~~~~~~~~~ [332/372] Building CXX object src/test/mgr/CMakeFiles/unittest_mgr_common_obj.dir/__/__/mgr/DaemonServer.cc.o In file included from /usr/include/python3.14/pyconfig.h:6, from /usr/include/python3.14/Python.h:14, from /home/szuraski/ceph/src/mgr/PyModule.h:25, from /home/szuraski/ceph/src/mgr/PyModuleRegistry.h:19, from /home/szuraski/ceph/src/mgr/DaemonServer.h:18, from /home/szuraski/ceph/src/mgr/DaemonServer.cc:15: /usr/include/python3.14/pyconfig-64.h:340:9: warning: ‘HAVE_EVENTFD’ redefined 340 | #define HAVE_EVENTFD 1 | ^~~~~~~~~~~~ In file included from /home/szuraski/ceph/src/include/compat.h:15, from /home/szuraski/ceph/src/common/ceph_context.h:33, from /home/szuraski/ceph/src/mgr/PyModule.h:22: /home/szuraski/ceph/build/include/acconfig.h:278:9: note: this is the location of the previous definition 278 | #define HAVE_EVENTFD | ^~~~~~~~~~~~ /usr/include/python3.14/pyconfig-64.h:485:9: warning: ‘HAVE_GETENTROPY’ redefined 485 | #define HAVE_GETENTROPY 1 | ^~~~~~~~~~~~~~~ /home/szuraski/ceph/build/include/acconfig.h:346:9: note: this is the location of the previous definition 346 | #define HAVE_GETENTROPY | ^~~~~~~~~~~~~~~ [371/372] Linking CXX executable bin/unittest_mgr_mgr

The tests build and run without issue otherwise

@dvanders dvanders mentioned this pull request Aug 25, 2026
4 of 14 tasks
@stzuraski898
stzuraski898 force-pushed the wip-sz-77389-wideMgrScaffolding branch from e643a1e to 8fd5b60 Compare September 2, 2026 21:33

@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 new comments on your changes.

Comment thread src/test/mgr/CMakeLists.txt Resolved
Comment thread src/test/mgr/test_pymoduleregistry.cc Outdated
bool needs_restart = registry->handle_mgr_map(mgr_map);
ASSERT_FALSE(needs_restart);

needs_restart = registry->handle_mgr_map(mgr_map);

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 explain. it looks like you are calling with the same mgr_map, what is the difference?

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.

The first call exercises the if (mgr_map.epoch == 0) { path

And the second handles the else. Both asserts may be false, but they are testing different return locations.

Comment thread src/test/mgr/test_pyosdmap.cc Resolved
Comment thread src/test/mgr/TestMgr.h Resolved
Comment thread src/test/mgr/TestMgr.h Outdated
}
};

class MgrStandbyTestHelper : public TestMgr {

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.

Can you please explain why we also have that class and StandbyPyModulesTestHelper - they look exactly the same

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.

There shouldn't be, will combine into one.

@stzuraski898
stzuraski898 force-pushed the wip-sz-77389-wideMgrScaffolding branch from 8fd5b60 to b5d4a21 Compare September 3, 2026 21:01
@stzuraski898

Copy link
Copy Markdown
Contributor Author

@NitzanMordhai think I've gotten to everything, I also did a second look over the setup and tests, and for an initial 'prove the setup works' state I think these are sufficient.

Next after this PR will be implementing deeper test coverage for each object.

@stzuraski898

Copy link
Copy Markdown
Contributor Author

jenkins test windows

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Several named test targets never instantiate or exercise the component they claim to cover.

Review effort: Balanced
Findings: 3 Medium severity

Open (3)
What changed in this PR

Adds reusable manager test scaffolding and initial unit tests for manager components.

Changes:

  • Introduces fixtures for manager services, collectors, Python modules, and counters.
  • Adds construction and public-API tests.
  • Refactors CMake targets around shared object libraries.
File Description
src/​test/​mgr/​TestMgr.h Adds shared fixtures and mocks.
src/​test/​mgr/​test_threadmonitor.cc Tests ThreadMonitor construction.
src/​test/​mgr/​test_standbypymodules.cc Tests standby Python-module construction.
src/​test/​mgr/​test_pyosdmap.cc Adds OSDMap behavior tests.
src/​test/​mgr/​test_pymodulerunner.cc Tests runner dependencies.
src/​test/​mgr/​test_pymoduleregistry.cc Tests registry queries and clients.
src/​test/​mgr/​test_perfcounterinstance.cc Tests counter buffering behavior.
src/​test/​mgr/​test_osdperfmetriccollector.cc Tests OSD collector initialization.
src/​test/​mgr/​test_mgrstandby.cc Checks standby scaffolding.
src/​test/​mgr/​test_mgroprequest.cc Tests tracked request creation.
src/​test/​mgr/​test_mgrclient.cc Tests client lifecycle.
src/​test/​mgr/​test_mgr.cc Checks manager scaffolding.
src/​test/​mgr/​test_metriccollector.cc Tests collector construction.
src/​test/​mgr/​test_mdsperfmetriccollector.cc Adds MDS collector test target.
src/​test/​mgr/​test_daemonserver.cc Checks daemon-server scaffolding.
src/​test/​mgr/​test_daemonperfcounters.cc Tests empty counter initialization.
src/​test/​mgr/​test_daemonhealthmetriccollector.cc Tests collector factory behavior.
src/​test/​mgr/​CMakeLists.txt Registers and shares unit-test sources.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +7 to +9
TEST_F(MetricCollectorTestHelper, MDSPerfMetricCollectorBasicSetup) {
ASSERT_NE(cct, nullptr);
}
Comment thread src/test/mgr/test_pymodulerunner.cc Outdated
Comment on lines +19 to +22
TEST_F(TestMgr, PyModuleRunner_PyModuleCreation) {
auto py_module = std::make_shared<PyModule>("test_module");
ASSERT_NE(py_module, nullptr);
EXPECT_EQ(py_module->get_name(), "test_module");

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 that issue as well

Comment thread src/test/mgr/test_pyosdmap.cc Outdated
Comment on lines +8 to +10
TEST_F(PyOSDMapTest, OSDMapInitialized) {
ASSERT_EQ(osd_map.get_epoch(), 1);
}

@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

Comment thread src/test/mgr/CMakeLists.txt Resolved
Comment thread src/test/mgr/CMakeLists.txt Outdated
@@ -1,7 +1,68 @@
set(unittest_mgr_base_srcs

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.

That is not a good way to have all those CMakeLists changes in one commit. What will happen if you need to revert 1 of the test commits? build will break

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 moved each test entry into the individual commits.

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.

Better, thanks. A few things are left: all the TestMgr.h helpers are still added in the first commit, the MgrOpRequest commit adds no test (test_mgroprequest.cc is already on main, so the commit title is misleading), and the PyModuleRunner commit has no CMake change.

Comment thread src/test/mgr/CMakeLists.txt Outdated
target_include_directories(unittest_mgr_common_obj PRIVATE
$<TARGET_PROPERTY:RocksDB::RocksDB,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:Python3::Python,INTERFACE_INCLUDE_DIRECTORIES>)
target_compile_definitions(unittest_mgr_common_obj PRIVATE UNIT_TESTS_BUILT)

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.

All those target_compile_definitions(unittest_mgr_common_obj PRIVATE UNIT_TESTS_BUILT) are redundant, you can remove them (8 places)

Comment thread src/test/mgr/CMakeLists.txt Outdated
${unittest_mgr_common_with_mgr_objs}
)
add_ceph_unittest(unittest_mgr_pyosdmap)
target_compile_definitions(unittest_mgr_pyosdmap PRIVATE UNIT_TESTS_BUILT)

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.

remove that line

Comment thread src/test/mgr/CMakeLists.txt Outdated
${unittest_mgr_common_with_mgr_objs}
)
add_ceph_unittest(unittest_mgr_pymodulerunner)
target_compile_definitions(unittest_mgr_pymodulerunner PRIVATE UNIT_TESTS_BUILT)

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.

remove that line

Comment thread src/test/mgr/CMakeLists.txt Outdated
${unittest_mgr_common_with_mgr_objs}
)
add_ceph_unittest(unittest_mgr_standbypymodules)
target_compile_definitions(unittest_mgr_standbypymodules PRIVATE UNIT_TESTS_BUILT)

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.

remove that line

Comment thread src/test/mgr/CMakeLists.txt Outdated
${unittest_mgr_common_with_mgr_objs}
)
add_ceph_unittest(unittest_mgr_daemonserver)
target_compile_definitions(unittest_mgr_daemonserver PRIVATE UNIT_TESTS_BUILT)

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.

remove that line

Comment thread src/test/mgr/CMakeLists.txt Outdated
${CMAKE_SOURCE_DIR}/src/mgr/MgrStandby.cc
)
add_ceph_unittest(unittest_mgr_mgrstandby)
target_compile_definitions(unittest_mgr_mgrstandby PRIVATE UNIT_TESTS_BUILT)

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.

remove that line

Comment thread src/test/mgr/CMakeLists.txt Outdated
${unittest_mgr_common_with_mgr_objs}
)
add_ceph_unittest(unittest_mgr_mgr)
target_compile_definitions(unittest_mgr_mgr PRIVATE UNIT_TESTS_BUILT)

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.

remove that line

Comment thread src/test/mgr/test_pyosdmap.cc Outdated
TEST_F(PyOSDMapTest, OSDMapInitialized) {
ASSERT_EQ(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.

Please check the copilot comment here - test_pyosdmap never tested any pyosdmap, it only tests osdmap .. change the name or change the 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.

same for test_pymodulerunner.cc

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 updated the tests, the primary goal was to just have the scaffolding in place but now we do some surface level verification that setup was successful.

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.

The new test_pymodulerunner.cc never builds, because the unittest_mgr_pymodulerunner target is gone from CMakeLists.txt. Please add the target back in the PyModuleRunner commit.

@stzuraski898
stzuraski898 force-pushed the wip-sz-77389-wideMgrScaffolding branch from b5d4a21 to b071e59 Compare October 26, 2026 16:41
@stzuraski898
stzuraski898 requested a review from a team as a code owner October 26, 2026 16:41
stzuraski898 added a commit to stzuraski898/ceph that referenced this pull request Oct 26, 2026
src/test/mgr/test_perfcounterinstance.cc and its unittest target do not
exist on the base branch. Cherry-pick the PerfCounterInstance scaffolding
(the test file and a unittest_mgr_perfcounterinstance CMake target) from
ceph/ceph PR ceph#71237 as a temporary measure until that PR merges; this
should be reconciled when the PR lands.

Only the PerfCounterInstance scaffolding is imported. PR ceph#71237 wires the
target through OBJECT libraries; here the target links the
PerfCounterInstance.cc source directly to remain self-contained on the
base branch.

Signed-off-by: Steven Zuraski <[email protected]>
Assisted-by: Claude Code (Opus 4.8)
stzuraski898 added a commit to stzuraski898/ceph that referenced this pull request Oct 26, 2026
Introduce src/test/mgr/test_perfcounterinstance.cc and its
unittest_mgr_perfcounterinstance CMake target. This scaffolding does not
exist on ceph-origin/main; it is cherry-picked from
ceph#71237 as a temporary measure until that
PR merges, and should be reconciled when the PR lands. Only the
PerfCounterInstance test file and its target are taken; no other test
files from that PR are imported. The CMake target is adapted to the base
branch's conventions (compiling src/mgr/PerfCounterInstance.cc directly),
mirroring the existing unittest_mgr_daemonstate target.

Coordinated with #81019, which cherry-picks the same file; if both land,
the scaffolding is added once.

Fixes: https://tracker.ceph.com/issues/81020
Signed-off-by: Steven Zuraski <[email protected]>
Assisted-by: Claude Code (Opus 4.8)
stzuraski898 added a commit to stzuraski898/ceph that referenced this pull request Oct 26, 2026
The MgrOpRequest unit-test harness does not exist on the base branch, so
the test fixture (MgrOpRequestTestHelper) and a BasicSetup smoke test are
cherry-picked from the pending scaffolding in ceph/ceph PR ceph#71237, kept
self-contained as a temporary measure. They should be reconciled with
src/test/mgr/TestMgr.h when PR ceph#71237 lands.

Adds the unittest_mgr_mgroprequest target to src/test/mgr/CMakeLists.txt,
linking only the mgr object that provides MgrOpRequest.

#81341 cherry-picks the same scaffolding; if both land, the scaffolding
is added once.

Fixes: https://tracker.ceph.com/issues/81340
Assisted-by: Claude Opus 4.8
Signed-off-by: Steven Zuraski <[email protected]>
@stzuraski898
stzuraski898 force-pushed the wip-sz-77389-wideMgrScaffolding branch from b071e59 to da1f798 Compare October 27, 2026 22:23

@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 fix the new comments, also check the CmakeLists again, we have few files that compiled more then one time, we can reduce it, also check PyFormatter, PyUtil, ServiceMap, MgrMapCache, the 5 MetricCollector files, DaemonHealthMetric*, ThreadMonitor and MgrOpRequest

Comment thread src/test/mgr/TestMgr.h Outdated
return mod;
}
};
using PyModuleRunnerTest = PyModuleRunnerTestHelper;

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.

That one is never used, do we really need it?

Comment thread src/test/mgr/CMakeLists.txt Outdated
)
add_ceph_unittest(unittest_mgr_mgroprequest)
if(WITH_LTTNG)
add_dependencies(unittest_mgr_mgroprequest mgr_op_tp)

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 if that add_dependencies is really needed, you have 9 of those, i think you can drop them

set(unittest_mgr_daemonstate_srcs
${CMAKE_SOURCE_DIR}/src/mgr/DaemonState.cc
${CMAKE_SOURCE_DIR}/src/mgr/DaemonPerfCounters.cc
${CMAKE_SOURCE_DIR}/src/mgr/PerfCounterInstance.cc

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 do we need PerfCounterInstance.cc compiled 3 times? (lines 9, 26 and 166)

@@ -1,7 +1,68 @@
set(unittest_mgr_base_srcs
${CMAKE_SOURCE_DIR}/src/mgr/ClusterState.cc

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.

ClusterState.cc compiled twice..

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.

Each file is compiled once now, thanks. But putting ClusterState.cc and DaemonKey.cc in one object library means daemonkey, pyformatter, pyutil, daemonstate and the other small tests now link ClusterState, which they didn't on main. Separate object libraries for each would fix that.

@@ -1,7 +1,68 @@
set(unittest_mgr_base_srcs
${CMAKE_SOURCE_DIR}/src/mgr/ClusterState.cc
${CMAKE_SOURCE_DIR}/src/mgr/DaemonKey.cc

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.

DaemonKey.cc compiled twice

@stzuraski898
stzuraski898 force-pushed the wip-sz-77389-wideMgrScaffolding branch from da1f798 to f765add Compare October 30, 2026 19:53
@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath37-testing-20261124.044935-main.

@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

Comment thread src/test/mgr/test_mgrstandby.cc Outdated
ASSERT_NE(cs->test_get_objecter(), nullptr);
ASSERT_EQ(mgr_map.epoch, 0);
ASSERT_GE(osd_map.get_epoch(), 0);
}

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.

Could we exercise MgrStandby itself here? BasicSetup checks objects created by the fixture, so it would still pass if the MgrStandby constructor failed. If there’s no standby behavior we want to cover yet, I’d leave this target out for now

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.

Sure, we can do that. I dropped the MgrStandby commit. The BasicSetup 'test' was mostly aimed at proving the scaffolding works, rather than being a real test. The goal of this PR was to get scaffolding in place, to follow up with unit test coverage for individual objects in future efforts.

Comment thread src/test/mgr/test_threadmonitor.cc Outdated
ASSERT_NE(cct, nullptr);
}

TEST_F(ThreadMonitorTestHelper, Construction) {

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.

The fixture already constructs and destroys a ThreadMonitor for each test. Could we use that instance to call start_monitoring() and stop_monitoring()? That would exercise shutdown with a worker that has actually started.

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 added three tests that use thread_monitor, StartAndStopMonitoring, RestartMonitoring, DestroyWhileMonitoring

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

PyObject *takes_obj = PyObject_CallMethod(py_crush, "_find_takes", nullptr);
ASSERT_NE(takes_obj, nullptr);
EXPECT_TRUE(PyDict_Check(takes_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.

Could we give the map a known root and a rule, then check the IDs returned under roots and takes? Python callers look up those keys by name. With an empty map and only PyDict_Check, both wrappers could return {} or swap the key names and the test would still pass

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.

The test now builds two root buckets, and empty results or swapped keys would now fail, and because the two sets differ, so would swapping the two wrappers' results.


registry->register_client("test_client", addrs2, true);
clients = registry->get_clients();
ASSERT_EQ(clients.size(), 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.

Could we also check that test_client maps to addrs2 after the second registration? The size is one either way, so keeping the old addrs1 would pass this test too.

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.

The test now checks that the stored value = addrs2, and does not equal addrs1.


MockMetricListener mds_listener;
MDSPerfMetricCollector mds_collector(mds_listener);
ASSERT_EQ(mds_listener.update_count, 0);

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.

Could we add a first query, check that the listener gets one notification, then remove its last registration and check for a second? Both counters start at zero, so the current assertions would pass even if MetricCollector stopped calling handle_query_updated() altogether

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.

Yes, I've done this for both the OSD and MDS collectors. I also added a check that removing an unknown query ID returns -ENOENT and sends no notification.

Comment thread src/test/mgr/test_daemonserver.cc Outdated
#include "TestMgr.h"
#include "mgr/DaemonServer.h"

TEST_F(DaemonServerTestHelper, BasicSetup) {

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.

Could we use this test to exercise a DaemonServer operation, such as adding and removing a perf query? These assertions only check pointers that SetUp() just initialized, and MgrTestHelper.ConstructAndDestruct already covers construction through Mgr::server. I’d defer the separate executable if there’s no server behavior we need to check yet

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.

(see above about original intentions)

Sure this is doable, and I've added the tests.

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

void SetUp() override {
TestMgr::SetUp();
if (!main_ts) {

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.

Could we pass the fixture’s save_ts to the runner? If Google Test repeats the suite and recreates its global environment, PythonEnv starts a new interpreter, but the static main_ts still points into the old one. The runner then uses that pointer during teardown. PyEval_SaveThread() already gives us the right state for each setup.

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.

Done

)

add_library(unittest_mgr_common_obj OBJECT ${unittest_mgr_common_srcs})
target_include_directories(unittest_mgr_common_obj PRIVATE

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.

Could we give this target the same PY_SSIZE_T_CLEAN definition as ceph-mgr? It compiles ActivePyModule.cc separately. On Python 3.10 through 3.12, the s# format used by _handle_command raises SystemError without that definition, so a command could work in the daemon and fail in the 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 added target_compile_definitions(unittest_mgr_common_obj PRIVATE PY_SSIZE_T_CLEAN)

Comment thread src/test/mgr/CMakeLists.txt Outdated
target_include_directories(unittest_mgr_common_obj PRIVATE
$<TARGET_PROPERTY:RocksDB::RocksDB,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:Python3::Python,INTERFACE_INCLUDE_DIRECTORIES>)
target_link_libraries(unittest_mgr_common_obj legacy-option-headers)

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.

Could we add SQLite3::SQLite3 to unittest_mgr_common_obj when WITH_LIBCEPHSQLITE is enabled? This target compiles Mgr.cc, so it needs SQLite’s include directory. Linking SQLite only to the test executables leaves sqlite3.h out of the compile command when SQLite is installed outside the
default include path

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.

Yes, unittest_mgr_common_obj's link to SQLite3 has been updated

@SrinivasaBharath

SrinivasaBharath commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

@stzuraski898 - I encountered a merge conflict while creating the Shaman build. Could you please resolve the conflict and re-add the needs-qa label once it is resolved?

Successfully aborted conflicted merge, repository is clean
PR #71237 has merge conflicts with previously merged changes. Please resolve conflicts manually or rebase the PR.

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been removed from wip-bharath37-testing-20261124.044935-main.

Factor shared src/mgr unit test sources into object libraries and reuse
them across the test/mgr executables instead of compiling the same mgr
source files repeatedly for each test binary.

This keeps the existing test coverage while reducing redundant
compilation in mgr unit test builds.

Fixes: https://tracker.ceph.com/issues/77389
Signed-off-by: Steven Zuraski <[email protected]>
Assisted-by: IBM Bob
@stzuraski898
stzuraski898 force-pushed the wip-sz-77389-wideMgrScaffolding branch from 9d616cf to fe80b16 Compare November 30, 2026 15:09
stzuraski898 added a commit to stzuraski898/ceph that referenced this pull request Dec 1, 2026
Introduce src/test/mgr/test_perfcounterinstance.cc and its
unittest_mgr_perfcounterinstance CMake target.

This commit is temporary scaffolding cherry-picked from
ceph#71237 (branch wip-sz-77389-wideMgrScaffolding)
and should be taken out once PR 71237 is merged.

Only the PerfCounterInstance test file and its target are taken; no other
test files from that PR are imported. The CMake target compiles
src/mgr/PerfCounterInstance.cc directly, mirroring the existing
unittest_mgr_daemonstate target.

Signed-off-by: Steven Zuraski <[email protected]>
Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]>
Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]>
Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]>
Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]>
Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]>
Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]>
Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]>
Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]>
Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]>
Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]>
Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]>
Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]>
Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]>
Assisted-by: IBM Bob
Signed-off-by: Steven Zuraski <[email protected]>
Assisted-by: IBM Bob
@stzuraski898
stzuraski898 force-pushed the wip-sz-77389-wideMgrScaffolding branch from fe80b16 to ba8c386 Compare December 3, 2026 00:24
@stzuraski898

Copy link
Copy Markdown
Contributor Author

I believe all comments have been addressed in the newest push @tchaikov @NitzanMordhai

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.

5 participants