<s> from nova import test <EOL> from nova_solverscheduler . scheduler . solvers . constraints import vcpu_constraint <EOL> from nova_solverscheduler . tests . scheduler import solver_scheduler_fakes as fakes <EOL> class TestVcpuConstraint ( test . NoDBTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestVcpuConstraint , self ) . setUp ( ) <EOL> self . constraint_cls = vcpu_constraint . VcpuConstraint <EOL> self . _generate_fake_constraint_input ( ) <EOL> def _generate_fake_constraint_input ( self ) : <EOL> self . fake_filter_properties = { <EOL> '<STR_LIT>' : { '<STR_LIT>' : <NUM_LIT:2> } , <EOL> '<STR_LIT>' : [ '<STR_LIT>' % x for x in range ( <NUM_LIT:2> ) ] , <EOL> '<STR_LIT>' : <NUM_LIT:2> } <EOL> host1 = fakes . FakeSolverSchedulerHostState ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : <NUM_LIT:4> , '<STR_LIT>' : <NUM_LIT:4> } ) <EOL> host2 = fakes . FakeSolverSchedulerHostState ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : <NUM_LIT:8> , '<STR_LIT>' : <NUM_LIT:2> } ) <EOL> host3 = fakes . FakeSolverSchedulerHostState ( '<STR_LIT>' , '<STR_LIT>' , { } ) <EOL> self . fake_hosts = [ host1 , host2 , host3 ] <EOL> def test_get_constraint_matrix ( self ) : <EOL> self . flags ( cpu_allocation_ratio = <NUM_LIT:1.0> ) <EOL> expected_cons_mat = [ <EOL> [ False , False ] , <EOL> [ True , True ] , <EOL> [ True , True ] ] <EOL> cons_mat = self . constraint_cls ( ) . get_constraint_matrix ( <EOL> self . fake_hosts , self . fake_filter_properties ) <EOL> self . assertEqual ( expected_cons_mat , cons_mat ) <EOL> def test_get_constraint_matrix_oversubscribe ( self ) : <EOL> self . flags ( cpu_allocation_ratio = <NUM_LIT> ) <EOL> expected_cons_mat = [ <EOL> [ True , True ] , <EOL> [ True , True ] , <EOL> [ True , True ] ] <EOL> cons_mat = self . constraint_cls ( ) . get_constraint_matrix ( <EOL> self . fake_hosts , self . fake_filter_properties ) <EOL> self . assertEqual ( expected_cons_mat , cons_mat ) <EOL> self . assertEqual ( <NUM_LIT:4> * <NUM_LIT> , self . fake_hosts [ <NUM_LIT:0> ] . limits [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( <NUM_LIT:8> * <NUM_LIT> , self . fake_hosts [ <NUM_LIT:1> ] . limits [ '<STR_LIT>' ] ) </s>
