@@ -258,6 +258,46 @@ def test_create_server_with_legacy_pinning_policy_old_configuration(self):
258
258
259
259
self ._run_build_test (flavor_id , expected_usage = expected_usage )
260
260
261
+ def test_create_server_with_isolate_thread_policy_old_configuration (self ):
262
+ """Create a server with the legacy 'hw:cpu_thread_policy=isolate' extra
263
+ spec and configuration.
264
+
265
+ This should pass and result in an instance consuming $flavor.vcpu host
266
+ cores plus the thread sibling(s) of each of these cores. We also be
267
+ consuming VCPUs since we're on legacy configuration here, though that
268
+ would in theory be fixed during a later reshape.
269
+ """
270
+ self .flags (
271
+ cpu_dedicated_set = None , cpu_shared_set = None , group = 'compute' )
272
+ self .flags (vcpu_pin_set = '0-3' )
273
+
274
+ # host has hyperthreads, which means we're going to end up consuming
275
+ # $flavor.vcpu hosts cores plus the thread sibling(s) for each core
276
+ host_info = fakelibvirt .HostInfo (
277
+ cpu_nodes = 1 , cpu_sockets = 1 , cpu_cores = 2 , cpu_threads = 2 ,
278
+ kB_mem = (1024 * 1024 * 16 ), # GB
279
+ )
280
+ fake_connection = self ._get_connection (host_info = host_info )
281
+ self .mock_conn .return_value = fake_connection
282
+
283
+ extra_spec = {
284
+ 'hw:cpu_policy' : 'dedicated' ,
285
+ 'hw:cpu_thread_policy' : 'isolate' ,
286
+ }
287
+ flavor_id = self ._create_flavor (vcpu = 2 , extra_spec = extra_spec )
288
+
289
+ expected_usage = {'DISK_GB' : 20 , 'MEMORY_MB' : 2048 , 'VCPU' : 2 }
290
+ self ._run_build_test (flavor_id , expected_usage = expected_usage )
291
+
292
+ # verify that we have consumed two cores plus the thread sibling of
293
+ # each core, totalling four cores since the HostInfo indicates each
294
+ # core should have two threads
295
+ ctxt = nova_context .get_admin_context ()
296
+ host_numa = objects .NUMATopology .obj_from_db_obj (
297
+ objects .ComputeNode .get_by_nodename (ctxt , 'compute1' ).numa_topology
298
+ )
299
+ self .assertEqual ({0 , 1 , 2 , 3 }, host_numa .cells [0 ].pinned_cpus )
300
+
261
301
def test_create_server_with_legacy_pinning_policy_fails (self ):
262
302
"""Create a pinned instance on a host with no PCPUs.
263
303
@@ -320,6 +360,37 @@ def test_create_server_with_legacy_pinning_policy_quota_fails(self):
320
360
self .api .post_server , post )
321
361
self .assertEqual (403 , ex .response .status_code )
322
362
363
+ def test_create_server_with_isolate_thread_policy_fails (self ):
364
+ """Create a server with the legacy 'hw:cpu_thread_policy=isolate' extra
365
+ spec.
366
+
367
+ This should fail on a host with hyperthreading.
368
+ """
369
+ self .flags (
370
+ cpu_dedicated_set = '0-3' , cpu_shared_set = '4-7' , group = 'compute' )
371
+ self .flags (vcpu_pin_set = None )
372
+
373
+ # host has hyperthreads, which means it should be rejected
374
+ host_info = fakelibvirt .HostInfo (
375
+ cpu_nodes = 2 , cpu_sockets = 1 , cpu_cores = 2 , cpu_threads = 2 ,
376
+ kB_mem = (1024 * 1024 * 16 ), # GB
377
+ )
378
+ fake_connection = self ._get_connection (host_info = host_info )
379
+ self .mock_conn .return_value = fake_connection
380
+
381
+ extra_spec = {
382
+ 'hw:cpu_policy' : 'dedicated' ,
383
+ 'hw:cpu_thread_policy' : 'isolate' ,
384
+ }
385
+ flavor_id = self ._create_flavor (vcpu = 2 , extra_spec = extra_spec )
386
+
387
+ # FIXME(stephenfin): This should go to error status since there should
388
+ # not be a host available
389
+ expected_usage = {
390
+ 'DISK_GB' : 20 , 'MEMORY_MB' : 2048 , 'PCPU' : 0 , 'VCPU' : 2 ,
391
+ }
392
+ self ._run_build_test (flavor_id , expected_usage = expected_usage )
393
+
323
394
def test_create_server_with_pcpu (self ):
324
395
"""Create a server using an explicit 'resources:PCPU' request.
325
396
0 commit comments