]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
Merge PR #31908 into master
authorSage Weil <sage@redhat.com>
Wed, 4 Dec 2019 13:06:34 +0000 (07:06 -0600)
committerSage Weil <sage@redhat.com>
Wed, 4 Dec 2019 13:06:34 +0000 (07:06 -0600)
* refs/pull/31908/head:
ceph-daemon: use uid/gid 0 when creating tempfiles
ceph-daemon: drop unneeded `mode` during tmpfile create
ceph-daemon: consolidate NamedTemporaryFile logic
ceph-daemon: chown uid/gid `ceph-volume` tmpfiles

Reviewed-by: Sage Weil <sage@redhat.com>
Reviewed-by: Sebastian Wagner <swagner@suse.com>
1  2 
src/ceph-daemon/ceph-daemon

index 97d0892d6b9fe6ebca27eedd81046d459882b35b,f4dafd264a8e1e839533fad6c1abd54b052b9a87..21020fa667f91bad74de45e0d3b65a61c287877d
@@@ -565,24 -569,14 +574,16 @@@ def extract_uid_gid()
  
  def deploy_daemon(fsid, daemon_type, daemon_id, c, uid, gid,
                    config, keyring):
 -    # type: (str, str, Union[int, str], CephContainer, int, int, str, str) -> None
 -    if daemon_type == 'mon' and not os.path.exists(get_data_dir(fsid, 'mon',
 -                                                                daemon_id)):
 +    # type: (str, str, Union[int, str], CephContainer, int, int, Optional[str], Optional[str]) -> None
 +    if daemon_type == 'mon' and not os.path.exists(
 +            get_data_dir(fsid, 'mon', daemon_id)):
 +        assert config
 +        assert keyring
          # tmp keyring file
-         tmp_keyring = tempfile.NamedTemporaryFile(mode='w')
-         os.fchmod(tmp_keyring.fileno(), 0o600)
-         os.fchown(tmp_keyring.fileno(), uid, gid)
-         tmp_keyring.write(keyring)
-         tmp_keyring.flush()
+         tmp_keyring = write_tmp(keyring, uid, gid)
  
          # tmp config file
-         tmp_config = tempfile.NamedTemporaryFile(mode='w')
-         os.fchmod(tmp_config.fileno(), 0o600)
-         os.fchown(tmp_config.fileno(), uid, gid)
-         tmp_config.write(config)
-         tmp_config.flush()
+         tmp_config = write_tmp(config, uid, gid)
  
          # --mkfs
          create_daemon_dirs(fsid, daemon_type, daemon_id, uid, gid)
@@@ -1114,22 -1056,13 +1110,14 @@@ def command_bootstrap()
          f.write(config)
  
      mon_c = get_container(fsid, 'mon', mon_id)
 -    deploy_daemon_units(fsid, uid, gid, 'mon', mon_id, mon_c)
 +    deploy_daemon(fsid, 'mon', mon_id, mon_c, uid, gid,
 +                  config=None, keyring=None)
  
      # client.admin key + config to issue various CLI commands
-     tmp_admin_keyring = tempfile.NamedTemporaryFile(mode='w')
-     os.fchmod(tmp_admin_keyring.fileno(), 0o600)
-     os.fchown(tmp_admin_keyring.fileno(), uid, gid)
-     tmp_admin_keyring.write('[client.admin]\n'
-                       '\tkey = ' + admin_key + '\n')
-     tmp_admin_keyring.flush()
-     tmp_config = tempfile.NamedTemporaryFile(mode='w')
-     os.fchmod(tmp_config.fileno(), 0o600)
-     os.fchown(tmp_config.fileno(), uid, gid)
-     tmp_config.write(config)
-     tmp_config.flush()
+     tmp_admin_keyring = write_tmp('[client.admin]\n'
+                                   '\tkey = ' + admin_key + '\n',
+                                        uid, gid)
+     tmp_config = write_tmp(config, uid, gid)
  
      # a CLI helper to reduce our typing
      def cli(cmd, extra_mounts={}):