]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
task/ssh_keys: use remote.write_file instead misc.create_file 1557/head
authorKyr Shatskyy <kyrylo.shatskyy@suse.com>
Sat, 5 Sep 2020 09:23:56 +0000 (11:23 +0200)
committerKyr Shatskyy <kyrylo.shatskyy@suse.com>
Sun, 6 Sep 2020 17:58:19 +0000 (19:58 +0200)
Because misc.create_file with data arguments creates file,
changes permissions, and later appends the data using
misc.append_lines_to_file, this logic makes the algorythm
above to fail if the file created without write permissions.

    2020-09-05T10:00:32.003 INFO:teuthology.task.ssh_keys:pushing keys to smithi086.front.sepia.ceph.com for ubuntu
    2020-09-05T10:00:32.003 INFO:teuthology.orchestra.run.smithi086:> rm -f -- /home/ubuntu/.ssh/id_rsa
    2020-09-05T10:00:32.046 INFO:teuthology.orchestra.run.smithi086:> touch /home/ubuntu/.ssh/id_rsa && chmod 500 -- /home/ubuntu/.ssh/id_rsa
    2020-09-05T10:00:32.095 INFO:teuthology.orchestra.run.smithi086:> set -ex
    2020-09-05T10:00:32.096 INFO:teuthology.orchestra.run.smithi086:> dd of=/home/ubuntu/.ssh/id_rsa conv=notrunc oflag=append
    2020-09-05T10:00:32.140 INFO:teuthology.orchestra.run.smithi086.stderr:+ dd of=/home/ubuntu/.ssh/id_rsa conv=notrunc oflag=append
    2020-09-05T10:00:32.142 INFO:teuthology.orchestra.run.smithi086.stderr:dd: failed to open '/home/ubuntu/.ssh/id_rsa': Permission denied
    2020-09-05T10:00:32.142 DEBUG:teuthology.orchestra.run:got remote process result: 1

However we have more advanced remote.write_file function now,
which does not have such issues and moreover creates file
with the data provided in a single hop without trying to
download the file locally.

Related-to: 243ff3bbf218102b24ed992e3931bf8c76cdaadd
Related-to: 45aba9cf8d72fd30ca607200694c638cfd240fd8
Signed-off-by: Kyr Shatskyy <kyrylo.shatskyy@suse.com>
teuthology/task/ssh_keys.py

index a38ed9406438c32e3cfbe07eb6a2cfdabfba1eeb..f7e0dba32c57d71497cd5def7d9ebe9de0a15dba 100644 (file)
@@ -154,13 +154,13 @@ def push_keys_to_host(ctx, config, public_key, private_key):
             priv_key_data = '{priv_key}'.format(priv_key=private_key)
             misc.delete_file(remote, priv_key_file, force=True)
             # Hadoop requires that .ssh/id_rsa have permissions of '500'
-            misc.create_file(remote, priv_key_file, priv_key_data, str(500))
+            remote.write_file(priv_key_file, priv_key_data, mode='0500')
 
             # then a private key
             pub_key_file = '/home/{user}/.ssh/id_rsa.pub'.format(user=username)
             pub_key_data = 'ssh-rsa {pub_key} {user_host}'.format(pub_key=public_key, user_host=str(remote))
             misc.delete_file(remote, pub_key_file, force=True)
-            misc.create_file(remote, pub_key_file, pub_key_data)
+            remote.write_file(pub_key_file, pub_key_data)
 
             # add appropriate entries to the authorized_keys file for this host
             auth_keys_file = '/home/{user}/.ssh/authorized_keys'.format(