def setUp(self): super(NUMATopologyClaimsTest, self).setUp() self.host = hw.VirtNUMAHostTopology( cells=[ hw.VirtNUMATopologyCellUsage( 1, set([1, 2, 3, 4]), 2048, cpu_usage=1, memory_usage=512), hw.VirtNUMATopologyCellUsage( 2, set([5, 6]), 1024)]) self.limits = hw.VirtNUMALimitTopology( cells=[ hw.VirtNUMATopologyCellLimit( 1, set([1, 2, 3, 4]), 2048, cpu_limit=8, memory_limit=4096), hw.VirtNUMATopologyCellLimit( 2, set([5, 6]), 1024, cpu_limit=4, memory_limit=2048)]) self.large_instance = hw.VirtNUMAInstanceTopology( cells=[ hw.VirtNUMATopologyCell(1, set([1, 2, 3, 4, 5, 6]), 8192), hw.VirtNUMATopologyCell(2, set([7, 8]), 4096)]) self.medium_instance = hw.VirtNUMAInstanceTopology( cells=[ hw.VirtNUMATopologyCell(1, set([1, 2, 3, 4]), 1024), hw.VirtNUMATopologyCell(2, set([7, 8]), 2048)]) self.small_instance = hw.VirtNUMAInstanceTopology( cells=[ hw.VirtNUMATopologyCell(1, set([1]), 256), hw.VirtNUMATopologyCell(2, set([5]), 1024)])
def test_numa_topology_passes(self, mock_get): huge_instance = hardware.VirtNUMAInstanceTopology( cells=[hardware.VirtNUMATopologyCell( 1, set([1, 2, 3, 4, 5]), 2048)]) limit_topo = hardware.VirtNUMALimitTopology( cells=[hardware.VirtNUMATopologyCellLimit( 1, [1, 2], 512, cpu_limit=5, memory_limit=4096), hardware.VirtNUMATopologyCellLimit( 1, [3, 4], 512, cpu_limit=5, memory_limit=4096)]) self._claim(limits={'numa_topology': limit_topo.to_json()}, numa_topology=huge_instance)
def test_numa_topology_passes(self, mock_get): huge_instance = objects.InstanceNUMATopology( cells=[objects.InstanceNUMACell( id=1, cpuset=set([1, 2]), memory=512)]) limit_topo = hardware.VirtNUMALimitTopology( cells=[hardware.VirtNUMATopologyCellLimit( 1, [1, 2], 512, cpu_limit=5, memory_limit=4096), hardware.VirtNUMATopologyCellLimit( 1, [3, 4], 512, cpu_limit=5, memory_limit=4096)]) self._claim(limits={'numa_topology': limit_topo.to_json()}, numa_topology=huge_instance)
def test_numa_topology_fails(self, mock_get): huge_instance = hardware.VirtNUMAInstanceTopology( cells=[hardware.VirtNUMATopologyCell( 1, set([1, 2, 3, 4, 5]), 2048)]) limit_topo = hardware.VirtNUMALimitTopology( cells=[hardware.VirtNUMATopologyCellLimit( 1, [1, 2], 512, cpu_limit=2, memory_limit=512), hardware.VirtNUMATopologyCellLimit( 1, [3, 4], 512, cpu_limit=2, memory_limit=512)]) self.assertRaises(exception.ComputeResourcesUnavailable, self._claim, limits={'numa_topology': limit_topo.to_json()}, numa_topology=huge_instance)
def host_passes(self, host_state, filter_properties): ram_ratio = CONF.ram_allocation_ratio cpu_ratio = CONF.cpu_allocation_ratio instance = filter_properties.get('instance_properties', {}) instance_topology = hardware.instance_topology_from_instance(instance) host_topology, _fmt = hardware.host_topology_and_format_from_host( host_state) if instance_topology: if host_topology: if not hardware.VirtNUMAHostTopology.can_fit_instances( host_topology, [instance_topology]): return False limit_cells = [] usage_after_instance = ( hardware.VirtNUMAHostTopology.usage_from_instances( host_topology, [instance_topology])) for cell in usage_after_instance.cells: max_cell_memory = int(cell.memory * ram_ratio) max_cell_cpu = len(cell.cpuset) * cpu_ratio if (cell.memory_usage > max_cell_memory or cell.cpu_usage > max_cell_cpu): return False limit_cells.append( hardware.VirtNUMATopologyCellLimit( cell.id, cell.cpuset, cell.memory, max_cell_cpu, max_cell_memory)) host_state.limits['numa_topology'] = ( hardware.VirtNUMALimitTopology( cells=limit_cells).to_json()) return True else: return False else: return True
def host_passes(self, host_state, filter_properties): ram_ratio = CONF.ram_allocation_ratio cpu_ratio = CONF.cpu_allocation_ratio request_spec = filter_properties.get('request_spec', {}) instance = request_spec.get('instance_properties', {}) requested_topology = hardware.instance_topology_from_instance(instance) host_topology, _fmt = hardware.host_topology_and_format_from_host( host_state) if requested_topology and host_topology: limit_cells = [] for cell in host_topology.cells: max_cell_memory = int(cell.memory * ram_ratio) max_cell_cpu = len(cell.cpuset) * cpu_ratio limit_cells.append( hardware.VirtNUMATopologyCellLimit(cell.id, cell.cpuset, cell.memory, max_cell_cpu, max_cell_memory)) limits = hardware.VirtNUMALimitTopology(cells=limit_cells) instance_topology = (hardware.numa_fit_instance_to_host( host_topology, requested_topology, limits_topology=limits)) if not instance_topology: return False host_state.limits['numa_topology'] = limits.to_json() instance['numa_topology'] = instance_topology return True elif requested_topology: return False else: return True
def test_numa_limits_topo_dict(self): topo = hw.VirtNUMALimitTopology( cells=[ hw.VirtNUMATopologyCellLimit( 1, set([1, 2]), 1024, 4, 2048), hw.VirtNUMATopologyCellLimit( 2, set([3, 4]), 1024, 4, 2048)]) topo_dict = {'cells': [ {'cpus': '1,2', 'cpu_limit': 4, 'mem': {'total': 1024, 'limit': 2048}, 'id': 1}, {'cpus': '3,4', 'cpu_limit': 4, 'mem': {'total': 1024, 'limit': 2048}, 'id': 2}]} self._test_to_dict(topo, topo_dict) self._test_topo_from_dict(topo_dict, topo)
def test_numa_limit_cell_dict(self): cell = hw.VirtNUMATopologyCellLimit(1, set([1, 2]), 512, 4, 2048) cell_dict = {'cpus': '1,2', 'cpu_limit': 4, 'mem': {'total': 512, 'limit': 2048}, 'id': 1} self._test_to_dict(cell, cell_dict) self._test_cell_from_dict(cell_dict, cell)
def host_passes(self, host_state, filter_properties): ram_ratio = CONF.ram_allocation_ratio cpu_ratio = CONF.cpu_allocation_ratio instance = filter_properties.get('instance_properties', {}) instance_topology = hardware.instance_topology_from_instance(instance) if instance_topology: if host_state.numa_topology: limit_cells = [] usage_after_instance = ( hardware.get_host_numa_usage_from_instance( host_state, instance, never_serialize_result=True)) for cell in usage_after_instance.cells: max_cell_memory = int(cell.memory * ram_ratio) max_cell_cpu = len(cell.cpuset) * cpu_ratio if (cell.memory_usage > max_cell_memory or cell.cpu_usage > max_cell_cpu): return False limit_cells.append( hardware.VirtNUMATopologyCellLimit( cell.id, cell.cpuset, cell.memory, max_cell_cpu, max_cell_memory)) host_state.limits['numa_topology'] = ( hardware.VirtNUMALimitTopology( cells=limit_cells).to_json()) return True else: return False else: return True