<s> import mock <EOL> from oslo_serialization import jsonutils <EOL> from nova import objects <EOL> from nova . objects import base as obj_base <EOL> from nova import test <EOL> from nova . tests . unit import fake_instance <EOL> from nova_solverscheduler . scheduler . solvers . constraints import numa_topology_constraint <EOL> from nova_solverscheduler . tests . scheduler import solver_scheduler_fakes as fakes <EOL> NUMA_TOPOLOGY = objects . NUMATopology ( <EOL> cells = [ <EOL> objects . NUMACell ( id = <NUM_LIT:0> , cpuset = set ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) , memory = <NUM_LIT> , <EOL> cpu_usage = <NUM_LIT:0> , memory_usage = <NUM_LIT:0> , mempages = [ ] , <EOL> siblings = [ ] , pinned_cpus = set ( [ ] ) ) , <EOL> objects . NUMACell ( id = <NUM_LIT:1> , cpuset = set ( [ <NUM_LIT:3> , <NUM_LIT:4> ] ) , memory = <NUM_LIT> , <EOL> cpu_usage = <NUM_LIT:0> , memory_usage = <NUM_LIT:0> , mempages = [ ] , <EOL> siblings = [ ] , pinned_cpus = set ( [ ] ) ) <EOL> ] <EOL> ) <EOL> class TestNUMATopologyConstraint ( test . NoDBTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( TestNUMATopologyConstraint , self ) . setUp ( ) <EOL> self . constraint_cls = numa_topology_constraint . NUMATopologyConstraint <EOL> def _gen_fake_hosts ( self ) : <EOL> host1 = fakes . FakeSolverSchedulerHostState ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { <EOL> '<STR_LIT>' : objects . NUMATopology ( <EOL> cells = [ <EOL> objects . NUMACell ( id = <NUM_LIT:0> , cpuset = set ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) , <EOL> memory = <NUM_LIT> , cpu_usage = <NUM_LIT:0> , memory_usage = <NUM_LIT:0> , <EOL> mempages = [ ] , siblings = [ ] , pinned_cpus = set ( [ ] ) ) , <EOL> objects . NUMACell ( id = <NUM_LIT:1> , cpuset = set ( [ <NUM_LIT:3> , <NUM_LIT:4> ] ) , <EOL> memory = <NUM_LIT> , cpu_usage = <NUM_LIT:0> , memory_usage = <NUM_LIT:0> , <EOL> mempages = [ ] , siblings = [ ] , pinned_cpus = set ( [ ] ) ) ] ) , <EOL> '<STR_LIT>' : None <EOL> } ) <EOL> host2 = fakes . FakeSolverSchedulerHostState ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { <EOL> '<STR_LIT>' : objects . NUMATopology ( <EOL> cells = [ <EOL> objects . NUMACell ( id = <NUM_LIT:0> , cpuset = set ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) , <EOL> memory = <NUM_LIT> , cpu_usage = <NUM_LIT:0> , memory_usage = <NUM_LIT:0> , <EOL> mempages = [ ] , siblings = [ ] , pinned_cpus = set ( [ ] ) ) , <EOL> objects . NUMACell ( id = <NUM_LIT:1> , cpuset = set ( [ <NUM_LIT:3> , <NUM_LIT:4> ] ) , <EOL> memory = <NUM_LIT> , cpu_usage = <NUM_LIT:0> , memory_usage = <NUM_LIT:0> , <EOL> mempages = [ ] , siblings = [ ] , pinned_cpus = set ( [ ] ) ) ] ) , <EOL> '<STR_LIT>' : None <EOL> } ) <EOL> host3 = fakes . FakeSolverSchedulerHostState ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { <EOL> '<STR_LIT>' : objects . NUMATopology ( <EOL> cells = [ <EOL> objects . NUMACell ( id = <NUM_LIT:0> , cpuset = set ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) , <EOL> memory = <NUM_LIT> , cpu_usage = <NUM_LIT:0> , memory_usage = <NUM_LIT:0> , <EOL> mempages = [ ] , siblings = [ ] , pinned_cpus = set ( [ ] ) ) , <EOL> objects . NUMACell ( id = <NUM_LIT:1> , cpuset = set ( [ <NUM_LIT:3> ] ) , <EOL> memory = <NUM_LIT> , cpu_usage = <NUM_LIT:0> , memory_usage = <NUM_LIT:0> , <EOL> mempages = [ ] , siblings = [ ] , pinned_cpus = set ( [ ] ) ) ] ) , <EOL> '<STR_LIT>' : None <EOL> } ) <EOL> hosts = [ host1 , host2 , host3 ] <EOL> return hosts <EOL> def test_get_constraint_matrix ( self ) : <EOL> self . flags ( ram_allocation_ratio = <NUM_LIT:1> ) <EOL> self . flags ( cpu_allocation_ratio = <NUM_LIT:2> ) <EOL> instance_topology = objects . InstanceNUMATopology ( cells = [ <EOL> objects . InstanceNUMACell ( id = <NUM_LIT:0> , cpuset = set ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) , memory = <NUM_LIT> ) , <EOL> objects . InstanceNUMACell ( id = <NUM_LIT:1> , cpuset = set ( [ <NUM_LIT:3> , <NUM_LIT:4> ] ) , memory = <NUM_LIT> ) ] <EOL> ) <EOL> instance = fake_instance . fake_instance_obj ( mock . sentinel . ctx , <EOL> root_gb = <NUM_LIT:0> , ephemeral_gb = <NUM_LIT:0> , memory_mb = <NUM_LIT:0> , vcpus = <NUM_LIT:0> , ) <EOL> instance . numa_topology = instance_topology <EOL> filter_properties = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : jsonutils . to_primitive ( <EOL> obj_base . obj_to_primitive ( instance ) ) } , <EOL> '<STR_LIT>' : <NUM_LIT:2> } <EOL> fake_hosts = self . _gen_fake_hosts ( ) <EOL> expected_cons_mat = [ <EOL> [ True , True ] , <EOL> [ True , False ] , <EOL> [ False , False ] ] <EOL> cons_mat = self . constraint_cls ( ) . get_constraint_matrix ( <EOL> fake_hosts , filter_properties ) <EOL> self . assertEqual ( expected_cons_mat , cons_mat ) </s>
