#NEWLINE# @ mock . patch ( 'nova.utils.execute' ) #NEWLINE# def test_attach_volume_fail( self , mock_execute ) : #NEWLINE# #INDENT# self . encryptor . _get_key = mock . MagicMock ( ) #NEWLINE# self . encryptor . _get_key . return_value = test_cryptsetup . fake__get_key ( None ) #NEWLINE# mock_execute . side_effect = [ processutils . ProcessExecutionError ( exit_code = 1 ) , mock . DEFAULT ] #NEWLINE# self . assertRaises ( processutils . ProcessExecutionError , self . encryptor . attach_volume , None ) #NEWLINE# mock_execute . assert_has_calls ( [ mock . call ( 'cryptsetup' , 'luksOpen' , '--key-file=-' , mock_execute . dev_path , self . dev_name , process_input = ( '0' * 32 ) , run_as_root = True , check_exit_code = True ) , mock . call ( 'cryptsetup' , 'isLuks' , '--verbose' , self . dev_path , run_as_root = True , check_exit_code = True ) ] , any_order = False ) #NEWLINE# self . assertEqual ( 2 , mock_execute . call_count )