From: Sage Weil Date: Fri, 22 Nov 2019 17:24:27 +0000 (-0600) Subject: Merge PR #31698 into master X-Git-Tag: v15.1.0~792 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=378fed3aa00e2292c6a62768784f5885de69e591;p=ceph.git Merge PR #31698 into master * refs/pull/31698/head: rpm,deb: add cephdaemon user and sudoers file ceph-daemon: use mgr/ssh command to create the ssh key mgr/ssh: add 'ssh generate-key' and 'ssh clear-key' commands mgr/ssh: add mode option mgr/ssh: add 'ssh get-pub-key' and 'ssh get-user' commands mgr/ssh: convert to command decorations mgr/orchestrator: move command annotation helpers to orchestrator.py Reviewed-by: Sebastian Wagner --- 378fed3aa00e2292c6a62768784f5885de69e591 diff --cc src/ceph-daemon/ceph-daemon index e3179a97ce62,207e1b71681e..9e4216f3b3d1 --- a/src/ceph-daemon/ceph-daemon +++ b/src/ceph-daemon/ceph-daemon @@@ -60,28 -60,8 +60,9 @@@ except ImportError import uuid from distutils.spawn import find_executable +from functools import wraps from glob import glob - try: - from tempfile import TemporaryDirectory # py3 - except ImportError: - # define a minimal (but sufficient) equivalent for <= py 3.2 - class TemporaryDirectory(object): # type: ignore - def __init__(self): - self.name = tempfile.mkdtemp() - - def __enter__(self): - if not self.name: - self.name = tempfile.mkdtemp() - return self.name - - def cleanup(self): - shutil.rmtree(self.name) - - def __exit__(self, exc_type, exc_value, traceback): - self.cleanup() - container_path = None @@@ -1184,42 -1111,10 +1141,21 @@@ def command_bootstrap() logger.info('Adding key to root@localhost\'s authorized_keys...') if not os.path.exists('/root/.ssh'): os.mkdir('/root/.ssh', 0o700) - with open('/root/.ssh/authorized_keys', 'a') as f: + auth_keys_file = '/root/.ssh/authorized_keys' + add_newline = False + if os.path.exists(auth_keys_file): + with open(auth_keys_file, 'r') as f: + f.seek(0, 2) + if f.tell() > 0: + f.seek(-1, 2) # go to last character + if f.read() != '\n': + add_newline = True + with open(auth_keys_file, 'a') as f: os.fchmod(f.fileno(), 0o600) # just in case we created it + if add_newline: + f.write('\n') f.write(ssh_pub.strip() + '\n') - logger.info('Enabling ssh module...') - cli(['mgr', 'module', 'enable', 'ssh']) - logger.info('Setting orchestrator backend to ssh...') - cli(['orchestrator', 'set', 'backend', 'ssh']) host = get_hostname() logger.info('Adding host %s...' % host) cli(['orchestrator', 'host', 'add', host])