#NEWLINE# @ mock . patch ( 'nova.objects.InstancePCIRequests.get_by_instance_uuid' , return_value = objects . InstancePCIRequests ( requests = [ ] ) ) #NEWLINE# @ mock . patch ( 'nova.objects.Instance.save' ) #NEWLINE# def test_cpu_stats( self , mock_save , mock_get ) : #NEWLINE# #INDENT# limits = { #NEWLINE# #INDENT# 'disk_gb' : 100 , #NEWLINE# 'memory_mb' : 100 , #NEWLINE# #UNINDENT# } #NEWLINE# self . assertEqual ( 0 , self . tracker . compute_node . vcpus_used ) #NEWLINE# vcpus = 1 #NEWLINE# instance = self . _fake_instance_obj ( vcpus = vcpus ) #NEWLINE# self . tracker . update_usage ( self . context , instance ) #NEWLINE# self . assertEqual ( 0 , self . tracker . compute_node . vcpus_used ) #NEWLINE# with self . tracker . instance_claim ( self . context , instance , limits ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# self . assertEqual ( vcpus , self . tracker . compute_node . vcpus_used ) #NEWLINE# instance [ 'task_state' ] = task_states . SCHEDULING #NEWLINE# self . tracker . update_usage ( self . context , instance ) #NEWLINE# self . assertEqual ( vcpus , self . tracker . compute_node . vcpus_used ) #NEWLINE# add_vcpus = 10 #NEWLINE# vcpus += add_vcpus #NEWLINE# instance = self . _fake_instance_obj ( vcpus = add_vcpus ) #NEWLINE# with self . tracker . instance_claim ( self . context , instance , limits ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# self . assertEqual ( vcpus , self . tracker . compute_node . vcpus_used ) #NEWLINE# instance [ 'vm_state' ] = vm_states . DELETED #NEWLINE# self . tracker . update_usage ( self . context , instance ) #NEWLINE# vcpus -= add_vcpus #NEWLINE# self . assertEqual ( vcpus , self . tracker . compute_node . vcpus_used )