Skip to content
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

Merged
merged 1 commit into from Apr 23, 2018

Conversation

guzhongyan
Copy link
Contributor

check if the module do exist or is disabled already.

Signed-off-by: Gu Zhongyan guzhongyan@360.cn

@guzhongyan
Copy link
Contributor Author

guzhongyan commented Apr 3, 2018

$ceph mgr module ls
{
    "enabled_modules": [
        "balancer",
        "dashboard",
        "restful",
        "status"
    ],
    "disabled_modules": [
        {
            "name": "dashboard_v2",
            "can_run": true,
            "error_string": ""
        },
        {
            "name": "influx",
            "can_run": false,
            "error_string": "influxdb python module not found"
        },
        {
            "name": "localpool",
            "can_run": true,
            "error_string": ""
        },
        {
            "name": "prometheus",
            "can_run": true,
            "error_string": ""
        },
        {
            "name": "selftest",
            "can_run": true,
            "error_string": ""
        },
        {
            "name": "smart",
            "can_run": true,
            "error_string": ""
        },
        {
            "name": "zabbix",
            "can_run": true,
            "error_string": ""
        }
    ]
}
disable an already disabled module
$ceph mgr module disable smart
Error EINVAL: module  smart is already disabled

disable an non existed module
$ceph mgr module disable non_exist_module
Error ENOENT: module  non_exist_module does not exist

enable an already enabled module
$ bin/ceph mgr module enable balancer
Error EINVAL: module balancer is already enabled

@smithfarm smithfarm added the mgr label Apr 3, 2018
@guzhongyan guzhongyan force-pushed the mgr-disable-fix branch 2 times, most recently from b1bfe39 to 8d8943d Compare April 3, 2018 03:20
@guzhongyan guzhongyan changed the title improve 'mgr module disable' cmd mon,mgr: improve 'mgr module disable' cmd Apr 3, 2018
@LenzGr LenzGr requested a review from jcsp April 4, 2018 13:41
src/mon/MgrMap.h Outdated
@@ -179,6 +179,17 @@ class MgrMap
return false;
}

bool enabled_module(const std::string &module_name) const
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

}
if (!pending_map.enabled_module(module)) {
ss << "module " << module << " is already disabled";
r = -EINVAL;
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

@@ -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;
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@@ -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;
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

@guzhongyan guzhongyan force-pushed the mgr-disable-fix branch 2 times, most recently from 091cef2 to f325b1a Compare April 10, 2018 07:26
src/mon/MgrMap.h Outdated
return false;
}

bool module_existed(const std::string& module) {
Copy link
Contributor

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

Copy link
Contributor Author

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) {
Copy link
Contributor

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()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jcsp fixed.

@@ -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";
Copy link
Contributor

@tchaikov tchaikov Apr 13, 2018

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

@jcsp jcsp Apr 13, 2018

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);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jcsp @tchaikov , updated. please take a look.

Copy link
Contributor

@tchaikov tchaikov left a 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
Copy link
Contributor

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());
Copy link
Contributor

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) {
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor

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

@@ -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";
Copy link
Contributor

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";

goto out;
}
if (!pending_map.any_support_module(module)) {
ss << "module " << module << " does not exist";
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto.

@jcsp
Copy link
Contributor

jcsp commented Apr 13, 2018

retest this please (jenkins)

@tchaikov tchaikov dismissed their stale review April 13, 2018 15:45

the test should pass now.

@guzhongyan
Copy link
Contributor Author

@tchaikov all your comments are addressed. please take a look.

@tchaikov
Copy link
Contributor

@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>
@guzhongyan
Copy link
Contributor Author

@tchaikov rebased, Thanks.

@tchaikov tchaikov self-assigned this Apr 23, 2018
@liewegas liewegas added this to the mimic milestone Apr 23, 2018
@liewegas liewegas merged commit 5b99b6f into ceph:master Apr 23, 2018
@guzhongyan guzhongyan deleted the mgr-disable-fix branch April 24, 2018 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
6 participants