#NEWLINE# @ contextlib . contextmanager #NEWLINE# def _iscsi_setup_and_handle_errors( address , port , iqn , lun ) : #NEWLINE# #INDENT# 'Function that yields an iSCSI target device to work on.\n\n    :param address: The iSCSI IP address.\n    :param port: The iSCSI port number.\n    :param iqn: The iSCSI qualified name.\n    :param lun: The iSCSI logical unit number.\n    ' #NEWLINE# dev = get_dev ( address , port , iqn , lun ) #NEWLINE# discovery ( address , port ) #NEWLINE# login_iscsi ( address , port , iqn ) #NEWLINE# if ( not disk_utils . is_block_device ( dev ) ) : #NEWLINE# #INDENT# raise exception . InstanceDeployFailure ( ( _ ( "Parent device '%s' not found" ) % dev ) ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# ( yield dev ) #NEWLINE# #UNINDENT# except processutils . ProcessExecutionError as err : #NEWLINE# #INDENT# with excutils . save_and_reraise_exception ( ) : #NEWLINE# #INDENT# LOG . error ( _LE ( 'Deploy to address %s failed.' ) , address ) #NEWLINE# LOG . error ( _LE ( 'Command: %s' ) , err . cmd ) #NEWLINE# LOG . error ( _LE ( 'StdOut: %r' ) , dev . stdout ) #NEWLINE# LOG . error ( _LE ( 'StdErr: %r' ) , err . stderr ) #NEWLINE# #UNINDENT# #UNINDENT# except exception . InstanceDeployFailure as e : #NEWLINE# #INDENT# with excutils . save_and_reraise_exception ( ) : #NEWLINE# #INDENT# LOG . error ( _LE ( 'Deploy to address %s failed.' ) , address ) #NEWLINE# LOG . error ( e ) #NEWLINE# #UNINDENT# #UNINDENT# finally : #NEWLINE# #INDENT# logout_iscsi ( address , port , iqn ) #NEWLINE# delete_iscsi ( address , port , iqn )