Best Python code snippet using lisa_python
power.py
Source:power.py  
...54        self, environment: Environment, log: Logger55    ) -> None:56        node = cast(RemoteNode, environment.nodes[0])57        is_distro_supported(node)58        verify_hibernation(node, log)59    @TestCaseMetadata(60        description="""61            This case is to verify vm hibernation with sriov network.62            It has the same steps with verify_hibernation_synthetic_network.63        """,64        priority=3,65        requirement=simple_requirement(66            network_interface=Sriov(),67            supported_features=[HibernationEnabled()],68        ),69    )70    def verify_hibernation_sriov_network(71        self, environment: Environment, log: Logger72    ) -> None:73        node = cast(RemoteNode, environment.nodes[0])74        is_distro_supported(node)75        verify_hibernation(node, log)76    @TestCaseMetadata(77        description="""78            This case is to verify vm time sync working after hibernation.79            Steps,80            1. Reset time using hwclock as 1 year after current date.81            2. Hibernate and resume vm.82            3. Check vm time sync correctly.83        """,84        priority=3,85        requirement=simple_requirement(86            supported_features=[HibernationEnabled()],87        ),88    )89    def verify_hibernation_time_sync(90        self, environment: Environment, log: Logger91    ) -> None:92        node = cast(RemoteNode, environment.nodes[0])93        is_distro_supported(node)94        date = node.tools[Date]95        current_date = date.current()96        newdate = current_date.replace(year=current_date.year + 1)97        hwclock = node.tools[Hwclock]98        hwclock.set_datetime(newdate)99        changed_date_before_hb = hwclock.get()100        assert_that(101            changed_date_before_hb.year - current_date.year,102            "fail to reset time",103        ).is_equal_to(1)104        verify_hibernation(node, log)105        timeout = 600106        timer = create_timer()107        while timeout > timer.elapsed(False):108            changed_date_after_hb = hwclock.get()109            if changed_date_after_hb.year == current_date.year:110                break111            time.sleep(2)112        assert_that(113            changed_date_after_hb.year,114            "after hb, timesync doesn't work",115        ).is_equal_to(current_date.year)116    @TestCaseMetadata(117        description="""118            This case is to verify hibernation with network workload.119            Steps,120            1. Run iperf3 network benchmark, make sure no issues.121            2. Hibernate and resume vm.122            3. Run iperf3 network benchmark, make sure no issues.123        """,124        priority=3,125        requirement=simple_requirement(126            min_count=2,127            supported_features=[HibernationEnabled()],128        ),129    )130    def verify_hibernation_with_network_workload(131        self, environment: Environment, log: Logger132    ) -> None:133        client_node = cast(RemoteNode, environment.nodes[0])134        is_distro_supported(client_node)135        run_network_workload(environment)136        verify_hibernation(client_node, log)137        run_network_workload(environment)138    @TestCaseMetadata(139        description="""140            This case is to verify hibernation with storage workload.141            Steps,142            1. Run fio benchmark, make sure no issues.143            2. Hibernate and resume vm.144            3. Run fio benchmark, make sure no issues.145        """,146        priority=3,147        requirement=simple_requirement(148            supported_features=[HibernationEnabled()],149        ),150    )151    def verify_hibernation_with_storage_workload(152        self, environment: Environment, log: Logger153    ) -> None:154        node = cast(RemoteNode, environment.nodes[0])155        is_distro_supported(node)156        run_storage_workload(node)157        verify_hibernation(node, log)158        run_storage_workload(node)159    @TestCaseMetadata(160        description="""161            This case is to verify hibernation with memory workload.162            Steps,163            1. Run stress-ng benchmark, make sure no issues.164            2. Hibernate and resume vm.165            3. Run stress-ng benchmark, make sure no issues.166        """,167        priority=3,168        requirement=simple_requirement(169            supported_features=[HibernationEnabled()],170        ),171    )172    def verify_hibernation_with_memory_workload(173        self, environment: Environment, log: Logger174    ) -> None:175        node = cast(RemoteNode, environment.nodes[0])176        is_distro_supported(node)177        stress_ng_tool = node.tools[StressNg]178        stress_ng_tool.launch(16, "100%", 300)179        verify_hibernation(node, log)180        stress_ng_tool.launch(16, "100%", 300)181    def after_case(self, log: Logger, **kwargs: Any) -> None:182        environment: Environment = kwargs.pop("environment")...common.py
Source:common.py  
...24        raise SkippedException(25            f"hibernation setup tool doesn't support current distro {node.os.name}, "26            f"version {node.os.information.version}"27        )28def verify_hibernation(node: RemoteNode, log: Logger) -> None:29    node_nic = node.nics30    lower_nics_before_hibernation = node_nic.get_lower_nics()31    upper_nics_before_hibernation = node_nic.get_upper_nics()32    hibernation_setup_tool = node.tools[HibernationSetup]33    entry_before_hibernation = hibernation_setup_tool.check_entry()34    exit_before_hibernation = hibernation_setup_tool.check_exit()35    received_before_hibernation = hibernation_setup_tool.check_received()36    uevent_before_hibernation = hibernation_setup_tool.check_uevent()37    startstop = node.features[StartStop]38    hibernation_setup_tool.start()39    startstop.stop(state=features.StopState.Hibernate)40    is_ready = True41    timeout = 90042    timer = create_timer()...stress.py
Source:stress.py  
...38    def verify_stress_hibernation(self, environment: Environment, log: Logger) -> None:39        node = cast(RemoteNode, environment.nodes[0])40        is_distro_supported(node)41        for _ in range(0, self._loop):42            verify_hibernation(node, log)43    def after_case(self, log: Logger, **kwargs: Any) -> None:44        environment: Environment = kwargs.pop("environment")...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!!
