Best Python code snippet using autotest_python
Env.py
Source:Env.py
...141 None142 Returns:143 kernel configuration as string144 """145 k_ver = Env.get_kernel_ver()146 if k_ver is None:147 return False148 result = Utl.exe(["cat", "/boot/config-%s" %(k_ver)])149 if not result["valid"]:150 return None151 config = {}152 tokens = result["output"].split("\n")153 for token in tokens:154 token = token.strip()155 if re.search("=", token):156 name, value = token.split("=")157 config[name.strip()] = value.strip()158 if len(config) < 1:159 return None160 return config161 @staticmethod162 def get_kernel_ver():163 """get kernel version164 Args:165 None166 Returns:167 kernel version as string168 """169 return platform.release()170 @staticmethod171 def get_objdump_ver():172 """get objdump version173 Args:174 None175 Returns:176 objdump version as string177 """178 result = Utl.exe(["objdump", "--version"])179 if not result["valid"]:180 return None181 tokens = result["output"].split()182 if len(tokens) < 7:183 return None184 return tokens[6]185 @staticmethod186 def has_binutils():187 """check if binutils of supported version exists188 Args:189 None190 Returns:191 True if yes, False otherwise192 """193 ver = Env.get_binutils_ver()194 if ver is None:195 return False196 tokens = [int(i) for i in ver.split(".")[:2]]197 if tokens[0] >= 3:198 return True199 return tokens[0] >= 2 and tokens[1] >= 24200 @staticmethod201 def has_cpu_family():202 """check if supported cpu family exists203 Args:204 None205 Returns:206 True if yes, False otherwise207 """208 try:209 return int(Env.get_cpu_family()) >= 6210 except ValueError:211 return False212 @staticmethod213 def has_cpu_vendor_id():214 """check if supported cpu vendor id exists215 Args:216 None217 Returns:218 True if yes, False otherwise219 """220 vendor_id = Env.get_cpu_vendor_id()221 return vendor_id is not None and vendor_id == "GenuineIntel"222 @staticmethod223 def has_gcc():224 """check if gcc of supported version exists225 Args:226 None227 Returns:228 True if yes, False otherwise229 """230 ver = Env.get_gcc_ver()231 if ver is None:232 return False233 tokens = [int(i) for i in ver.split(".")[:1]]234 if tokens[0] >= 5:235 return True236 @staticmethod237 def has_gdb():238 """check if gdb of supported version exists239 Args:240 None241 Returns:242 True if yes, False otherwise243 """244 ver = Env.get_gdb_ver()245 if ver is None:246 return False247 tokens = [int(i) for i in ver.split(".")[:2]]248 if tokens[0] > 7:249 return True250 return tokens[0] >= 7 and tokens[1] >= 10251 @staticmethod252 def has_glibc():253 """check if glibc of supported version exists254 Args:255 None256 Returns:257 True if yes, False otherwise258 """259 ver = Env.get_glibc_ver()260 if ver is None:261 return False262 tokens = [int(i) for i in ver.split(".")[:2]]263 if tokens[0] > 2:264 return True265 return tokens[0] >= 2 and tokens[1] >= 20266 @staticmethod267 def has_kernel():268 """check if Linux kernel of supported version exists269 Args:270 None271 Returns:272 True if yes, False otherwise273 """274 ver = Env.get_kernel_ver()275 if ver is None:276 return False277 tokens = [int(i) for i in ver.split(".")[:2]]278 if tokens[0] > 4:279 return True280 return tokens[0] >= 4 and Env.has_mpx_kernel()281 @staticmethod282 def has_mpx():283 """check for mpx support in cpu and Linux kernel284 Args:285 None286 Returns:287 True if yes, False otherwise288 """...
hosts.py
Source:hosts.py
...94 arch = self.run('/bin/uname -m').stdout.rstrip()95 if re.match(r'i\d86$', arch):96 arch = 'i386'97 return arch98 def get_kernel_ver(self):99 """ Get the kernel version of the remote machine. """100 return self.run('/bin/uname -r').stdout.rstrip()101 def get_cmdline(self):102 """ Get the kernel command line of the remote machine. """103 return self.run('cat /proc/cmdline').stdout.rstrip()104 def get_meminfo(self):105 """ Get the kernel memory info (/proc/meminfo) of the remote machine106 and return a dictionary mapping the various statistics. """107 meminfo_dict = {}108 meminfo = self.run('cat /proc/meminfo').stdout.splitlines()109 for key, val in (line.split(':', 1) for line in meminfo):110 meminfo_dict[key.strip()] = val.strip()111 return meminfo_dict112 def path_exists(self, path):...
host_info_collector.py
Source:host_info_collector.py
...33 hostname_ver_str ="unkown"34 log(str(e))35 return hostname_ver_str36 37 def get_kernel_ver(self):38 """"""39 try:40 kernel_ver_list =os.popen('uname -r').read()41 42 if isinstance(kernel_ver_list,(list,)) and kernel_ver_list:43 ker_ver_str = kernel_ver_list[0].strip('\n')44 else:45 ker_ver_str = kernel_ver_list.strip('\n')46 except Exception,e:47 ker_ver_str ="unkown"48 log(str(e))49 return ker_ver_str50 51 def get_libvirt_ver(self):52 """"""53 try:54 lib_ver_list = os.popen('rpm -qa|grep libvirt').read()55 #log(type(lib_ver_list))56 if isinstance(lib_ver_list,(list,)) and lib_ver_list:57 lib_ver_str = lib_ver_list[0].strip('\n')58 else:59 lib_ver_str = lib_ver_list.strip('\n')60 except Exception,e:61 lib_ver_str ="unkown"62 log(str(e))63 return lib_ver_str64 65 def get_qemu_ver(self):66 """"""67 try:68 qemu_ver_list = os.popen('rpm -qa|grep qemu').read()69 #log(type(lib_ver_list))70 if isinstance(qemu_ver_list,(list,)) and qemu_ver_list:71 qemu_ver_str = qemu_ver_list[0].strip('\n')72 else:73 qemu_ver_str = qemu_ver_list.strip('\n')74 except Exception,e:75 qemu_ver_str ="unkown"76 log(str(e))77 return qemu_ver_str78 79 def get_disk_usage(self):80 """"""81 ret_list=[]82 disk_usage_list = exec_cmd("/bin/df -PTh")83 for index,item in enumerate(disk_usage_list):84 if item.startswith("Filesystem"):85 #filter start header86 continue87 try:88 (device,fstype,total,used,available,percentage,mount)=item.split(None)89 ret_list.append({90 "device":device,91 "fstyp":fstype,92 "total":total,93 "used":used,94 "available":available,95 "percentage":percentage,96 "mount":mount97 })98 except Exception,e:99 log(str(e))100 return ret_list101 102 def get_hardware_info(self):103 """"""104 105 return106 107class HostBasicInfo(BasicInfo):108 109 def __init__(self,router_obj):110 super(HostBasicInfo,self).__init__()111 self._router_obj = router_obj112 self._info ={}113 114 def run(self):115 116 while 1:117 try:118 interval_sec = random.randint(30,60)119 time.sleep(interval_sec)120 log("[HostBasicInfo]report interval [%s] "%str(interval_sec))121 self._compose()122 ReportInfo().run(self._info)123 except Exception,e:124 log(str(e))125 #log("dddddd")126 #return self.get_result()127 128 def _compose(self):129 130 self._info["libvirt"]=self.get_libvirt_ver()131 self._info["qemu"] = self.get_qemu_ver()132 self._info["kernel"] = self.get_kernel_ver()133 self._info["hostname"] = self.get_hostname()134 self._info["diskUsage"]=self.get_disk_usage()135 log(json.dumps(self._info))136 137 def get_result(self):138 return self._info139 140141#class ReportHostInfo():142# """"""143# def __init__(self):144# self._host_obj = HostBasicInfo()145# self._report_obj = ReportInfo()146#
...
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!!