From 4d8908df3072d2cb76615237e52eac765f815e5b Mon Sep 17 00:00:00 2001 From: Ricardo Marques Date: Thu, 6 Aug 2020 10:47:29 +0100 Subject: [PATCH] mgr/cephadm: Prevent unnecessary SSH reconfiguration When 'set-user', 'set-pub-key' or 'set-priv-key' are called two times with the same value, we can ignore the second call. Signed-off-by: Ricardo Marques (cherry picked from commit 4cbf587b686d3b539f98b5c4cab1f0320efbe68c) --- src/pybind/mgr/cephadm/module.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 30405d7100216..4f9c16281d036 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -646,6 +646,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): if ssh_config_fname: self.validate_ssh_config_fname(ssh_config_fname) ssh_options += ['-F', ssh_config_fname] + self.ssh_config = ssh_config # identity ssh_key = self.get_store("ssh_identity_key") @@ -742,6 +743,8 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): """ if inbuf is None or len(inbuf) == 0: return -errno.EINVAL, "", "empty ssh config provided" + if inbuf == self.ssh_config: + return 0, "value unchanged", "" self.set_store("ssh_config", inbuf) self.log.info('Set ssh_config') self._reconfig_ssh() @@ -809,6 +812,8 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): def _set_priv_key(self, inbuf=None): if inbuf is None or len(inbuf) == 0: return -errno.EINVAL, "", "empty private ssh key provided" + if inbuf == self.ssh_key: + return 0, "value unchanged", "" self.set_store("ssh_identity_key", inbuf) self.log.info('Set ssh private key') self._reconfig_ssh() @@ -820,6 +825,8 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): def _set_pub_key(self, inbuf=None): if inbuf is None or len(inbuf) == 0: return -errno.EINVAL, "", "empty public ssh key provided" + if inbuf == self.ssh_pub: + return 0, "value unchanged", "" self.set_store("ssh_identity_pub", inbuf) self.log.info('Set ssh public key') self._reconfig_ssh() @@ -856,6 +863,8 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): 'Set user for SSHing to cluster hosts, passwordless sudo will be needed for non-root users') def set_ssh_user(self, user): current_user = self.ssh_user + if user == current_user: + return 0, "value unchanged", "" self.set_store('ssh_user', user) self._reconfig_ssh() -- 2.39.5