#NEWLINE# def test_ls_( self ) : #NEWLINE# #INDENT# '\n        Test for list SCSI devices, with details\n        ' #NEWLINE# lsscsi = { #NEWLINE# #INDENT# 'stdout' : '[0:0:0:0] disk HP LOGICAL VOLUME 6.68 /dev/sda [8:0]' , #NEWLINE# 'stderr' : '' , #NEWLINE# 'retcode' : 0 , #NEWLINE# #UNINDENT# } #NEWLINE# lsscsi_size = { #NEWLINE# #INDENT# 'stdout' : '[0:0:0:0] disk HP LOGICAL VOLUME 6.68 /dev/sda [8:0] 1.20TB' , #NEWLINE# 'stderr' : '' , #NEWLINE# 'retcode' : 0 , #NEWLINE# #UNINDENT# } #NEWLINE# result = { #NEWLINE# #INDENT# '[0:0:0:0]' : { #NEWLINE# #INDENT# 'major' : '8' , #NEWLINE# 'lun' : '0:0:0:0' , #NEWLINE# 'device' : '/dev/sda' , #NEWLINE# 'model' : 'LOGICAL VOLUME 6.68' , #NEWLINE# 'minor' : '0' , #NEWLINE# 'size' : None , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# result_size = copy . deepcopy ( result ) #NEWLINE# result_size [ '[0:0:0:0]' ] [ 'size' ] = '1.20TB' #NEWLINE# mock = MagicMock ( return_value = '/usr/bin/lsscsi' ) #NEWLINE# with patch . object ( salt . utils , 'which' , mock ) : #NEWLINE# #INDENT# cmd_mock = MagicMock ( return_value = lsscsi_size ) #NEWLINE# with patch . dict ( scsi . __salt__ , { #NEWLINE# #INDENT# 'cmd.run_all' : cmd_mock , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# self . assertDictEqual ( scsi . ls_ ( ) , result_size ) #NEWLINE# with patch . dict ( lsscsi_size , { #NEWLINE# #INDENT# 'retcode' : 1 , #NEWLINE# 'stderr' : 'An error occurred' , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# self . assertEqual ( scsi . ls_ ( ) , 'An error occurred' ) #NEWLINE# #UNINDENT# with patch . dict ( lsscsi_size , { #NEWLINE# #INDENT# 'retcode' : 1 , #NEWLINE# 'stderr' : "lsscsi: invalid option -- 's'\nUsage:" , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# self . assertEqual ( scsi . ls_ ( ) , "lsscsi: invalid option -- 's' - try get_size=False" ) #NEWLINE# #UNINDENT# #UNINDENT# cmd_mock = MagicMock ( return_value = lsscsi ) #NEWLINE# with patch . dict ( scsi . __salt__ , { #NEWLINE# #INDENT# 'cmd.run_all' : cmd_mock , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# self . assertDictEqual ( scsi . ls_ ( get_size = False ) , result ) #NEWLINE# #UNINDENT# #UNINDENT# mock = MagicMock ( return_value = None ) #NEWLINE# with patch . object ( salt . utils , 'which' , mock ) : #NEWLINE# #INDENT# self . assertEqual ( scsi . ls_ ( ) , 'scsi.ls not available - lsscsi command not found' )