From f6270a7fb0fde8ca98fb2dd75925d9a8345891ec Mon Sep 17 00:00:00 2001 From: Sandon Van Ness Date: Thu, 20 Jun 2013 18:36:58 -0700 Subject: [PATCH] Wipe out existing id_rsa.pub and id_rsa before pushing ssh keys A very simple change. Just touch a file first (to create it if it doesn't yet exist so the delete doesn't error out) and then delete it before pushing the keys to the file. This should avoid the id_rsa.pub and id_rsa files from getting messed up due to previous runs which were interrupted or failed (or if those files exist for some reason). This appears to be what was causing breaking in the ceph-deploy nightlies. Signed-off-by: Sandon Van Ness --- teuthology/misc.py | 6 ++++-- teuthology/task/ssh_keys.py | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/teuthology/misc.py b/teuthology/misc.py index 35e74c0223033..3d9e2a177fe5b 100644 --- a/teuthology/misc.py +++ b/teuthology/misc.py @@ -361,12 +361,14 @@ def move_file(remote, from_path, to_path, sudo=False): stdout=StringIO(), ) -def delete_file(remote, path, sudo=False): +def delete_file(remote, path, sudo=False, force=False): args = [] if sudo: args.append('sudo') + args.extend(['rm']) + if force: + args.extend(['-f']) args.extend([ - 'rm', '--', path, ]) diff --git a/teuthology/task/ssh_keys.py b/teuthology/task/ssh_keys.py index 8020f101fe554..6cadd12fb38da 100644 --- a/teuthology/task/ssh_keys.py +++ b/teuthology/task/ssh_keys.py @@ -108,12 +108,14 @@ def push_keys_to_host(ctx, config, public_key, private_key): # adding a private key priv_key_file = '/home/{user}/.ssh/id_rsa'.format(user=username) 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)) # 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) # adding appropriate entries to the authorized_keys2 file for this host -- 2.39.5