#NEWLINE# def _test_save( self , cell_type = None , update_device_name = False ) : #NEWLINE# #INDENT# if cell_type : #NEWLINE# #INDENT# self . flags ( enable = True , cell_type = cell_type , group = 'cells' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . flags ( enable = False , group = 'cells' ) #NEWLINE# #UNINDENT# create = False #NEWLINE# fake_bdm = self . fake_bdm ( ) #NEWLINE# with test . nested ( mock . patch . object ( db , 'block_device_mapping_update' , return_value = fake_bdm ) , mock . patch . object ( cells_rpcapi . CellsAPI , 'bdm_update_or_create_at_top' ) ) as ( bdm_update_mock , cells_update_mock ) : #NEWLINE# #INDENT# bdm_object = objects . BlockDeviceMapping ( context = self . context ) #NEWLINE# bdm_object . id = 123 #NEWLINE# bdm_object . volume_id = 'fake_volume_id' #NEWLINE# if update_device_name : #NEWLINE# #INDENT# bdm_object . device_name = '/dev/vda' #NEWLINE# create = None #NEWLINE# #UNINDENT# bdm_object . save ( ) #NEWLINE# if update_device_name : #NEWLINE# #INDENT# bdm_update_mock . assert_called_once_with ( self . context , 123 , { #NEWLINE# #INDENT# 'volume_id' : 'fake_volume_id' , #NEWLINE# 'device_name' : '/dev/vda' , #NEWLINE# #UNINDENT# } , legacy = False ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# bdm_update_mock . assert_called_once_with ( self . context , 123 , { #NEWLINE# #INDENT# 'volume_id' : 'fake_volume_id' , #NEWLINE# #UNINDENT# } , legacy = False ) #NEWLINE# #UNINDENT# if ( cell_type != 'compute' ) : #NEWLINE# #INDENT# self . assertFalse ( cells_update_mock . called ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . assertEqual ( 1 , cells_update_mock . call_count ) #NEWLINE# self . assertTrue ( ( len ( cells_update_mock . call_args [ 0 ] ) > 1 ) ) #NEWLINE# self . assertIsInstance ( cells_update_mock . call_args [ 0 ] [ 1 ] , block_device_obj . BlockDeviceMapping ) #NEWLINE# self . assertEqual ( { #NEWLINE# #INDENT# 'create' : create , #NEWLINE# #UNINDENT# } , cells_update_mock . call_args [ 1 ] )