Best Python code snippet using lisa_python
cpusuite.py
Source:cpusuite.py
...189 # current max channel will be cpu_count - len(idle_cpus)190 # check channels of synthetic network adapter align with current setting channel191 try:192 # take idle cpu to offline193 set_cpu_state_serial(log, node, idle_cpus, CPUState.OFFLINE)194 # get vmbus channels of synthetic network adapter. the synthetic network195 # drivers have class id "f8615163-df3e-46c5-913f-f2d2f965ed0e"196 node.tools[Lsvmbus].get_device_channels(force_run=True)197 cpu_count = node.tools[Lscpu].get_core_count()198 # current max channel count need minus count of idle cpus199 max_channel_count = cpu_count - len(idle_cpus)200 # change current channel201 first_channel_count = random.randint(1, min(max_channel_count, 64))202 node.tools[Ethtool].change_device_channels_info("eth0", first_channel_count)203 # verify that the added channels do not handle interrupts on offline cpu204 lsvmbus_channels = node.tools[Lsvmbus].get_device_channels(force_run=True)205 for channel in lsvmbus_channels:206 # verify synthetic network adapter channels align with expected value207 if channel.class_id == "f8615163-df3e-46c5-913f-f2d2f965ed0e":208 log.debug(f"Network synthetic channel: {channel}")209 assert_that(channel.channel_vp_map).is_length(first_channel_count)210 # verify that devices do not handle interrupts on offline cpu211 for channel_vp in channel.channel_vp_map:212 assert_that(channel_vp.target_cpu).is_not_in(idle_cpus)213 # reset idle cpu to online214 set_cpu_state_serial(log, node, idle_cpus, CPUState.ONLINE)215 # reset max and current channel count into original ones216 # by reloading hv_netvsc driver217 node.tools[Modprobe].reload(["hv_netvsc"])218 # change the combined channels count after all cpus online219 second_channel_count = random.randint(1, min(cpu_count, 64))220 while True:221 if first_channel_count != second_channel_count:222 break223 second_channel_count = random.randint(1, min(cpu_count, 64))224 node.tools[Ethtool].change_device_channels_info(225 "eth0", second_channel_count226 )227 # verify that the network adapter channels count changed228 # into new channel count229 lsvmbus_channels = node.tools[Lsvmbus].get_device_channels(force_run=True)230 for channel in lsvmbus_channels:231 # verify that channels were added to synthetic network adapter232 if channel.class_id == "f8615163-df3e-46c5-913f-f2d2f965ed0e":233 log.debug(f"Network synthetic channel: {channel}")234 assert_that(channel.channel_vp_map).is_length(second_channel_count)235 finally:236 # reset idle cpu to online237 set_cpu_state_serial(log, node, idle_cpus, CPUState.ONLINE)238 # restore channel count into origin value239 current_device_channel = (240 node.tools[Ethtool].get_device_channels_info("eth0", True)241 ).current_channels242 if current_device_channel != origin_device_channel:243 node.tools[Ethtool].change_device_channels_info(244 "eth0", origin_device_channel245 )246 # when kernel doesn't support set vmbus channels target cpu feature, the247 # dict which stores original status is empty, nothing need to be restored....
common.py
Source:common.py
...65 all_cpu = list(range(1, cpu_count))66 # get the idle cpu by excluding in used cpu from all cpu67 idle_cpu = [str(x) for x in all_cpu if str(x) not in cpu_in_used]68 return idle_cpu69def set_cpu_state_serial(70 log: Logger, node: Node, idle_cpu: List[str], state: str71) -> None:72 for target_cpu in idle_cpu:73 log.debug(f"setting cpu{target_cpu} to {state}.")74 if state == CPUState.ONLINE:75 set_state = set_cpu_state(node, target_cpu, True)76 else:77 set_state = set_cpu_state(node, target_cpu, False)78 if not set_state:79 raise BadEnvironmentStateException(80 (81 f"Expected cpu{target_cpu} state: {state}."82 f"The test failed leaving cpu{target_cpu} in a bad state."83 ),...
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!!