Repository navigation
test/mgr: Improve unit-test coverage for ceph-mgr - #66432
Conversation
NitzanMordhai
left a comment
There was a problem hiding this comment.
@stzuraski898, please check my comments
fda1f87 to
4f92dd2
Compare
NitzanMordhai
left a comment
There was a problem hiding this comment.
please check my comments
| digest->mon_status_json.append("status"); | ||
| cs.load_digest(digest.get()); | ||
|
|
||
| SUCCEED(); |
There was a problem hiding this comment.
test that we are setting them correctly
cefc4eb to
3d302ff
Compare
NitzanMordhai
left a comment
There was a problem hiding this comment.
@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.
|
|
||
| /* Begin Negative Tests */ | ||
|
|
||
| TEST(MgrCap, ParseEmptyString) |
There was a problem hiding this comment.
@stzuraski898, why not update the existing tests that we already have for parse? TEST(MgrCap, ParseIdentity)
There was a problem hiding this comment.
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
NitzanMordhai
left a comment
There was a problem hiding this comment.
Looks much better!
0756796 to
11e0f6e
Compare
ronen-fr
left a comment
There was a problem hiding this comment.
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
| { | ||
| return existing_pools; | ||
| } | ||
| const PGMap test_get_pg_map() const |
There was a problem hiding this comment.
Why is the PGMap copied, while the others above are returned as const-ref?
(and - if copied, the first 'const' shouldn't be there)
There was a problem hiding this comment.
I missed this, good catch!
| void SetUp() override | ||
| { | ||
| icp = new ca::io_context_pool(1); | ||
| mc = new MonClient(g_ceph_context, *icp); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I was using tests' scaffolding as a guildeline, after changing to unique_ptr it looks like everything is still working as expected
There was a problem hiding this comment.
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.
| mc = new MonClient(g_ceph_context, *icp); | ||
| objecter = new Objecter(g_ceph_context, messenger, mc, *icp); | ||
|
|
||
| assert(objecter != nullptr); |
There was a problem hiding this comment.
regular assert? you have used SetUp(), which means, I think, you can use ASSERT here
There was a problem hiding this comment.
Conceptually it looks like a part of the testing program's logic, not necessarily of the logic being tested.
Anyway, ceph_assert is preferable.
|
|
||
| protected: | ||
| static inline ca::io_context_pool *icp; | ||
| Messenger* messenger = nullptr; |
There was a problem hiding this comment.
see my unique_ptr question above
| std::string expected = R"({"epoch":123,"modified":"0.000000","services":{"svc":{"daemons":{"summary":"testSummary"}}}})"; | ||
| std::ostringstream oss; | ||
| std::string json_str; | ||
| JSONFormatter f; |
There was a problem hiding this comment.
same for the Formatter and elsewhere: always declate objects just where needed.
| d.gid = 123; | ||
| f.dump_object("daemon", d); | ||
| f.flush(oss); | ||
| std::string output = oss.str(); |
There was a problem hiding this comment.
consider making 'output' const. Reduces the mental load on the reader.
| EXPECT_NE(output.find("\"metadata\": {}"), std::string::npos); | ||
| } | ||
|
|
||
| TEST(ServiceMapService, GetSummaryEmptyString) |
There was a problem hiding this comment.
move upwards, near the other get_summary() test?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I see. Didn't notice the +/- ordering. Your call.
|
NB - one additional comment: |
Agreed, I pulled these additions out and have created a ClusterStateTestHelper class which holds the getters instead |
|
I think I got to everything else, but I'm not sure what you meant by:
|
| void SetUp() override | ||
| { | ||
| icp = new ca::io_context_pool(1); | ||
| mc = new MonClient(g_ceph_context, *icp); |
There was a problem hiding this comment.
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.
| mc = new MonClient(g_ceph_context, *icp); | ||
| objecter = new Objecter(g_ceph_context, messenger, mc, *icp); | ||
|
|
||
| assert(objecter != nullptr); |
There was a problem hiding this comment.
Conceptually it looks like a part of the testing program's logic, not necessarily of the logic being tested.
Anyway, ceph_assert is preferable.
| assert(objecter != nullptr); | ||
| assert(mc != nullptr); | ||
| delete cs; | ||
| cs = nullptr; | ||
| objecter->shutdown(); | ||
| mc->shutdown(); | ||
| delete objecter; | ||
| objecter = nullptr; | ||
| delete mc; | ||
| mc = nullptr; |
There was a problem hiding this comment.
Pretty much of boring boilerplate that a smart pointer would deduplicate & hide.
| class ClusterStateTest : public TestMgr | ||
| { | ||
| public: | ||
| ceph::ref_t<DeviceState> device; |
There was a problem hiding this comment.
ACK, an intrusive pointer. (I'm making the "ACK notes" just to the record).
| 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}; |
There was a problem hiding this comment.
nit: let's be consistent and initialize with = or {} but without mixing the styles.
| TEST_F(TestMgr, ClusterState_Setters) | ||
| { | ||
| Objecter* original_objecter = objecter; | ||
| Objecter* new_objecter = new Objecter(g_ceph_context, messenger, mc, *icp); |
There was a problem hiding this comment.
Why to allocate on the heap? It seems the instance's life time fits the life-time of the stack frame.
ronen-fr
left a comment
There was a problem hiding this comment.
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 |
0b59e40 to
dcab7cd
Compare
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. |
|
And - good work! |
dcab7cd to
f00e976
Compare
| Memcheck:Leak | ||
| match-leak-kinds: all | ||
| ... | ||
| fun:UnknownInlinedFun |
There was a problem hiding this comment.
This is a function (as I think its attribute says) or is it an error designation?
There was a problem hiding this comment.
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.
b1b4342 to
452f862
Compare
| const bufferlist mon_status_bl = [] { | ||
| bufferlist bl; | ||
| bl.append("{\"monmap\":{\"epoch\":1}}"); | ||
| return bl; | ||
| }(); |
There was a problem hiding this comment.
This reminds me bufferlist lacks a constructor for the cases like this one.
Anyway, nice workaround.
|
|
||
| OSDMap::Incremental notify_inc(osd_map.get_epoch() + 1); | ||
| notify_inc.new_pool_max = 2; | ||
| notify_inc.new_pools[1] = pool1; |
There was a problem hiding this comment.
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_poolsThere was a problem hiding this comment.
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); |
There was a problem hiding this comment.
OK. Just to the record:
PyObject *get()
{
finish_pending_streams();
Py_INCREF(root);
return root;
}| /*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 */ |
| "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 = { |
There was a problem hiding this comment.
I assume this only a pure refactor.
2398d8d to
cc794d7
Compare
|
jenkins test api |
|
jenkins test make check |
8dc96ce to
48e2879
Compare
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
109f6af to
97427eb
Compare
97427eb to
26893c4
Compare
|
jenkins test make check arm64 |
2 similar comments
|
jenkins test make check arm64 |
|
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.
26893c4 to
eaa2013
Compare
|
jenkins test make check |
|
jenkins test docs |
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
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job DefinitionYou must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.