Exemple #1
0
 def test_save_fills_in_bus_dev_num_for_pcie(self):
     bus_number = random.randint(0, 2**16)
     device_number = random.randint(0, 2**16)
     node = factory.make_Node()
     node_device = NodeDevice.objects.create(
         bus=NODE_DEVICE_BUS.PCIE,
         node=node,
         numa_node=random.choice(node.numanode_set.all()),
         vendor_id=factory.make_hex_string(size=4),
         product_id=factory.make_hex_string(size=4),
         pci_address=(f"{hex(bus_number)[2:].zfill(2)}:"
                      f"{hex(device_number)[2:].zfill(2)}.0"),
     )
     self.assertEqual(bus_number, node_device.bus_number)
     self.assertEqual(device_number, node_device.device_number)
    def test_GET_filter_vendor_id(self):
        vendor_id = factory.make_hex_string(4)
        node_devices = [
            factory.make_NodeDevice(node=self.node, vendor_id=vendor_id)
            for _ in range(3)
        ]

        response = self.client.get(self.get_script_results_uri(),
                                   {"vendor_id": vendor_id})
        self.assertThat(response, HasStatusCode(http.client.OK))
        parsed_results = json_load_bytes(response.content)

        self.assertCountEqual(
            [node_device.id for node_device in node_devices],
            [node_device["id"] for node_device in parsed_results],
        )