#NEWLINE# def test_ensure_bridge_brings_up_interface( self ) : #NEWLINE# #INDENT# self . flags ( fake_network = False ) #NEWLINE# fake_mac = 'aa:bb:cc:00:11:22' #NEWLINE# fake_ifaces = { #NEWLINE# #INDENT# netifaces . AF_LINK : [ { #NEWLINE# #INDENT# 'addr' : fake_mac , #NEWLINE# #UNINDENT# } ] , #NEWLINE# #UNINDENT# } #NEWLINE# calls = { #NEWLINE# #INDENT# 'device_exists' : [ mock . call ( 'bridge' ) ] , #NEWLINE# '_execute' : [ mock . call ( 'brctl' , 'addif' , 'bridge' , 'eth0' , run_as_root = True , check_exit_code = False ) , mock . call ( 'ip' , 'link' , 'set' , 'bridge' , 'address' , fake_mac , run_as_root = True ) , mock . call ( 'ip' , 'link' , 'set' , 'eth0' , 'up' , run_as_root = True , check_exit_code = False ) , mock . call ( 'ip' , 'route' , 'show' , 'dev' , 'eth0' ) , mock . call ( 'ip' , 'addr' , 'show' , 'dev' , 'eth0' , 'scope' , 'global' ) ] , #NEWLINE# #UNINDENT# } #NEWLINE# with test . nested ( mock . patch . object ( linux_net , 'device_exists' , return_value = True ) , mock . patch . object ( linux_net , '_execute' , return_value = ( '' , '' ) ) , mock . patch . object ( netifaces , 'ifaddresses' ) ) as ( device_exists , _execute , ifaddresses ) : #NEWLINE# #INDENT# ifaddresses . return_value = fake_ifaces #NEWLINE# driver = linux_net . LinuxBridgeInterfaceDriver ( ) #NEWLINE# driver . ensure_bridge ( 'bridge' , 'eth0' ) #NEWLINE# device_exists . assert_has_calls ( calls [ 'device_exists' ] ) #NEWLINE# _execute . assert_has_calls ( calls [ '_execute' ] ) #NEWLINE# ifaddresses . assert_called_once_with ( 'eth0' )