#NEWLINE# @ mock . patch ( 'nova.utils.get_image_from_system_metadata' ) #NEWLINE# def test_unshelve_volume_backed( self , mock_image_meta ) : #NEWLINE# #INDENT# instance = self . _create_fake_instance_obj ( ) #NEWLINE# node = test_compute . NODENAME #NEWLINE# limits = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# filter_properties = { #NEWLINE# #INDENT# 'limits' : limits , #NEWLINE# #UNINDENT# } #NEWLINE# instance . task_state = task_states . UNSHELVING #NEWLINE# instance . save ( ) #NEWLINE# image_meta = { #NEWLINE# #INDENT# 'properties' : { #NEWLINE# #INDENT# 'base_image_ref' : 'fake_id' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# mock_image_meta . return_value = image_meta #NEWLINE# self . mox . StubOutWithMock ( self . compute , '_notify_about_instance_usage' ) #NEWLINE# self . mox . StubOutWithMock ( self . compute , '_prep_block_device' ) #NEWLINE# self . mox . StubOutWithMock ( self . compute . driver , 'spawn' ) #NEWLINE# self . mox . StubOutWithMock ( self . compute , '_get_power_state' ) #NEWLINE# self . mox . StubOutWithMock ( self . rt , 'instance_claim' ) #NEWLINE# self . mox . StubOutWithMock ( self . compute . network_api , 'setup_instance_network_on_host' ) #NEWLINE# tracking = { #NEWLINE# #INDENT# 'last_state' : instance . task_state , #NEWLINE# #UNINDENT# } #NEWLINE# def check_save( expected_task_state = None ) : #NEWLINE# #INDENT# if ( tracking [ 'last_state' ] == task_states . UNSHELVING ) : #NEWLINE# #INDENT# self . assertEqual ( task_states . SPAWNING , instance . task_state ) #NEWLINE# tracking [ 'last_state' ] = instance . task_state #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( tracking [ 'last_state' ] == task_states . SPAWNING ) : #NEWLINE# #INDENT# self . assertEqual ( 123 , instance . power_state ) #NEWLINE# self . assertEqual ( vm_states . ACTIVE , instance . vm_state ) #NEWLINE# self . assertIsNone ( instance . task_state ) #NEWLINE# self . assertIsNone ( instance . key_data ) #NEWLINE# self . assertFalse ( instance . auto_disk_config ) #NEWLINE# self . assertIsNone ( instance . task_state ) #NEWLINE# tracking [ 'last_state' ] = instance . task_state #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . fail ( 'Unexpected save!' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# self . compute . _notify_about_instance_usage ( self . context , instance , 'unshelve.start' ) #NEWLINE# self . compute . _prep_block_device ( self . context , instance , mox . IgnoreArg ( ) , do_check_attach = False ) . AndReturn ( 'fake_bdm' ) #NEWLINE# self . compute . network_api . setup_instance_network_on_host ( self . context , instance , self . compute . host ) #NEWLINE# self . rt . instance_claim ( self . context , instance , limits ) . AndReturn ( claims . Claim ( self . context , instance , self . rt , _fake_resources ( ) ) ) #NEWLINE# self . compute . driver . spawn ( self . context , instance , mox . IsA ( objects . ImageMeta ) , injected_files = [ ] , admin_password = None , network_info = [ ] , block_device_info = 'fake_bdm' ) #NEWLINE# self . compute . _get_power_state ( self . context , instance ) . AndReturn ( 123 ) #NEWLINE# self . compute . _notify_about_instance_usage ( self . context , instance , 'unshelve.end' ) #NEWLINE# self . mox . ReplayAll ( ) #NEWLINE# with mock . patch . object ( instance , 'save' ) as mock_save : #NEWLINE# #INDENT# mock_save . side_effect = check_save #NEWLINE# self . compute . unshelve_instance ( self . context , instance , image = None , filter_properties = filter_properties , node = self )