Exemple #1
0
 def test_full_dehydrate_for_list_no_details(self):
     admin = factory.make_admin()
     handler = PodHandler(admin, {}, None)
     vlan = factory.make_VLAN(dhcp_on=True)
     subnet = factory.make_Subnet(vlan=vlan)
     node = factory.make_Node_with_Interface_on_Subnet(subnet=subnet)
     ip = factory.make_StaticIPAddress(interface=node.boot_interface,
                                       subnet=subnet)
     numa_node0 = node.default_numanode
     numa_node0.cores = [0, 3]
     numa_node0.memory = 4096
     numa_node0.save()
     factory.make_NUMANode(node=node, cores=[1, 4], memory=1024)
     factory.make_NUMANode(node=node, cores=[2, 5], memory=2048)
     project = factory.make_string()
     pod = self.make_pod_with_hints(
         pod_type="lxd",
         parameters={"project": project},
         host=node,
         ip_address=ip,
     )
     factory.make_VirtualMachine(bmc=pod, project=project)
     result = handler.full_dehydrate(pod, for_list=True)
     self.assertEqual(result["resources"]["numa"], [])
     self.assertEqual(result["resources"]["vms"], [])
Exemple #2
0
 def test_get_numa_nodes_indexes_many_devices(self):
     node = factory.make_Node()
     numa_nodes = [
         node.default_numanode,
         factory.make_NUMANode(node=node),
         factory.make_NUMANode(node=node),
     ]
     block_devices = [
         factory.make_PhysicalBlockDevice(numa_node=numa_node)
         for numa_node in numa_nodes
     ]
     filesystems = [
         factory.make_Filesystem(
             fstype=FILESYSTEM_TYPE.LVM_PV, block_device=block_device
         )
         for block_device in block_devices
     ]
     fsgroup = factory.make_FilesystemGroup(
         node=node,
         filesystems=filesystems,
         group_type=FILESYSTEM_GROUP_TYPE.LVM_VG,
     )
     virtual_block_device = factory.make_VirtualBlockDevice(
         filesystem_group=fsgroup
     )
     cache_set = factory.make_CacheSet(block_device=virtual_block_device)
     self.assertEqual(cache_set.get_numa_node_indexes(), [0, 1, 2])
 def test_get_resources_unaligned(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)
     pod = factory.make_Pod(pod_type="lxd")
     pod.hints.nodes.add(node)
     factory.make_VirtualMachine(
         memory=2048,
         pinned_cores=[0, 2],
         hugepages_backed=False,
         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": 1024 * MB,
                         "free": 3072 * MB
                     },
                     "hugepages": [],
                 },
                 "node_id": 0,
                 "vms": [{
                     "pinned_cores": [0],
                     "system_id": "vm0"
                 }],
             },
             {
                 "cores": {
                     "allocated": [2],
                     "free": [3]
                 },
                 "memory": {
                     "general": {
                         "allocated": 1024 * MB,
                         "free": 1024 * MB
                     },
                     "hugepages": [],
                 },
                 "node_id": 1,
                 "vms": [{
                     "pinned_cores": [2],
                     "system_id": "vm0"
                 }],
             },
         ],
     )
 def test_get_resources_numa_aligned(self):
     node = factory.make_Node()
     numa_node0 = node.default_numanode
     numa_node0.cores = [0, 3]
     numa_node0.memory = 4096
     numa_node0.save()
     factory.make_NUMANode(node=node, cores=[1, 4], memory=1024)
     factory.make_NUMANode(node=node, cores=[2, 5], memory=2048)
     pod = factory.make_Pod(pod_type="lxd", host=node)
     vm0 = factory.make_VirtualMachine(
         memory=1024,
         pinned_cores=[0],
         hugepages_backed=False,
         bmc=pod,
     )
     vm1 = factory.make_VirtualMachine(
         memory=1024,
         pinned_cores=[2, 5],
         hugepages_backed=False,
         bmc=pod,
     )
     resources = get_vm_host_resources(pod)
     self.assertEqual(
         [asdict(r) for r in resources.numa],
         [
             {
                 "cores": {"allocated": [0], "free": [3]},
                 "memory": {
                     "general": {"allocated": 1024 * MB, "free": 3072 * MB},
                     "hugepages": [],
                 },
                 "interfaces": [],
                 "node_id": 0,
                 "vms": [vm0.id],
             },
             {
                 "cores": {"allocated": [], "free": [1, 4]},
                 "memory": {
                     "general": {"allocated": 0, "free": 1024 * MB},
                     "hugepages": [],
                 },
                 "interfaces": [],
                 "node_id": 1,
                 "vms": [],
             },
             {
                 "cores": {"allocated": [2, 5], "free": []},
                 "memory": {
                     "general": {"allocated": 1024 * MB, "free": 1024 * MB},
                     "hugepages": [],
                 },
                 "interfaces": [],
                 "node_id": 2,
                 "vms": [vm1.id],
             },
         ],
     )
Exemple #5
0
    def test_read_returns_numa_node(self):
        node = factory.make_Node(with_boot_disk=False)
        factory.make_NUMANode(node=node)
        numa_node2 = factory.make_NUMANode(node=node)
        factory.make_PhysicalBlockDevice(numa_node=numa_node2)

        uri = get_blockdevices_uri(node)
        response = self.client.get(uri)

        self.assertEqual(http.client.OK, response.status_code,
                         response.content)
        [parsed_device] = json_load_bytes(response.content)
        self.assertEqual(parsed_device["numa_node"], 2)
Exemple #6
0
 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"}],
             },
         ],
     )
Exemple #7
0
 def test_creates_physical_block_device_with_numa_node(self):
     node = factory.make_Node()
     numa_node = factory.make_NUMANode(node=node)
     name = factory.make_name("sd")
     id_path = factory.make_absolute_path()
     size = random.randint(MIN_BLOCK_DEVICE_SIZE,
                           MIN_BLOCK_DEVICE_SIZE * 10)
     block_size = 4096
     form = CreatePhysicalBlockDeviceForm(
         node,
         data={
             "name": name,
             "id_path": id_path,
             "size": size,
             "block_size": block_size,
             "numa_node": numa_node.index,
         },
     )
     self.assertTrue(form.is_valid(), form.errors)
     block_device = form.save()
     self.assertThat(
         block_device,
         MatchesStructure.byEquality(
             name=name,
             id_path=id_path,
             size=size,
             block_size=block_size,
             numa_node=numa_node,
         ),
     )
Exemple #8
0
 def test_update_no_numa_node_change(self):
     node = factory.make_Node()
     numa_node = factory.make_NUMANode(node=node)
     # associate with a node different from the default one
     block_device = factory.make_PhysicalBlockDevice(numa_node=numa_node)
     form = UpdatePhysicalBlockDeviceForm(instance=block_device, data={})
     self.assertTrue(form.is_valid(), form.errors)
     block_device = form.save()
     self.assertEqual(block_device.numa_node, numa_node)
 def test_get_resources_global_resources_pinned_cores_overlap(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)
     pod = factory.make_Pod(pod_type="lxd", host=node)
     factory.make_VirtualMachine(
         pinned_cores=[0, 1],
         bmc=pod,
     )
     factory.make_VirtualMachine(
         pinned_cores=[1, 2],
         bmc=pod,
     )
     resources = get_vm_host_resources(pod)
     self.assertEqual(resources.cores.free, 0)
     self.assertEqual(resources.cores.allocated, 4)
 def test_node_from_numa_node(self):
     numa_node = factory.make_NUMANode()
     bdev = PhysicalBlockDevice.objects.create(
         serial="123",
         model="disk",
         name="sda",
         size=MIN_BLOCK_DEVICE_SIZE,
         block_size=1024,
         numa_node=numa_node,
     )
     self.assertEqual(bdev.node, numa_node.node)
Exemple #11
0
 def test_unique(self):
     numa_node = factory.make_NUMANode()
     NUMANodeHugepages.objects.create(
         numanode=numa_node, page_size=2048, total=20480
     )
     self.assertRaises(
         ValidationError,
         NUMANodeHugepages.objects.create,
         numanode=numa_node,
         page_size=2048,
         total=20480,
     )
 def test_node_and_numa_node_fail(self):
     node = factory.make_Node()
     numa_node = factory.make_NUMANode()
     self.assertRaises(
         ValidationError,
         PhysicalBlockDevice.objects.create,
         serial="123",
         model="disk",
         name="sda",
         size=MIN_BLOCK_DEVICE_SIZE,
         block_size=1024,
         node=node,
         numa_node=numa_node,
     )
 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,
     )
Exemple #14
0
    def test_get_host_interfaces_sriov(self):
        admin = factory.make_admin()
        handler = PodHandler(admin, {}, None)
        node = factory.make_Machine()
        numa_node0 = node.default_numanode
        numa_node1 = factory.make_NUMANode(node=node)
        iface1 = factory.make_Interface(
            INTERFACE_TYPE.PHYSICAL,
            name="eth0",
            numa_node=numa_node0,
            sriov_max_vf=8,
        )
        iface2 = factory.make_Interface(
            INTERFACE_TYPE.PHYSICAL,
            name="eth1",
            numa_node=numa_node1,
            sriov_max_vf=16,
        )
        pod = self.make_pod_with_hints(
            pod_type="lxd",
            host=node,
        )
        vm_machine0 = factory.make_Node(system_id="vm0")
        factory.make_Interface(
            INTERFACE_TYPE.PHYSICAL,
            node=vm_machine0,
            mac_address="11:11:11:11:11:11",
        )
        vm_machine1 = factory.make_Node(system_id="vm1")
        factory.make_Interface(
            INTERFACE_TYPE.PHYSICAL,
            node=vm_machine1,
            mac_address="aa:aa:aa:aa:aa:aa",
        )
        factory.make_Interface(
            INTERFACE_TYPE.PHYSICAL,
            node=vm_machine1,
            mac_address="bb:bb:bb:bb:bb:bb",
        )
        vm0 = factory.make_VirtualMachine(
            bmc=pod,
            machine=vm_machine0,
        )
        VirtualMachineInterface.objects.create(
            vm=vm0,
            mac_address="11:11:11:11:11:11",
            host_interface=iface1,
            attachment_type=InterfaceAttachType.SRIOV,
        )
        vm1 = factory.make_VirtualMachine(bmc=pod, machine=vm_machine1)
        VirtualMachineInterface.objects.create(
            vm=vm1,
            mac_address="aa:aa:aa:aa:aa:aa",
            host_interface=iface1,
            attachment_type=InterfaceAttachType.SRIOV,
        )
        VirtualMachineInterface.objects.create(
            vm=vm1,
            mac_address="bb:bb:bb:bb:bb:bb",
            host_interface=iface2,
            attachment_type=InterfaceAttachType.SRIOV,
        )

        result = handler.get({"id": pod.id})
        numa1, numa2 = result["resources"]["numa"]
        self.assertCountEqual(numa1["interfaces"], [iface1.id])
        self.assertCountEqual(numa2["interfaces"], [iface2.id])
        self.assertCountEqual(
            result["resources"]["interfaces"],
            [
                {
                    "id": iface1.id,
                    "name": "eth0",
                    "numa_index": 0,
                    "virtual_functions": {
                        "allocated_tracked": 2,
                        "allocated_other": 0,
                        "free": 6,
                    },
                },
                {
                    "id": iface2.id,
                    "name": "eth1",
                    "numa_index": 1,
                    "virtual_functions": {
                        "allocated_tracked": 1,
                        "allocated_other": 0,
                        "free": 15,
                    },
                },
            ],
        )
Exemple #15
0
    def test_get_with_pod_host(self):
        admin = factory.make_admin()
        handler = PodHandler(admin, {}, None)
        vlan = factory.make_VLAN(dhcp_on=True)
        subnet = factory.make_Subnet(vlan=vlan)
        node = factory.make_Node_with_Interface_on_Subnet(subnet=subnet)
        ip = factory.make_StaticIPAddress(interface=node.boot_interface,
                                          subnet=subnet)
        numa_node0 = node.default_numanode
        numa_node0.cores = [0, 3]
        numa_node0.memory = 4096
        numa_node0.save()
        factory.make_NUMANode(node=node, cores=[1, 4], memory=1024)
        factory.make_NUMANode(node=node, cores=[2, 5], memory=2048)
        project = factory.make_string()
        pod = self.make_pod_with_hints(
            pod_type="lxd",
            parameters={"project": project},
            host=node,
            ip_address=ip,
        )
        vm0 = factory.make_VirtualMachine(
            project=project,
            memory=1024,
            pinned_cores=[0],
            hugepages_backed=False,
            bmc=pod,
            machine=factory.make_Node(system_id="vm0"),
        )
        vm1 = factory.make_VirtualMachine(
            project=project,
            memory=1024,
            pinned_cores=[2, 5],
            hugepages_backed=False,
            bmc=pod,
            machine=factory.make_Node(system_id="vm1"),
        )

        expected_numa_details = [
            {
                "cores": {
                    "allocated": [0],
                    "free": [3]
                },
                "interfaces": [node.boot_interface.id],
                "memory": {
                    "general": {
                        "allocated": 1024 * MB,
                        "free": 3072 * MB
                    },
                    "hugepages": [],
                },
                "node_id": 0,
                "vms": [vm0.id],
            },
            {
                "cores": {
                    "allocated": [],
                    "free": [1, 4]
                },
                "interfaces": [],
                "memory": {
                    "general": {
                        "allocated": 0,
                        "free": 1024 * MB
                    },
                    "hugepages": [],
                },
                "node_id": 1,
                "vms": [],
            },
            {
                "cores": {
                    "allocated": [2, 5],
                    "free": []
                },
                "interfaces": [],
                "memory": {
                    "general": {
                        "allocated": 1024 * MB,
                        "free": 1024 * MB
                    },
                    "hugepages": [],
                },
                "node_id": 2,
                "vms": [vm1.id],
            },
        ]
        result = handler.get({"id": pod.id})
        self.assertThat(result["host"], Equals(node.system_id))
        self.assertThat(result["attached_vlans"], Equals([subnet.vlan_id]))
        self.assertThat(result["boot_vlans"], Equals([subnet.vlan_id]))
        resources = result["resources"]
        self.assertEqual(
            resources["cores"],
            {
                "allocated_other": 0,
                "allocated_tracked": 3,
                "free": 3
            },
        )
        self.assertEqual(
            resources["interfaces"],
            [{
                "id": node.boot_interface.id,
                "name": node.boot_interface.name,
                "numa_index": 0,
                "virtual_functions": {
                    "allocated_other": 0,
                    "allocated_tracked": 0,
                    "free": 0,
                },
            }],
        )
        self.assertEqual(
            resources["memory"],
            {
                "general": {
                    "allocated_other": 0,
                    "allocated_tracked": 2147483648,
                    "free": 5368709120,
                },
                "hugepages": {
                    "allocated_other": 0,
                    "allocated_tracked": 0,
                    "free": 0,
                },
            },
        )
        self.assertEqual(resources["numa"], expected_numa_details)
        self.assertEqual(resources["vm_count"], {"other": 0, "tracked": 2})
        self.assertCountEqual(
            resources["vms"],
            [
                {
                    "id": vm0.id,
                    "system_id": "vm0",
                    "memory": 1024 * MB,
                    "hugepages_backed": False,
                    "pinned_cores": [0],
                    "unpinned_cores": 0,
                },
                {
                    "id": vm1.id,
                    "system_id": "vm1",
                    "memory": 1024 * MB,
                    "hugepages_backed": False,
                    "pinned_cores": [2, 5],
                    "unpinned_cores": 0,
                },
            ],
        )
Exemple #16
0
    def test_get_with_pod_host(self):
        admin = factory.make_admin()
        handler = PodHandler(admin, {}, None)
        vlan = factory.make_VLAN(dhcp_on=True)
        subnet = factory.make_Subnet(vlan=vlan)
        node = factory.make_Node_with_Interface_on_Subnet(subnet=subnet)
        ip = factory.make_StaticIPAddress(interface=node.boot_interface,
                                          subnet=subnet)
        numa_node0 = node.default_numanode
        numa_node0.cores = [0, 3]
        numa_node0.memory = 4096
        numa_node0.save()
        factory.make_NUMANode(node=node, cores=[1, 4], memory=1024)
        factory.make_NUMANode(node=node, cores=[2, 5], memory=2048)
        pod = self.make_pod_with_hints(pod_type="lxd",
                                       host=node,
                                       ip_address=ip)
        factory.make_VirtualMachine(
            memory=1024,
            pinned_cores=[0],
            hugepages_backed=False,
            bmc=pod,
            machine=factory.make_Node(system_id="vm0"),
        )
        factory.make_VirtualMachine(
            memory=1024,
            pinned_cores=[2, 5],
            hugepages_backed=False,
            bmc=pod,
            machine=factory.make_Node(system_id="vm1"),
        )

        expected_data = handler.full_dehydrate(pod)
        result = handler.get({"id": pod.id})
        self.assertItemsEqual(expected_data.keys(), result.keys())
        for key in expected_data:
            self.assertEqual(expected_data[key], result[key], key)
        self.assertThat(result, Equals(expected_data))
        self.assertThat(result["host"], Equals(node.system_id))
        self.assertThat(result["attached_vlans"], Equals([subnet.vlan_id]))
        self.assertThat(result["boot_vlans"], Equals([subnet.vlan_id]))
        self.assertEqual(
            result["numa_pinning"],
            [
                {
                    "cores": {
                        "allocated": [0],
                        "free": [3]
                    },
                    "interfaces": [
                        {
                            "id": 100,
                            "name": "eth4",
                            "virtual_functions": {
                                "allocated": 4,
                                "free": 12
                            },
                        },
                        {
                            "id": 200,
                            "name": "eth5",
                            "virtual_functions": {
                                "allocated": 14,
                                "free": 2
                            },
                        },
                    ],
                    "memory": {
                        "general": {
                            "allocated": 1024 * MB,
                            "free": 3072 * MB
                        },
                        "hugepages": [],
                    },
                    "node_id":
                    0,
                    "vms": [
                        {
                            "pinned_cores": [0],
                            "system_id":
                            "vm0",
                            "networks": [
                                {
                                    "guest_nic_id": 101,
                                    "host_nic_id": 100
                                },
                                {
                                    "guest_nic_id": 102,
                                    "host_nic_id": 100
                                },
                            ],
                        },
                    ],
                },
                {
                    "cores": {
                        "allocated": [],
                        "free": [1, 4]
                    },
                    "interfaces": [
                        {
                            "id": 100,
                            "name": "eth4",
                            "virtual_functions": {
                                "allocated": 4,
                                "free": 12
                            },
                        },
                        {
                            "id": 200,
                            "name": "eth5",
                            "virtual_functions": {
                                "allocated": 14,
                                "free": 2
                            },
                        },
                    ],
                    "memory": {
                        "general": {
                            "allocated": 0,
                            "free": 1024 * MB
                        },
                        "hugepages": [],
                    },
                    "node_id":
                    1,
                    "vms": [],
                },
                {
                    "cores": {
                        "allocated": [2, 5],
                        "free": []
                    },
                    "interfaces": [
                        {
                            "id": 100,
                            "name": "eth4",
                            "virtual_functions": {
                                "allocated": 4,
                                "free": 12
                            },
                        },
                        {
                            "id": 200,
                            "name": "eth5",
                            "virtual_functions": {
                                "allocated": 14,
                                "free": 2
                            },
                        },
                    ],
                    "memory": {
                        "general": {
                            "allocated": 1024 * MB,
                            "free": 1024 * MB
                        },
                        "hugepages": [],
                    },
                    "node_id":
                    2,
                    "vms": [
                        {
                            "pinned_cores": [2, 5],
                            "system_id":
                            "vm1",
                            "networks": [
                                {
                                    "guest_nic_id": 101,
                                    "host_nic_id": 100
                                },
                                {
                                    "guest_nic_id": 102,
                                    "host_nic_id": 100
                                },
                            ],
                        },
                    ],
                },
            ],
        )
Exemple #17
0
    def test_get_host_interfaces_no_sriov(self):
        admin = factory.make_admin()
        handler = PodHandler(admin, {}, None)
        node = factory.make_Machine()
        numa_node0 = node.default_numanode
        numa_node1 = factory.make_NUMANode(node=node)
        iface1 = factory.make_Interface(
            INTERFACE_TYPE.PHYSICAL, name="eth0", numa_node=numa_node0
        )
        br1 = factory.make_Interface(
            INTERFACE_TYPE.BRIDGE,
            name="br0",
            numa_node=numa_node0,
            parents=[iface1],
        )
        iface2 = factory.make_Interface(
            INTERFACE_TYPE.PHYSICAL, name="eth1", numa_node=numa_node1
        )
        pod = self.make_pod_with_hints(
            pod_type="lxd",
            host=node,
        )
        vm_machine0 = factory.make_Node(system_id="vm0")
        factory.make_Interface(
            INTERFACE_TYPE.PHYSICAL,
            node=vm_machine0,
            mac_address="11:11:11:11:11:11",
        )
        vm_machine1 = factory.make_Node(system_id="vm1")
        factory.make_Interface(
            INTERFACE_TYPE.PHYSICAL,
            node=vm_machine1,
            mac_address="aa:aa:aa:aa:aa:aa",
        )
        factory.make_Interface(
            INTERFACE_TYPE.PHYSICAL,
            node=vm_machine1,
            mac_address="bb:bb:bb:bb:bb:bb",
        )
        vm0 = factory.make_VirtualMachine(
            bmc=pod,
            machine=vm_machine0,
        )
        VirtualMachineInterface.objects.create(
            vm=vm0,
            mac_address="11:11:11:11:11:11",
            host_interface=br1,
            attachment_type=InterfaceAttachType.BRIDGE,
        )
        vm1 = factory.make_VirtualMachine(bmc=pod, machine=vm_machine1)
        VirtualMachineInterface.objects.create(
            vm=vm1,
            mac_address="aa:aa:aa:aa:aa:aa",
            host_interface=br1,
            attachment_type=InterfaceAttachType.BRIDGE,
        )
        VirtualMachineInterface.objects.create(
            vm=vm1,
            mac_address="bb:bb:bb:bb:bb:bb",
            host_interface=iface2,
            attachment_type=InterfaceAttachType.MACVLAN,
        )

        result = handler.get({"id": pod.id})
        numa1, numa2 = result["numa_pinning"]
        self.assertEqual(
            [
                {
                    "id": iface1.id,
                    "name": "eth0",
                    "virtual_functions": {"allocated": 0, "free": 0},
                },
                {
                    "id": br1.id,
                    "name": "br0",
                    "virtual_functions": {"allocated": 0, "free": 0},
                },
            ],
            numa1["interfaces"],
        )
        self.assertEqual(
            [
                [
                    {
                        "guest_nic_id": None,
                        "host_nic_id": br1.id,
                    },
                ],
                [
                    {
                        "guest_nic_id": None,
                        "host_nic_id": br1.id,
                    },
                ],
            ],
            [vm["networks"] for vm in numa1["vms"]],
        )
        self.assertEqual(
            [
                {
                    "id": iface2.id,
                    "name": "eth1",
                    "virtual_functions": {"allocated": 0, "free": 0},
                }
            ],
            numa2["interfaces"],
        )
        self.assertEqual(
            [
                [
                    {
                        "guest_nic_id": None,
                        "host_nic_id": iface2.id,
                    },
                ],
            ],
            [vm["networks"] for vm in numa2["vms"]],
        )
 def test_get_resources_interfaces(self):
     node = factory.make_Node()
     if0 = factory.make_Interface(
         INTERFACE_TYPE.PHYSICAL,
         name="eth0",
         numa_node=node.default_numanode,
         sriov_max_vf=8,
     )
     if1 = factory.make_Interface(
         INTERFACE_TYPE.PHYSICAL,
         name="eth1",
         numa_node=factory.make_NUMANode(node=node),
         sriov_max_vf=4,
     )
     project = factory.make_string()
     pod = factory.make_Pod(
         pod_type="lxd",
         parameters={"project": project},
         host=node,
     )
     vm0 = factory.make_VirtualMachine(bmc=pod, project=project)
     for _ in range(3):
         VirtualMachineInterface.objects.create(
             vm=vm0,
             host_interface=if0,
             attachment_type=InterfaceAttachType.SRIOV,
         )
     vm1 = factory.make_VirtualMachine(bmc=pod,
                                       project=factory.make_string())
     for _ in range(2):
         VirtualMachineInterface.objects.create(
             vm=vm1,
             host_interface=if0,
             attachment_type=InterfaceAttachType.SRIOV,
         )
     vm2 = factory.make_VirtualMachine(bmc=pod)
     for _ in range(2):
         VirtualMachineInterface.objects.create(
             vm=vm2,
             host_interface=if1,
             attachment_type=InterfaceAttachType.SRIOV,
         )
     resources = get_vm_host_resources(pod)
     self.assertCountEqual(
         resources.interfaces,
         [
             VMHostNetworkInterface(
                 id=if0.id,
                 name="eth0",
                 numa_index=0,
                 virtual_functions=VMHostResource(
                     allocated_tracked=3,
                     allocated_other=2,
                     free=3,
                 ),
             ),
             VMHostNetworkInterface(
                 id=if1.id,
                 name="eth1",
                 numa_index=1,
                 virtual_functions=VMHostResource(
                     allocated_tracked=0,
                     allocated_other=2,
                     free=2,
                 ),
             ),
         ],
     )
 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],
             },
         ],
     )