@@ -50,39 +50,7 @@ def get_fake_obj_numa_topology(context):
5050 return fake_obj_numa_topology_cpy
5151
5252
53- class _TestInstanceNUMATopology (object ):
54- @mock .patch ('nova.db.api.instance_extra_update_by_uuid' )
55- def test_create (self , mock_update ):
56- topo_obj = get_fake_obj_numa_topology (self .context )
57- topo_obj .instance_uuid = fake_db_topology ['instance_uuid' ]
58- topo_obj .create ()
59- self .assertEqual (1 , len (mock_update .call_args_list ))
60-
61- def _test_get_by_instance_uuid (self ):
62- numa_topology = objects .InstanceNUMATopology .get_by_instance_uuid (
63- self .context , fake_db_topology ['instance_uuid' ])
64- self .assertEqual (fake_db_topology ['instance_uuid' ],
65- numa_topology .instance_uuid )
66- for obj_cell , topo_cell in zip (
67- numa_topology .cells , fake_obj_numa_topology ['cells' ]):
68- self .assertIsInstance (obj_cell , objects .InstanceNUMACell )
69- self .assertEqual (topo_cell .id , obj_cell .id )
70- self .assertEqual (topo_cell .cpuset , obj_cell .cpuset )
71- self .assertEqual (topo_cell .memory , obj_cell .memory )
72- self .assertEqual (topo_cell .pagesize , obj_cell .pagesize )
73-
74- @mock .patch ('nova.db.api.instance_extra_get_by_instance_uuid' )
75- def test_get_by_instance_uuid (self , mock_get ):
76- mock_get .return_value = fake_db_topology
77- self ._test_get_by_instance_uuid ()
78-
79- @mock .patch ('nova.db.api.instance_extra_get_by_instance_uuid' )
80- def test_get_by_instance_uuid_missing (self , mock_get ):
81- mock_get .return_value = None
82- self .assertRaises (
83- exception .NumaTopologyNotFound ,
84- objects .InstanceNUMATopology .get_by_instance_uuid ,
85- self .context , 'fake_uuid' )
53+ class _TestInstanceNUMACell (object ):
8654
8755 def test_siblings (self ):
8856 inst_cell = objects .InstanceNUMACell (
@@ -126,7 +94,7 @@ def test_pin_vcpus(self):
12694 inst_cell .pin_vcpus ((0 , 14 ), (1 , 15 ), (2 , 16 ), (3 , 17 ))
12795 self .assertEqual ({0 : 14 , 1 : 15 , 2 : 16 , 3 : 17 }, inst_cell .cpu_pinning )
12896
129- def test_cpu_pinning_requested_cell (self ):
97+ def test_cpu_pinning_requested (self ):
13098 inst_cell = objects .InstanceNUMACell (cpuset = set ([0 , 1 , 2 , 3 ]),
13199 cpu_pinning = None )
132100 self .assertFalse (inst_cell .cpu_pinning_requested )
@@ -135,24 +103,14 @@ def test_cpu_pinning_requested_cell(self):
135103
136104 def test_cpu_pinning (self ):
137105 topo_obj = get_fake_obj_numa_topology (self .context )
138-
139106 self .assertEqual (set (), topo_obj .cpu_pinning )
140107
141108 topo_obj .cells [0 ].pin_vcpus ((1 , 10 ), (2 , 11 ))
142-
143109 self .assertEqual (set ([10 , 11 ]), topo_obj .cpu_pinning )
144110
145111 topo_obj .cells [1 ].pin_vcpus ((3 , 0 ), (4 , 1 ))
146-
147112 self .assertEqual (set ([0 , 1 , 10 , 11 ]), topo_obj .cpu_pinning )
148113
149- def test_cpu_pinning_requested (self ):
150- fake_topo_obj = copy .deepcopy (fake_obj_numa_topology )
151- self .assertFalse (fake_topo_obj .cpu_pinning_requested )
152- for cell in fake_topo_obj .cells :
153- cell .cpu_policy = fields .CPUAllocationPolicy .DEDICATED
154- self .assertTrue (fake_topo_obj .cpu_pinning_requested )
155-
156114 def test_clear_host_pinning (self ):
157115 topo_obj = get_fake_obj_numa_topology (self .context )
158116 topo_obj .cells [0 ].pin_vcpus ((1 , 10 ), (2 , 11 ))
@@ -174,22 +132,76 @@ def test_emulator_threads_policy(self):
174132 fields .CPUEmulatorThreadsPolicy .ISOLATE )
175133 self .assertTrue (topo_obj .emulator_threads_isolated )
176134
177- def test_obj_make_compatible_numa_pre_1_3 (self ):
178- topo_obj = objects .InstanceNUMATopology (
179- emulator_threads_policy = (
180- fields .CPUEmulatorThreadsPolicy .ISOLATE ))
181- versions = ovo_base .obj_tree_get_versions ('InstanceNUMATopology' )
182- primitive = topo_obj .obj_to_primitive (target_version = '1.2' ,
183- version_manifest = versions )
184- self .assertNotIn (
185- 'emulator_threads_policy' , primitive ['nova_object.data' ])
135+ def test_obj_make_compatible_numa_cell_pre_1_4 (self ):
136+ topo_obj = objects .InstanceNUMACell (
137+ cpuset_reserved = set ([1 , 2 ]))
138+ versions = ovo_base .obj_tree_get_versions ('InstanceNUMACell' )
139+ data = lambda x : x ['nova_object.data' ]
140+ primitive = data (topo_obj .obj_to_primitive (target_version = '1.4' ,
141+ version_manifest = versions ))
142+ self .assertIn ('cpuset_reserved' , primitive )
143+ primitive = data (topo_obj .obj_to_primitive (target_version = '1.3' ,
144+ version_manifest = versions ))
145+ self .assertNotIn ('cpuset_reserved' , primitive )
146+
147+
148+ class TestInstanceNUMACell (
149+ test_objects ._LocalTest , _TestInstanceNUMACell ,
150+ ):
151+ pass
186152
187- topo_obj = objects .InstanceNUMATopology .obj_from_primitive (primitive )
188- self .assertFalse (topo_obj .emulator_threads_isolated )
153+
154+ class TestInstanceNUMACellRemote (
155+ test_objects ._RemoteTest , _TestInstanceNUMACell ,
156+ ):
157+ pass
158+
159+
160+ class _TestInstanceNUMATopology (object ):
161+
162+ @mock .patch ('nova.db.api.instance_extra_update_by_uuid' )
163+ def test_create (self , mock_update ):
164+ topo_obj = get_fake_obj_numa_topology (self .context )
165+ topo_obj .instance_uuid = fake_db_topology ['instance_uuid' ]
166+ topo_obj .create ()
167+ self .assertEqual (1 , len (mock_update .call_args_list ))
168+
169+ def _test_get_by_instance_uuid (self ):
170+ numa_topology = objects .InstanceNUMATopology .get_by_instance_uuid (
171+ self .context , fake_db_topology ['instance_uuid' ])
172+ self .assertEqual (fake_db_topology ['instance_uuid' ],
173+ numa_topology .instance_uuid )
174+ for obj_cell , topo_cell in zip (
175+ numa_topology .cells , fake_obj_numa_topology ['cells' ]):
176+ self .assertIsInstance (obj_cell , objects .InstanceNUMACell )
177+ self .assertEqual (topo_cell .id , obj_cell .id )
178+ self .assertEqual (topo_cell .cpuset , obj_cell .cpuset )
179+ self .assertEqual (topo_cell .memory , obj_cell .memory )
180+ self .assertEqual (topo_cell .pagesize , obj_cell .pagesize )
181+
182+ @mock .patch ('nova.db.api.instance_extra_get_by_instance_uuid' )
183+ def test_get_by_instance_uuid (self , mock_get ):
184+ mock_get .return_value = fake_db_topology
185+ self ._test_get_by_instance_uuid ()
186+
187+ @mock .patch ('nova.db.api.instance_extra_get_by_instance_uuid' )
188+ def test_get_by_instance_uuid_missing (self , mock_get ):
189+ mock_get .return_value = None
190+ self .assertRaises (
191+ exception .NumaTopologyNotFound ,
192+ objects .InstanceNUMATopology .get_by_instance_uuid ,
193+ self .context , 'fake_uuid' )
194+
195+ def test_cpu_pinning_requested (self ):
196+ fake_topo_obj = copy .deepcopy (fake_obj_numa_topology )
197+ self .assertFalse (fake_topo_obj .cpu_pinning_requested )
198+ for cell in fake_topo_obj .cells :
199+ cell .cpu_policy = fields .CPUAllocationPolicy .DEDICATED
200+ self .assertTrue (fake_topo_obj .cpu_pinning_requested )
189201
190202 def test_cpuset_reserved (self ):
191203 topology = objects .InstanceNUMATopology (
192- instance_uuid = fake_instance_uuid ,
204+ instance_uuid = fake_instance_uuid ,
193205 cells = [
194206 objects .InstanceNUMACell (
195207 id = 0 , cpuset = set ([1 , 2 ]), memory = 512 , pagesize = 2048 ,
@@ -201,24 +213,27 @@ def test_cpuset_reserved(self):
201213 self .assertEqual (set ([3 , 7 ]), topology .cells [0 ].cpuset_reserved )
202214 self .assertEqual (set ([9 , 12 ]), topology .cells [1 ].cpuset_reserved )
203215
204- def test_obj_make_compatible_numa_cell_pre_1_4 (self ):
205- topo_obj = objects .InstanceNUMACell (
206- cpuset_reserved = set ([1 , 2 ]))
207- versions = ovo_base .obj_tree_get_versions ('InstanceNUMACell' )
208- data = lambda x : x ['nova_object.data' ]
209- primitive = data (topo_obj .obj_to_primitive (target_version = '1.4' ,
210- version_manifest = versions ))
211- self .assertIn ('cpuset_reserved' , primitive )
212- primitive = data (topo_obj .obj_to_primitive (target_version = '1.3' ,
213- version_manifest = versions ))
214- self .assertNotIn ('cpuset_reserved' , primitive )
216+ def test_obj_make_compatible_numa_pre_1_3 (self ):
217+ topo_obj = objects .InstanceNUMATopology (
218+ emulator_threads_policy = (
219+ fields .CPUEmulatorThreadsPolicy .ISOLATE ))
220+ versions = ovo_base .obj_tree_get_versions ('InstanceNUMATopology' )
221+ primitive = topo_obj .obj_to_primitive (target_version = '1.2' ,
222+ version_manifest = versions )
223+ self .assertNotIn (
224+ 'emulator_threads_policy' , primitive ['nova_object.data' ])
225+
226+ topo_obj = objects .InstanceNUMATopology .obj_from_primitive (primitive )
227+ self .assertFalse (topo_obj .emulator_threads_isolated )
215228
216229
217- class TestInstanceNUMATopology (test_objects ._LocalTest ,
218- _TestInstanceNUMATopology ):
230+ class TestInstanceNUMATopology (
231+ test_objects ._LocalTest , _TestInstanceNUMATopology ,
232+ ):
219233 pass
220234
221235
222- class TestInstanceNUMATopologyRemote (test_objects ._RemoteTest ,
223- _TestInstanceNUMATopology ):
236+ class TestInstanceNUMATopologyRemote (
237+ test_objects ._RemoteTest , _TestInstanceNUMATopology ,
238+ ):
224239 pass
0 commit comments