def test_get_resources_hugepages_round(self): node = factory.make_Node() numa_node0 = node.default_numanode numa_node0.cores = [0, 1] numa_node0.memory = 4096 numa_node0.save() numa_node1 = factory.make_NUMANode( node=node, cores=[2, 3], memory=8192 ) factory.make_NUMANodeHugepages( numa_node=numa_node0, page_size=2048 * MB, total=4096 * MB ) factory.make_NUMANodeHugepages( numa_node=numa_node1, page_size=4096 * MB, total=8192 * MB ) pod = factory.make_Pod(pod_type="lxd") pod.hints.nodes.add(node) factory.make_VirtualMachine( memory=2048, pinned_cores=[0, 2], hugepages_backed=True, bmc=pod, machine=factory.make_Node(system_id="vm0"), ) resources = get_vm_host_resources(pod) self.assertEqual( [asdict(r) for r in resources], [ { "cores": {"allocated": [0], "free": [1]}, "memory": { "general": {"allocated": 0, "free": 0}, "hugepages": [ { "allocated": 2048 * MB, "free": 2048 * MB, "page_size": 2048 * MB, } ], }, "node_id": 0, "vms": [{"pinned_cores": [0], "system_id": "vm0"}], }, { "cores": {"allocated": [2], "free": [3]}, "memory": { "general": {"allocated": 0, "free": 0}, "hugepages": [ { "allocated": 4096 * MB, "free": 4096 * MB, "page_size": 4096 * MB, } ], }, "node_id": 1, "vms": [{"pinned_cores": [2], "system_id": "vm0"}], }, ], )
def test_get_resources_numa_unaligned_hugepages(self): node = factory.make_Node() numa_node0 = node.default_numanode numa_node0.cores = [0, 1] numa_node0.memory = 4096 numa_node0.save() numa_node1 = factory.make_NUMANode(node=node, cores=[2, 3], memory=4096) factory.make_NUMANodeHugepages(numa_node=numa_node0, page_size=1024 * MB, total=1024 * MB) factory.make_NUMANodeHugepages(numa_node=numa_node1, page_size=1024 * MB, total=4096 * MB) pod = factory.make_Pod(pod_type="lxd") pod.hints.nodes.add(node) vm = factory.make_VirtualMachine( memory=2048, pinned_cores=[0, 2], hugepages_backed=True, bmc=pod, ) resources = get_vm_host_resources(pod) self.assertEqual( [asdict(r) for r in resources.numa], [ { "cores": { "allocated": [0], "free": [1] }, "memory": { "general": { "allocated": 0, "free": 3072 * MB }, "hugepages": [{ "allocated": 1024 * MB, "free": 0, "page_size": 1024 * MB, }], }, "interfaces": [], "node_id": 0, "vms": [vm.id], }, { "cores": { "allocated": [2], "free": [3] }, "memory": { "general": { "allocated": 0, "free": 0 }, "hugepages": [{ "allocated": 1024 * MB, "free": 3072 * MB, "page_size": 1024 * MB, }], }, "interfaces": [], "node_id": 1, "vms": [vm.id], }, ], )
def test_get_resources_global_resources(self): node = factory.make_Node() numa_node0 = node.default_numanode numa_node0.cores = [0, 1] numa_node0.memory = 4096 numa_node0.save() factory.make_NUMANode(node=node, cores=[2, 3], memory=2048) factory.make_NUMANode(node=node, cores=[4, 5], memory=2048) factory.make_NUMANode(node=node, cores=[6, 7], memory=2048) factory.make_NUMANodeHugepages(numa_node=numa_node0, page_size=1024 * MB, total=2048 * MB) project = factory.make_string() pod = factory.make_Pod(pod_type="lxd", parameters={"project": project}, host=node) pool1 = factory.make_PodStoragePool(pod=pod) pool2 = factory.make_PodStoragePool(pod=pod) vm1 = factory.make_VirtualMachine( memory=1024, pinned_cores=[0, 1], hugepages_backed=False, bmc=pod, project=project, ) disk1 = factory.make_VirtualMachineDisk(vm=vm1, backing_pool=pool1) vm2 = factory.make_VirtualMachine( memory=1024, pinned_cores=[2], hugepages_backed=False, bmc=pod, ) disk2 = factory.make_VirtualMachineDisk(vm=vm2, backing_pool=pool2) factory.make_VirtualMachine( memory=1024, unpinned_cores=2, hugepages_backed=True, project=project, bmc=pod, ) factory.make_VirtualMachine(memory=2048, unpinned_cores=1, hugepages_backed=False, bmc=pod) resources = get_vm_host_resources(pod) self.assertEqual(resources.vm_count.tracked, 2) self.assertEqual(resources.vm_count.other, 2) self.assertEqual(resources.cores.free, 2) self.assertEqual(resources.cores.allocated, 6) self.assertEqual(resources.cores.allocated_tracked, 4) self.assertEqual(resources.cores.allocated_other, 2) self.assertEqual(resources.memory.general.free, 6144 * MB) self.assertEqual(resources.memory.general.allocated, 4096 * MB) self.assertEqual(resources.memory.general.allocated_tracked, 1024 * MB) self.assertEqual(resources.memory.general.allocated_other, 3072 * MB) self.assertEqual(resources.memory.hugepages.free, 1024 * MB) self.assertEqual(resources.memory.hugepages.allocated, 1024 * MB) self.assertEqual(resources.memory.hugepages.allocated_tracked, 1024 * MB) self.assertEqual(resources.memory.hugepages.allocated_other, 0) self.assertEqual(resources.storage.allocated_tracked, disk1.size) self.assertEqual(resources.storage.allocated_other, disk2.size) self.assertEqual( resources.storage.free, pool1.storage + pool2.storage - disk1.size - disk2.size, )