plugin installation process was managed about possible exceptions

This commit is contained in:
Volkan Şahin 2016-05-17 12:31:38 +03:00
parent 7d22232c1c
commit 7d829bef7d

View file

@ -10,6 +10,7 @@ import stat
import subprocess import subprocess
import uuid import uuid
import urllib.request import urllib.request
import errno
from base.Scope import Scope from base.Scope import Scope
from base.messaging.ssh_file_transfer import FileTransfer from base.messaging.ssh_file_transfer import FileTransfer
@ -57,16 +58,21 @@ class ExecutionManager(object):
temp_file = self.config_manager.get('CONNECTION', 'receivefileparam') + str(uuid.uuid4()) + '.deb' temp_file = self.config_manager.get('CONNECTION', 'receivefileparam') + str(uuid.uuid4()) + '.deb'
if str(plugin['protocol']).lower() == 'ssh': if str(plugin['protocol']).lower() == 'ssh':
self.logger.debug('[ExecutionManager] Distribution protocol is {}'.format(str(plugin['protocol']).lower())) try:
host = parameter_map['host'] self.logger.debug('[ExecutionManager] Distribution protocol is {}'.format(str(plugin['protocol']).lower()))
username = parameter_map['username'] host = parameter_map['host']
password = parameter_map['password'] username = parameter_map['username']
port = parameter_map['port'] password = parameter_map['password']
path = parameter_map['path'] port = parameter_map['port']
path = parameter_map['path']
transfer = FileTransfer(host, port, username, password) transfer = FileTransfer(host, port, username, password)
transfer.connect() transfer.connect()
transfer.get_file(temp_file, path) transfer.get_file(temp_file, path)
except Exception as e:
self.logger.error('[ExecutionManager] Plugin package could not fetch. Error Message: {}.'.format(str(e)))
self.logger.error('[ExecutionManager] Plugin Installation is cancelling')
return
elif plugin['protocol'].lower() == 'http': elif plugin['protocol'].lower() == 'http':
self.logger.debug('[ExecutionManager] Distribution protocol is {}.'.format(str(plugin['protocol']).lower())) self.logger.debug('[ExecutionManager] Distribution protocol is {}.'.format(str(plugin['protocol']).lower()))
@ -75,10 +81,19 @@ class ExecutionManager(object):
self.logger.debug('[ExecutionManager] Unsupported protocol is {}.'.format(str(plugin['protocol']).lower())) self.logger.debug('[ExecutionManager] Unsupported protocol is {}.'.format(str(plugin['protocol']).lower()))
self.logger.debug('[ExecutionManager] Plugin package downloaded via {}.'.format(str(plugin['protocol']).lower())) self.logger.debug('[ExecutionManager] Plugin package downloaded via {}.'.format(str(plugin['protocol']).lower()))
self.install_deb(temp_file) try:
self.logger.debug('[ExecutionManager] Plugin installed.') self.install_deb(temp_file)
self.remove_file(temp_file) self.logger.debug('[ExecutionManager] Plugin installed.')
self.logger.debug('[ExecutionManager] Temp files were removed.') except Exception as e:
self.logger.error('[ExecutionManager] Could not install plugin. Error Message: {}'.format(str(e)))
return
try:
self.remove_file(temp_file)
self.logger.debug('[ExecutionManager] Temp files were removed.')
except Exception as e:
self.logger.error('[ExecutionManager] Could not remove temp file. Error Message: {}'.format(str(e)))
self.plugin_manager.loadSinglePlugin(plugin_name) self.plugin_manager.loadSinglePlugin(plugin_name)
except Exception as e: except Exception as e: