New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mon,mgr: improve 'mgr module disable' cmd #21188
Conversation
|
b1bfe39
to
8d8943d
Compare
src/mon/MgrMap.h
Outdated
@@ -179,6 +179,17 @@ class MgrMap | |||
return false; | |||
} | |||
|
|||
bool enabled_module(const std::string &module_name) const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering: would it make sense to rename this to module_enabled
or is_enabled
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.
src/mon/MgrMonitor.cc
Outdated
} | ||
if (!pending_map.enabled_module(module)) { | ||
ss << "module " << module << " is already disabled"; | ||
r = -EINVAL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not desired behaviour -- all Ceph CLI operations should be idempotent, so disabling a disabled module should return 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
src/mon/MgrMonitor.cc
Outdated
@@ -895,6 +900,16 @@ bool MgrMonitor::prepare_command(MonOpRequestRef op) | |||
r = -EINVAL; | |||
goto out; | |||
} | |||
if (!pending_map.all_support_module(module)) { | |||
ss << "module " << module << " does not exist"; | |||
r = -ENOENT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would agree that disabling a nonexistent module should be an error (in order to detect mistyped module names), but I don't think all_support_module
is the right check. We should accept a disable command if any mgr has reported the module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jcsp , I re-checked the all_support_module(), it seems it included all mgrs' reported modules(both active and standby). Could you point out why it is not the right check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If module foo
is enabled, and module foo
is installed on mgr.x
, but not mgr.y
, then all_support_module would return false and we would return -ENOENT. The correct behaviour in that case would be to proceed with successfully disabling the module, even if some mgr daemons do not have it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jcsp got it. I updated the fix, please take a look.
src/mon/MgrMonitor.cc
Outdated
@@ -887,6 +887,11 @@ bool MgrMonitor::prepare_command(MonOpRequestRef op) | |||
r = -ENOENT; | |||
goto out; | |||
} | |||
if (pending_map.enabled_module(module)) { | |||
ss << "module " << module << " is already enabled"; | |||
r = -EINVAL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as in the disable case, if the module is already enabled then we must return 0 to be idempotent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
091cef2
to
f325b1a
Compare
src/mon/MgrMap.h
Outdated
return false; | ||
} | ||
|
||
bool module_existed(const std::string& module) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest naming this function any_support_module
so that its relationship with all_support_module
is more obvious
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jcsp fixed.
src/mon/MgrMap.h
Outdated
@@ -179,6 +179,29 @@ class MgrMap | |||
return false; | |||
} | |||
|
|||
bool module_enabled(const std::string &module_name) const | |||
{ | |||
for (const auto &name : modules) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since modules
is a std::set
, you can make this function a one-liner modules.find(module_name) != modules.end()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jcsp fixed.
f325b1a
to
b0c3120
Compare
src/mon/MgrMonitor.cc
Outdated
@@ -895,6 +900,16 @@ bool MgrMonitor::prepare_command(MonOpRequestRef op) | |||
r = -EINVAL; | |||
goto out; | |||
} | |||
if (!pending_map.any_support_module(module)) { | |||
ss << "module " << module << " does not exist"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this breaks the test of test_mon_misc()
in qa/workunits/cephtool/test.sh, see http://pulpito.ceph.com/kchai-2018-04-13_07:54:02-rados-wip-kefu-testing-2018-04-13-1431-distro-basic-smithi/2394008/
2018-04-13T08:13:18.738 INFO:tasks.workunit.client.0.smithi109.stderr:/home/ubuntu/cephtest/clone.client.0/qa/workunits/cephtool/test.sh:751: test_mon_misc: ceph mgr module disable foodne
2018-04-13T08:13:19.020 INFO:tasks.workunit.client.0.smithi109.stderr:Error ENOENT: module foodne does not exist
probably we could just drop this check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should move the check inside the !pending_map.module_enabled
block, so that the test can still disable a non-existent module if the module was enabled with --force at some point.
Then the test should also be updated on the foodnebizbangbash
line to expect that to fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jcsp how about set the retval =0, if pending_map.any_support_module(module) is false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually what I just suggested was wrong because it wouldn't be idempotent. We need to return 0 from all these cases.
However, in the !pending_map.any_support_module(module)
we can't just return, because it might still need removing from the list of enabled modules if it was added with --force. We can do that by moving this block after the !pending_map.module_enabled(module)
one, and just set the ss
output rather then returning.
So I think the correct code would be:
if (!pending_map.module_enabled(module)) {
ss << "module " << module << " is already disabled";
r = 0;
goto out;
}
if (!pending_map.any_support_module(module)) {
ss << "module " << module << " does not exist";
}
pending_map.modules.erase(module);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b0c3120
to
2ae847e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, could you squash these two commits into a single one?
src/mon/MgrMap.h
Outdated
@@ -179,6 +179,23 @@ class MgrMap | |||
return false; | |||
} | |||
|
|||
bool module_enabled(const std::string &module_name) const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please be consistent where to put the &
. i'd suggest put it right next to std::string
.
src/mon/MgrMap.h
Outdated
@@ -179,6 +179,23 @@ class MgrMap | |||
return false; | |||
} | |||
|
|||
bool module_enabled(const std::string &module_name) const | |||
{ | |||
return (modules.find(module_name) != modules.end()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, remove the parentheses around this statement.
src/mon/MgrMap.h
Outdated
return (modules.find(module_name) != modules.end()); | ||
} | ||
|
||
bool any_support_module(const std::string& module) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mark this method const
, if you please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"any" is singular, so should be "supports", i guess?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either way is probably fine. I had been reading this as a contraction of "[do] any [daemons] support module" rather than "[if] any [daemon] supports module". I don't even know the right grammar terminology to describe the difference though :-D
src/mon/MgrMonitor.cc
Outdated
@@ -895,6 +895,14 @@ bool MgrMonitor::prepare_command(MonOpRequestRef op) | |||
r = -EINVAL; | |||
goto out; | |||
} | |||
if (!pending_map.module_enabled(module)) { | |||
ss << "module " << module << " is already disabled"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'd suggest add quotes around "module", like
ss << "module '" << module << "' is already disabled";
src/mon/MgrMonitor.cc
Outdated
goto out; | ||
} | ||
if (!pending_map.any_support_module(module)) { | ||
ss << "module " << module << " does not exist"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto.
retest this please (jenkins) |
2ae847e
to
1cabf79
Compare
@tchaikov all your comments are addressed. please take a look. |
@guzhongyan needs rebase |
when running those cmds, check if the module do exist or is disabled already. also check if the module is enabled already. Signed-off-by: Gu Zhongyan <guzhongyan@360.cn>
1cabf79
to
a7677c7
Compare
@tchaikov rebased, Thanks. |
check if the module do exist or is disabled already.
Signed-off-by: Gu Zhongyan guzhongyan@360.cn