Add a ssh key file checking

ssh is a storage used for linux destro, and the key file is
usually in '~/.ssh/' folder, default value is needed,
if the file is not generate by manually,
the freezer-agent will broken. Add checking is a
good idea for use. this patch is to:

1. add default ssh keyfile value
2. add ssh keyfile checking

Change-Id: Ic2d3cdd6f9d4c260cbf650f7aa532d5060778693
Closes-Bug: #1750566
This commit is contained in:
caoyuan 2018-02-20 21:07:01 +08:00
parent 98cff5322a
commit 0e45bc6daa
2 changed files with 10 additions and 3 deletions

View File

@ -76,9 +76,10 @@ DEFAULT_PARAMS = {
'restore_abs_path': None, 'log_file': None, 'log_level': "info",
'mode': 'fs', 'action': 'backup', 'shadow': '', 'shadow_path': '',
'windows_volume': '', 'command': None, 'metadata_out': None,
'storage': 'swift', 'ssh_key': '', 'ssh_username': '', 'ssh_host': '',
'ssh_port': DEFAULT_SSH_PORT, 'access_key': '', 'secret_key': '',
'endpoint': '', 'compression': 'gzip', 'overwrite': False,
'storage': 'swift', 'ssh_key': os.path.join(home, '.ssh/id_rsa'),
'ssh_username': '', 'ssh_host': '', 'ssh_port': DEFAULT_SSH_PORT,
'access_key': '', 'secret_key': '', 'endpoint': '',
'compression': 'gzip', 'overwrite': False,
'incremental': None, 'consistency_check': False,
'consistency_checksum': None, 'nova_restore_network': None,
'cindernative_backup_id': None, 'sync': True, 'engine_name': 'tar',

View File

@ -64,6 +64,12 @@ class SshStorage(fslike.FsLikeStorage):
elif not self.ssh_key_path:
raise ValueError('Please provide path to ssh key using '
'--ssh-key argument.')
elif not os.path.exists(self.ssh_key_path):
raise ValueError('The {0} is required, please ensure it '
'exists and ensure backup node can login '
'to {1} as user {2} without password '
.format(self.ssh_key_path, self.remote_ip,
self.remote_username))
return True
def init(self):