Merge pull request #37635 from jecluis/wip-46816

mon: have 'mon stat' output json as well

Reviewed-by: Jan Fajerski <jfajerski@suse.com>
Reviewed-by: Kefu Chai <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2020-10-19 14:08:09 +08:00 committed by GitHub
commit a40337c2d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 4 deletions

View File

@ -1166,6 +1166,7 @@ function test_mon_mon()
expect_false ceph mon feature set abcd
expect_false ceph mon feature set abcd --yes-i-really-mean-it
# test elector
expect_failure $TEMP_DIR ceph mon add disallowed_leader $first
ceph mon set election_strategy disallow
ceph mon add disallowed_leader $first
@ -1173,6 +1174,11 @@ function test_mon_mon()
ceph mon rm disallowed_leader $first
ceph mon set election_strategy classic
expect_failure $TEMP_DIR ceph mon rm disallowed_leader $first
# test mon stat
# don't check output, just ensure it does not fail.
ceph mon stat
ceph mon stat -f json | jq '.'
}
function test_mon_priority_and_weight()

View File

@ -313,10 +313,29 @@ bool MonmapMonitor::preprocess_command(MonOpRequestRef op)
boost::scoped_ptr<Formatter> f(Formatter::create(format));
if (prefix == "mon stat") {
mon->monmap->print_summary(ss);
ss << ", election epoch " << mon->get_epoch() << ", leader "
<< mon->get_leader() << " " << mon->get_leader_name()
<< ", quorum " << mon->get_quorum() << " " << mon->get_quorum_names();
if (f) {
f->open_object_section("monmap");
mon->monmap->dump_summary(f.get());
f->dump_string("leader", mon->get_leader_name());
f->open_array_section("quorum");
for (auto rank: mon->get_quorum()) {
std::string name = mon->monmap->get_name(rank);
f->open_object_section("mon");
f->dump_int("rank", rank);
f->dump_string("name", name);
f->close_section(); // mon
}
f->close_section(); // quorum
f->close_section(); // monmap
f->flush(ss);
} else {
mon->monmap->print_summary(ss);
ss << ", election epoch " << mon->get_epoch() << ", leader "
<< mon->get_leader() << " " << mon->get_leader_name()
<< ", quorum " << mon->get_quorum()
<< " " << mon->get_quorum_names();
}
rdata.append(ss);
ss.str("");
r = 0;