From 5b89188a0049835816bbdd0cfacd883082042772 Mon Sep 17 00:00:00 2001 From: panageo Date: Mon, 6 Mar 2017 15:52:50 +0200 Subject: [PATCH] Fixing issue in catching exceptions --- stress_test/controller.py | 15 +++++++++------ stress_test/nbemu.py | 12 ++++++++++-- stress_test/oftraf.py | 15 +++++++++------ stress_test/sbemu.py | 24 +++++++++++++----------- util/netutil.py | 9 +++++---- 5 files changed, 46 insertions(+), 29 deletions(-) diff --git a/stress_test/controller.py b/stress_test/controller.py index d35f68c2..158c08a1 100755 --- a/stress_test/controller.py +++ b/stress_test/controller.py @@ -511,20 +511,23 @@ def __del__(self): try: logging.info('Run controller stop.') self.stop() - except: - pass + except Exception as e: + logging.info('Fail stopping Controller during cleanup. ' + 'Exception message: {0}'.format(e)) try: logging.info('Run controller cleanup.') self.cleanup() - except: - pass + except Exception as e: + logging.info('Fail cleaning Controller files during cleanup. ' + 'Exception message: {0}'.format(e)) try: logging.info('Close controller node ssh connection.') self._ssh_conn.close() - except: - pass + except Exception as e: + logging.info('Fail closing ssh Controller node connection during ' + 'cleanup. Exception message: {0}'.format(e)) class ODL(Controller): diff --git a/stress_test/nbemu.py b/stress_test/nbemu.py index 44fe791a..c29e1436 100644 --- a/stress_test/nbemu.py +++ b/stress_test/nbemu.py @@ -261,8 +261,16 @@ def run(self): def __del__(self): """ Method called when object is destroyed""" + try: + logging.info('Cleaning NB-Generator.') + self.clean() + except Exception as e: + logging.info('Fail cleaning NB-Generator during ' + 'cleanup. Exception message: {0}'.format(e)) + try: logging.info('Closing NB-Generator ssh connection.') self._ssh_conn.close() - except: - pass + except Exception as e: + logging.info('Fail closing ssh NB-Generator node connection during ' + 'cleanup. Exception message: {0}'.format(e)) diff --git a/stress_test/oftraf.py b/stress_test/oftraf.py index 8797b2de..76cc3995 100644 --- a/stress_test/oftraf.py +++ b/stress_test/oftraf.py @@ -292,17 +292,20 @@ def __del__(self): try: logging.info('Run oftraf stop.') self.stop() - except: - pass + except Exception as e: + logging.info('Fail stopping oftraf during cleanup. ' + 'Exception message: {0}'.format(e)) try: logging.info('Run oftraf cleanup.') self.clean() - except: - pass + except Exception as e: + logging.info('Fail cleaning oftraf files during cleanup. ' + 'Exception message: {0}'.format(e)) try: logging.info('Close oftraf node ssh connection.') self._ssh_conn.close() - except: - pass + except Exception as e: + logging.info('Fail closing ssh oftraf node connection during ' + 'cleanup. Exception message: {0}'.format(e)) diff --git a/stress_test/sbemu.py b/stress_test/sbemu.py index 217262b8..b1c52089 100644 --- a/stress_test/sbemu.py +++ b/stress_test/sbemu.py @@ -201,16 +201,17 @@ def __del__(self): Method called when object is destroyed """ try: - logging.info('Run emulator clean handler.') - self.cleanup() - except: - pass - + logging.info('Run SB-Emulator clean handler.') + self.clean() + except Exception as e: + logging.info('Fail cleaning SB-Emulator during ' + 'cleanup. Exception message: {0}'.format(e)) try: logging.info('Close emulator node ssh connection.') self._ssh_conn.close() - except: - pass + except Exception as e: + logging.info('Fail closing ssh SB-Emulator node connection during ' + 'cleanup. Exception message: {0}'.format(e)) class MTCBench(SBEmu): @@ -628,7 +629,7 @@ def get_flows(self, new_ssh_conn=None): :rtype: str :type new_ssh_conn: paramiko.SFTPClient :raises IOError: if the handler does not exist on the remote host - :raises emulator_exceptions.MultinetGetFlowsError: if handler fails to \ + :raises emulator_exceptions.MultinetGetFlowsError: if handler fails to run successfully """ logging.info('[Multinet] get_flows') @@ -714,7 +715,7 @@ def start_topos(self): Wrapper to the Multinet SB-Emulator start_topos handler :raises IOError: if the handler does not exist on the remote host - :raises emulator_exceptions.MultinetStartToposError: if Multinet start \ + :raises emulator_exceptions.MultinetStartToposError: if Multinet start topology handler fails """ logging.info('[Multinet] start_topos') @@ -873,6 +874,7 @@ def __del__(self): try: logging.info('Run Multinet cleanup.') self.cleanup() - except: - pass + except Exception as e: + logging.info('Fail cleaning Multinet during ' + 'cleanup. Exception message: {0}'.format(e)) super(self.__class__, self).__del__() diff --git a/util/netutil.py b/util/netutil.py index f541525c..d57f6418 100755 --- a/util/netutil.py +++ b/util/netutil.py @@ -43,8 +43,9 @@ def copy_dir_local_to_remote(ip, ssh_port, username, password, try: folder_to_make = os.path.join(remote_path, walker[0]) sftp.mkdir(folder_to_make) - except: - pass + except Exception as e: + logging.error('Fail to create remote directory path. {0}'. + format(e)) for curr_file in walker[2]: local_file = os.path.join(walker[0], curr_file) remote_file = os.path.join(remote_path, walker[0], curr_file) @@ -272,8 +273,8 @@ def ssh_connection_close(sftp, transport_layer): try: sftp.close() transport_layer.close() - except: - pass + except Exception as e: + logging.error('Fail during closing connection. {0}'.format(e)) def ssh_connection_open(ip, ssh_port, username, password):