From 515ce686bd2ec696797584debf7528c01ccf41ea Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Wed, 6 Jan 2021 14:42:37 +0100 Subject: [PATCH] mgr/cephadm: move _registry_login to serve.py Signed-off-by: Sebastian Wagner --- src/pybind/mgr/cephadm/module.py | 18 +----------------- src/pybind/mgr/cephadm/serve.py | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index b438a564901..9ce330d33ab 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -466,22 +466,6 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, self.log.debug('_kick_serve_loop') self.event.set() - # function responsible for logging single host into custom registry - def _registry_login(self, host: str, url: Optional[str], username: Optional[str], password: Optional[str]) -> Optional[str]: - self.log.debug(f"Attempting to log host {host} into custom registry @ {url}") - # want to pass info over stdin rather than through normal list of args - args_str = json.dumps({ - 'url': url, - 'username': username, - 'password': password, - }) - out, err, code = CephadmServe(self)._run_cephadm( - host, 'mon', 'registry-login', - ['--registry-json', '-'], stdin=args_str, error_ok=True) - if code: - return f"Host {host} failed to login to {url} as {username} with given password" - return None - def serve(self) -> None: """ The main loop of cephadm. @@ -893,7 +877,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule, break if not host: raise OrchestratorError('no hosts defined') - r = self._registry_login(host, url, username, password) + r = CephadmServe(self)._registry_login(host, url, username, password) if r is not None: return 1, '', r # if logins succeeded, store info diff --git a/src/pybind/mgr/cephadm/serve.py b/src/pybind/mgr/cephadm/serve.py index dc0deac21cc..0974728ac3d 100644 --- a/src/pybind/mgr/cephadm/serve.py +++ b/src/pybind/mgr/cephadm/serve.py @@ -136,8 +136,8 @@ class CephadmServe: if self.mgr.cache.host_needs_registry_login(host) and self.mgr.registry_url: self.log.debug(f"Logging `{host}` into custom registry") - r = self.mgr._registry_login(host, self.mgr.registry_url, - self.mgr.registry_username, self.mgr.registry_password) + r = self._registry_login(host, self.mgr.registry_url, + self.mgr.registry_username, self.mgr.registry_password) if r: bad_hosts.append(r) @@ -797,8 +797,8 @@ class CephadmServe: daemon_spec.extra_args.append('--allow-ptrace') if self.mgr.cache.host_needs_registry_login(daemon_spec.host) and self.mgr.registry_url: - self.mgr._registry_login(daemon_spec.host, self.mgr.registry_url, - self.mgr.registry_username, self.mgr.registry_password) + self._registry_login(daemon_spec.host, self.mgr.registry_url, + self.mgr.registry_username, self.mgr.registry_password) daemon_spec.extra_args.extend(['--config-json', '-']) @@ -973,8 +973,8 @@ class CephadmServe: if not host: raise OrchestratorError('no hosts defined') if self.mgr.cache.host_needs_registry_login(host) and self.mgr.registry_url: - self.mgr._registry_login(host, self.mgr.registry_url, - self.mgr.registry_username, self.mgr.registry_password) + self._registry_login(host, self.mgr.registry_url, + self.mgr.registry_username, self.mgr.registry_password) out, err, code = self._run_cephadm( host, '', 'pull', [], image=image_name, @@ -996,3 +996,19 @@ class CephadmServe: msg = 'Failed to pull %s on %s: Cannot decode JSON' % (image_name, host) self.log.exception('%s: \'%s\'' % (msg, '\n'.join(out))) raise OrchestratorError(msg) + + # function responsible for logging single host into custom registry + def _registry_login(self, host: str, url: Optional[str], username: Optional[str], password: Optional[str]) -> Optional[str]: + self.log.debug(f"Attempting to log host {host} into custom registry @ {url}") + # want to pass info over stdin rather than through normal list of args + args_str = json.dumps({ + 'url': url, + 'username': username, + 'password': password, + }) + out, err, code = self._run_cephadm( + host, 'mon', 'registry-login', + ['--registry-json', '-'], stdin=args_str, error_ok=True) + if code: + return f"Host {host} failed to login to {url} as {username} with given password" + return None -- 2.39.5