@@ -1376,8 +1376,9 @@ def test_host_usage_contiguous(self):
1376
1376
pagesize = 2048 ),
1377
1377
])
1378
1378
1379
- hostusage = hw .numa_usage_from_instances (
1380
- hosttopo , [instance1 , instance2 , instance3 ])
1379
+ hostusage = hw .numa_usage_from_instance_numa (hosttopo , instance1 )
1380
+ hostusage = hw .numa_usage_from_instance_numa (hostusage , instance2 )
1381
+ hostusage = hw .numa_usage_from_instance_numa (hostusage , instance3 )
1381
1382
1382
1383
self .assertEqual (len (hosttopo ), len (hostusage ))
1383
1384
@@ -1446,8 +1447,10 @@ def test_host_usage_contiguous_pages_compute(self):
1446
1447
objects .InstanceNUMACell (id = 0 , cpuset = set ([0 , 1 ]), memory = 16 ,
1447
1448
pagesize = 2048 ),
1448
1449
])
1449
- hostusage = hw .numa_usage_from_instances (
1450
- hosttopo , [instance1 , instance2 , instance3 ])
1450
+
1451
+ hostusage = hw .numa_usage_from_instance_numa (hosttopo , instance1 )
1452
+ hostusage = hw .numa_usage_from_instance_numa (hostusage , instance2 )
1453
+ hostusage = hw .numa_usage_from_instance_numa (hostusage , instance3 )
1451
1454
1452
1455
# instance1, instance2 are consuming 96MiB smallpages which
1453
1456
# means 96*1024/4 = 24576, plus 32 pages already used.
@@ -1494,8 +1497,8 @@ def test_host_usage_sparse(self):
1494
1497
size_kb = 4 , total = 512 , used = 0 )]),
1495
1498
])
1496
1499
1497
- hostusage = hw .numa_usage_from_instances (
1498
- hosttopo , [ instance1 , instance2 ] )
1500
+ hostusage = hw .numa_usage_from_instance_numa ( hosttopo , instance1 )
1501
+ hostusage = hw . numa_usage_from_instance_numa ( hostusage , instance2 )
1499
1502
1500
1503
self .assertEqual (len (hosttopo ), len (hostusage ))
1501
1504
@@ -1553,8 +1556,8 @@ def test_host_usage_culmulative_with_free(self):
1553
1556
objects .InstanceNUMACell (id = 1 , cpuset = set ([3 ]), memory = 256 ),
1554
1557
objects .InstanceNUMACell (id = 2 , cpuset = set ([4 ]), memory = 256 )])
1555
1558
1556
- hostusage = hw .numa_usage_from_instances (
1557
- hosttopo , [ instance1 ])
1559
+ hostusage = hw .numa_usage_from_instance_numa ( hosttopo , instance1 )
1560
+
1558
1561
self .assertIsInstance (hostusage .cells [0 ], objects .NUMACell )
1559
1562
self .assertEqual (hostusage .cells [0 ].cpu_usage , 5 )
1560
1563
self .assertEqual (hostusage .cells [0 ].memory_usage , 1024 )
@@ -1568,8 +1571,9 @@ def test_host_usage_culmulative_with_free(self):
1568
1571
self .assertEqual (hostusage .cells [2 ].memory_usage , 256 )
1569
1572
1570
1573
# Test freeing of resources
1571
- hostusage = hw .numa_usage_from_instances (
1572
- hostusage , [instance1 ], free = True )
1574
+ hostusage = hw .numa_usage_from_instance_numa (hostusage , instance1 ,
1575
+ free = True )
1576
+
1573
1577
self .assertEqual (hostusage .cells [0 ].cpu_usage , 2 )
1574
1578
self .assertEqual (hostusage .cells [0 ].memory_usage , 512 )
1575
1579
@@ -1627,8 +1631,8 @@ def test_reserved_hugepgaes_success(self):
1627
1631
{'node' : 0 , 'size' : 2048 , 'count' : 128 },
1628
1632
{'node' : 1 , 'size' : 1048576 , 'count' : 1 }])
1629
1633
hosttopo , instance1 = self ._topo_usage_reserved_page_size ()
1630
- hostusage = hw . numa_usage_from_instances (
1631
- hosttopo , [ instance1 ] )
1634
+
1635
+ hostusage = hw . numa_usage_from_instance_numa ( hosttopo , instance1 )
1632
1636
1633
1637
self .assertEqual (hostusage .cells [0 ].mempages [0 ].size_kb , 2048 )
1634
1638
self .assertEqual (hostusage .cells [0 ].mempages [0 ].total , 512 )
@@ -1674,60 +1678,15 @@ def test_topo_usage_none(self):
1674
1678
objects .InstanceNUMACell (id = 2 , cpuset = set ([2 ]), memory = 256 ),
1675
1679
])
1676
1680
1677
- hostusage = hw .numa_usage_from_instances (
1678
- None , [instance1 ])
1681
+ hostusage = hw .numa_usage_from_instance_numa (None , instance1 )
1679
1682
self .assertIsNone (hostusage )
1680
1683
1681
- hostusage = hw .numa_usage_from_instances (
1682
- hosttopo , [])
1683
- self .assertEqual (hostusage .cells [0 ].cpu_usage , 0 )
1684
- self .assertEqual (hostusage .cells [0 ].memory_usage , 0 )
1685
- self .assertEqual (hostusage .cells [1 ].cpu_usage , 0 )
1686
- self .assertEqual (hostusage .cells [1 ].memory_usage , 0 )
1687
-
1688
- hostusage = hw .numa_usage_from_instances (
1689
- hosttopo , None )
1684
+ hostusage = hw .numa_usage_from_instance_numa (hosttopo , None )
1690
1685
self .assertEqual (hostusage .cells [0 ].cpu_usage , 0 )
1691
1686
self .assertEqual (hostusage .cells [0 ].memory_usage , 0 )
1692
1687
self .assertEqual (hostusage .cells [1 ].cpu_usage , 0 )
1693
1688
self .assertEqual (hostusage .cells [1 ].memory_usage , 0 )
1694
1689
1695
- # Test the case where we have an instance with numa topology
1696
- # and one without
1697
- def test_topo_usage_mixed (self ):
1698
- hosttopo = objects .NUMATopology (cells = [
1699
- objects .NUMACell (id = 0 , cpuset = set ([0 , 1 ]), memory = 512 ,
1700
- cpu_usage = 0 , memory_usage = 0 , mempages = [
1701
- objects .NUMAPagesTopology (
1702
- size_kb = 4 , total = 512 , used = 0 )],
1703
- siblings = [set ([0 ]), set ([1 ])],
1704
- pinned_cpus = set ([])),
1705
- objects .NUMACell (id = 1 , cpuset = set ([2 , 3 ]), memory = 512 ,
1706
- cpu_usage = 0 , memory_usage = 0 , mempages = [
1707
- objects .NUMAPagesTopology (
1708
- size_kb = 4 , total = 512 , used = 0 )],
1709
- siblings = [set ([2 ]), set ([3 ])],
1710
- pinned_cpus = set ([])),
1711
- ])
1712
- instance1_topo = objects .InstanceNUMATopology (cells = [
1713
- objects .InstanceNUMACell (id = 0 , cpuset = set ([0 , 1 ]), memory = 256 ),
1714
- objects .InstanceNUMACell (id = 1 , cpuset = set ([2 ]), memory = 128 ),
1715
- ])
1716
- instance2_topo = None
1717
-
1718
- hostusage = hw .numa_usage_from_instances (hosttopo , [instance1_topo ])
1719
- self .assertEqual (hostusage .cells [0 ].cpu_usage , 2 )
1720
- self .assertEqual (hostusage .cells [0 ].memory_usage , 256 )
1721
- self .assertEqual (hostusage .cells [1 ].cpu_usage , 1 )
1722
- self .assertEqual (hostusage .cells [1 ].memory_usage , 128 )
1723
-
1724
- # This is like processing an instance with no numa_topology
1725
- hostusage = hw .numa_usage_from_instances (hostusage , instance2_topo )
1726
- self .assertEqual (hostusage .cells [0 ].cpu_usage , 2 )
1727
- self .assertEqual (hostusage .cells [0 ].memory_usage , 256 )
1728
- self .assertEqual (hostusage .cells [1 ].cpu_usage , 1 )
1729
- self .assertEqual (hostusage .cells [1 ].memory_usage , 128 )
1730
-
1731
1690
def test_topo_usage_with_network_metadata (self ):
1732
1691
r"""Validate behavior with network_metadata.
1733
1692
@@ -1748,7 +1707,7 @@ def test_topo_usage_with_network_metadata(self):
1748
1707
mempages = [], pinned_cpus = set ([])),
1749
1708
])
1750
1709
1751
- new_topo = hw .numa_usage_from_instances (topo , [] )
1710
+ new_topo = hw .numa_usage_from_instance_numa (topo , None )
1752
1711
self .assertIn ('network_metadata' , new_topo .cells [0 ])
1753
1712
self .assertNotIn ('network_metadata' , new_topo .cells [1 ])
1754
1713
@@ -1889,8 +1848,8 @@ def test_get_fitting_success_no_limits(self):
1889
1848
fitted_instance1 = hw .numa_fit_instance_to_host (
1890
1849
self .host , self .instance1 )
1891
1850
self .assertIsInstance (fitted_instance1 , objects .InstanceNUMATopology )
1892
- self .host = hw .numa_usage_from_instances ( self . host ,
1893
- [ fitted_instance1 ] )
1851
+ self .host = hw .numa_usage_from_instance_numa (
1852
+ self . host , fitted_instance1 )
1894
1853
fitted_instance2 = hw .numa_fit_instance_to_host (
1895
1854
self .host , self .instance3 )
1896
1855
self .assertIsInstance (fitted_instance2 , objects .InstanceNUMATopology )
@@ -1911,8 +1870,8 @@ def test_get_fitting_culmulative_fails_limits(self):
1911
1870
self .host , self .instance1 , self .limits )
1912
1871
self .assertIsInstance (fitted_instance1 , objects .InstanceNUMATopology )
1913
1872
self .assertEqual (1 , fitted_instance1 .cells [0 ].id )
1914
- self .host = hw .numa_usage_from_instances ( self . host ,
1915
- [ fitted_instance1 ] )
1873
+ self .host = hw .numa_usage_from_instance_numa (
1874
+ self . host , fitted_instance1 )
1916
1875
fitted_instance2 = hw .numa_fit_instance_to_host (
1917
1876
self .host , self .instance2 , self .limits )
1918
1877
self .assertIsNone (fitted_instance2 )
@@ -1922,8 +1881,8 @@ def test_get_fitting_culmulative_success_limits(self):
1922
1881
self .host , self .instance1 , self .limits )
1923
1882
self .assertIsInstance (fitted_instance1 , objects .InstanceNUMATopology )
1924
1883
self .assertEqual (1 , fitted_instance1 .cells [0 ].id )
1925
- self .host = hw .numa_usage_from_instances ( self . host ,
1926
- [ fitted_instance1 ] )
1884
+ self .host = hw .numa_usage_from_instance_numa (
1885
+ self . host , fitted_instance1 )
1927
1886
fitted_instance2 = hw .numa_fit_instance_to_host (
1928
1887
self .host , self .instance3 , self .limits )
1929
1888
self .assertIsInstance (fitted_instance2 , objects .InstanceNUMATopology )
@@ -2873,8 +2832,8 @@ def test_cpu_pinning_usage_from_instances(self):
2873
2832
cpu_pinning = {0 : 1 , 1 : 2 },
2874
2833
cpu_policy = fields .CPUAllocationPolicy .DEDICATED )])
2875
2834
2876
- host_pin = hw .numa_usage_from_instances (
2877
- host_pin , [ inst_pin_1 , inst_pin_2 ] )
2835
+ host_pin = hw .numa_usage_from_instance_numa ( host_pin , inst_pin_1 )
2836
+ host_pin = hw . numa_usage_from_instance_numa ( host_pin , inst_pin_2 )
2878
2837
self .assertEqual (set ([0 , 1 , 2 , 3 ]),
2879
2838
host_pin .cells [0 ].pinned_cpus )
2880
2839
@@ -2896,8 +2855,10 @@ def test_cpu_pinning_usage_from_instances_free(self):
2896
2855
cpuset = set ([0 , 1 ]), memory = 1024 , id = 0 ,
2897
2856
cpu_pinning = {0 : 0 , 1 : 3 },
2898
2857
cpu_policy = fields .CPUAllocationPolicy .DEDICATED )])
2899
- host_pin = hw .numa_usage_from_instances (
2900
- host_pin , [inst_pin_1 , inst_pin_2 ], free = True )
2858
+ host_pin = hw .numa_usage_from_instance_numa (host_pin , inst_pin_1 ,
2859
+ free = True )
2860
+ host_pin = hw .numa_usage_from_instance_numa (host_pin , inst_pin_2 ,
2861
+ free = True )
2901
2862
self .assertEqual (set (), host_pin .cells [0 ].pinned_cpus )
2902
2863
2903
2864
def test_host_usage_from_instances_fail (self ):
@@ -2921,9 +2882,9 @@ def test_host_usage_from_instances_fail(self):
2921
2882
cpu_pinning = {0 : 0 , 1 : 2 },
2922
2883
cpu_policy = fields .CPUAllocationPolicy .DEDICATED )])
2923
2884
2885
+ host_pin = hw .numa_usage_from_instance_numa (host_pin , inst_pin_1 )
2924
2886
self .assertRaises (exception .CPUPinningInvalid ,
2925
- hw .numa_usage_from_instances , host_pin ,
2926
- [inst_pin_1 , inst_pin_2 ])
2887
+ hw .numa_usage_from_instance_numa , host_pin , inst_pin_2 )
2927
2888
2928
2889
def test_host_usage_from_instances_isolate (self ):
2929
2890
host_pin = objects .NUMATopology (
@@ -2942,7 +2903,7 @@ def test_host_usage_from_instances_isolate(self):
2942
2903
cpu_thread_policy = fields .CPUThreadAllocationPolicy .ISOLATE
2943
2904
)])
2944
2905
2945
- new_cell = hw .numa_usage_from_instances (host_pin , [ inst_pin_1 ] )
2906
+ new_cell = hw .numa_usage_from_instance_numa (host_pin , inst_pin_1 )
2946
2907
self .assertEqual (host_pin .cells [0 ].cpuset ,
2947
2908
new_cell .cells [0 ].pinned_cpus )
2948
2909
self .assertEqual (new_cell .cells [0 ].cpu_usage , 4 )
@@ -2964,9 +2925,8 @@ def test_host_usage_from_instances_isolate_free(self):
2964
2925
cpu_thread_policy = fields .CPUThreadAllocationPolicy .ISOLATE
2965
2926
)])
2966
2927
2967
- new_cell = hw .numa_usage_from_instances (host_pin ,
2968
- [inst_pin_1 ],
2969
- free = True )
2928
+ new_cell = hw .numa_usage_from_instance_numa (host_pin , inst_pin_1 ,
2929
+ free = True )
2970
2930
self .assertEqual (set ([]), new_cell .cells [0 ].pinned_cpus )
2971
2931
self .assertEqual (new_cell .cells [0 ].cpu_usage , 0 )
2972
2932
@@ -2988,7 +2948,7 @@ def test_host_usage_from_instances_isolated_without_siblings(self):
2988
2948
cpu_thread_policy = fields .CPUThreadAllocationPolicy .ISOLATE
2989
2949
)])
2990
2950
2991
- new_cell = hw .numa_usage_from_instances (host_pin , [ inst_pin ] )
2951
+ new_cell = hw .numa_usage_from_instance_numa (host_pin , inst_pin )
2992
2952
self .assertEqual (inst_pin .cells [0 ].cpuset ,
2993
2953
new_cell .cells [0 ].pinned_cpus )
2994
2954
self .assertEqual (new_cell .cells [0 ].cpu_usage , 3 )
@@ -3011,9 +2971,8 @@ def test_host_usage_from_instances_isolated_without_siblings_free(self):
3011
2971
cpu_thread_policy = fields .CPUThreadAllocationPolicy .ISOLATE
3012
2972
)])
3013
2973
3014
- new_cell = hw .numa_usage_from_instances (host_pin ,
3015
- [inst_pin ],
3016
- free = True )
2974
+ new_cell = hw .numa_usage_from_instance_numa (host_pin , inst_pin ,
2975
+ free = True )
3017
2976
self .assertEqual (set ([3 ]), new_cell .cells [0 ].pinned_cpus )
3018
2977
self .assertEqual (new_cell .cells [0 ].cpu_usage , 1 )
3019
2978
@@ -3221,8 +3180,8 @@ def test_isolate_usage(self):
3221
3180
cpu_pinning = {0 : 0 },
3222
3181
cpuset_reserved = set ([1 ]))])
3223
3182
3224
- host_topo = hw .numa_usage_from_instances (
3225
- host_topo , [ inst_topo ])
3183
+ host_topo = hw .numa_usage_from_instance_numa ( host_topo , inst_topo )
3184
+
3226
3185
self .assertEqual (2 , host_topo .cells [0 ].cpu_usage )
3227
3186
self .assertEqual (set ([0 , 1 ]), host_topo .cells [0 ].pinned_cpus )
3228
3187
self .assertEqual (0 , host_topo .cells [1 ].cpu_usage )
@@ -3249,8 +3208,9 @@ def test_isolate_full_usage(self):
3249
3208
cpu_pinning = {0 : 2 },
3250
3209
cpuset_reserved = set ([3 ]))])
3251
3210
3252
- host_topo = hw .numa_usage_from_instances (
3253
- host_topo , [inst_topo1 , inst_topo2 ])
3211
+ host_topo = hw .numa_usage_from_instance_numa (host_topo , inst_topo1 )
3212
+ host_topo = hw .numa_usage_from_instance_numa (host_topo , inst_topo2 )
3213
+
3254
3214
self .assertEqual (2 , host_topo .cells [0 ].cpu_usage )
3255
3215
self .assertEqual (set ([0 , 1 ]), host_topo .cells [0 ].pinned_cpus )
3256
3216
0 commit comments