Best Python code snippet using lisa_python
sriov.py
Source:sriov.py  
...615            assert_that(len(initial_pci_interrupts_by_irqs)).described_as(616                "initial irqs count should be greater than 0"617            ).is_greater_than(0)618            initial_pci_interrupts_by_cpus = (619                client_interrupt_inspector.sum_cpu_counter_by_index(620                    client_nic_info.pci_slot621                )622            )623            assert_that(len(initial_pci_interrupts_by_cpus)).described_as(624                "initial cpu count of interrupts should be equal to cpu count"625            ).is_equal_to(client_cpu_count)626            matched_server_nic_info: NicInfo627            for _, server_nic_info in vm_nics[server_node.name].items():628                if (629                    server_nic_info.ip_addr.rsplit(".", maxsplit=1)[0]630                    == client_nic_info.ip_addr.rsplit(".", maxsplit=1)[0]631                ):632                    matched_server_nic_info = server_nic_info633                    break634            assert (635                matched_server_nic_info636            ), "not found the server nic has the same subnet of"637            f" {client_nic_info.ip_addr}"638            # 3. Start iperf3 for 120 seconds with 128 threads on client node.639            client_iperf3.run_as_client(640                server_ip=matched_server_nic_info.ip_addr,641                run_time_seconds=120,642                parallel_number=128,643                client_ip=client_nic_info.ip_addr,644            )645            # 4. Get final interrupts sum per irq number on client node.646            final_pci_interrupts_by_irqs = (647                client_interrupt_inspector.sum_cpu_counter_by_irqs(648                    client_nic_info.pci_slot,649                    exclude_key_words=["pages", "cmd", "async"],650                )651            )652            assert_that(len(final_pci_interrupts_by_irqs)).described_as(653                "final irqs count should be greater than 0"654            ).is_greater_than(0)655            for init_interrupts_irq in initial_pci_interrupts_by_irqs:656                init_irq_number = list(init_interrupts_irq)[0]657                init_interrupts_value = init_interrupts_irq[init_irq_number]658                for final_interrupts in final_pci_interrupts_by_irqs:659                    final_irq_number = list(final_interrupts)[0]660                    final_interrupts_value = final_interrupts[final_irq_number]661                    if init_irq_number == final_irq_number:662                        break663                # 5. Compare interrupts changes, expected to see interrupts increased.664                assert_that(final_interrupts_value).described_as(665                    f"irq {init_irq_number} didn't have an increased interrupts count"666                    " after iperf3 run!"667                ).is_greater_than(init_interrupts_value)668            # 6. Get final interrupts sum per cpu on client node.669            final_pci_interrupts_by_cpus = (670                client_interrupt_inspector.sum_cpu_counter_by_index(671                    client_nic_info.pci_slot672                )673            )674            assert_that(len(final_pci_interrupts_by_cpus)).described_as(675                "final cpu count of interrupts should be equal to cpu count"676            ).is_equal_to(client_cpu_count)677            unused_cpu = 0678            for cpu, init_interrupts_value in initial_pci_interrupts_by_cpus.items():679                final_interrupts_value = final_pci_interrupts_by_cpus[cpu]680                # 7. Collect cpus which don't have interrupts count increased.681                if final_interrupts_value == init_interrupts_value:682                    unused_cpu += 1683            # 8. Compare interrupts count changes, expected half of cpus' interrupts684            #    increased....interrupt_inspector.py
Source:interrupt_inspector.py  
...94        ]95        for interrupt in matched_interrupts:96            interrupts_sum_by_irqs.append({interrupt.irq_number: interrupt.counter_sum})97        return interrupts_sum_by_irqs98    def sum_cpu_counter_by_index(self, pci_slot: str) -> Dict[int, int]:99        interrupts_sum_by_cpus: Dict[int, int] = {}100        interrupts = self.get_interrupt_data()101        matched_interrupts = [x for x in interrupts if pci_slot in x.metadata]102        for cpu_index in range(0, len(matched_interrupts[0].cpu_counter)):103            interrupts_sum_by_cpus[cpu_index] = self._get_sum_of_interrupt_data_per_cpu(104                matched_interrupts, cpu_index105            )106        return interrupts_sum_by_cpus107    def _get_sum_of_interrupt_data_per_cpu(108        self, interrupts: List[Interrupt], index: int109    ) -> int:110        sum = 0111        for interrupt in interrupts:112            sum += interrupt.cpu_counter[index]...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
