How to use get_manufacturer method in Airtest

Best Python code snippet using Airtest

hwcheck-no-use.py

Source: hwcheck-no-use.py Github

copy

Full Screen

12#!/​usr/​bin/​env python3import re4import sys5import time6import socket7import json8import requests9import subprocess10def execute(cmd):11 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)12 return p.communicate()13def Get_manufacturer():14 cmd= """/​usr/​sbin/​dmidecode | grep -A1 'System Information' | grep 'Manufacturer'"""15 stdout, stderr = execute(cmd)16 return stdout.split(':')[1].strip()17# 1-OK , 0-ERROR18def CheckMem(ip,timestamp,step,manufacturer=Get_manufacturer()):19 if manufacturer == 'Dell Inc.':20 cmd = "/​opt/​dell/​srvadmin/​sbin/​omreport chassis memory | grep 'Health' | awk -F ':' '{ print $2 }'" 21 elif manufacturer == 'HP':22 cmd = "hpasmcli -s 'show dimm' | grep Status | awk '{print $2}'"23 else:24 cmd = ""25 stdout, stderr = execute(cmd)26 status = '1'27 p = []28 for i in stdout.splitlines():29 if 'OK' == i.strip().upper():30 pass31 else:32 status = '0'33 item = {34 "Metric": "hw1.mem.status",35 "Endpoint": ip,36 "Timestamp": timestamp,37 "Step": step,38 "Value": int(status),39 "CounterType": "GAUGE"40 }41 item = json.dumps(item)42 p.append(item)43 return p 44def CheckPower(ip,timestamp,step,manufacturer=Get_manufacturer()):45 if manufacturer == 'Dell Inc.':46 cmd = "/​opt/​dell/​srvadmin/​sbin/​omreport chassis pwrsupplies | grep ^Status | awk '{print $3}'"47 elif manufacturer == 'HP':48 cmd = "hpasmcli -s 'show POWERSUPPLY' |grep Condition | awk '{print $2}'"49 else:50 cmd = ""51 stdout, stderr = execute(cmd)52 status = '1'53 p = []54 for i in stdout.splitlines():55 if 'OK' == i.strip().upper():56 pass57 else:58 status = '0'59 break60 item = {61 "Metric": "hw1.power.status",62 "Endpoint": ip,63 "Timestamp": timestamp,64 "Step": step,65 "Value": int(status),66 "CounterType": "GAUGE"67 }68 item = json.dumps(item)69 p.append(item)70 return p71def CheckCPU(ip,timestamp,step,manufacturer=Get_manufacturer()):72 if manufacturer == 'Dell Inc.':73 cmd = "/​opt/​dell/​srvadmin/​sbin/​omreport chassis processors | grep ^Status|awk '{print $3}'"74 elif manufacturer == 'HP':75 cmd = "hpasmcli -s 'show SERVER' | grep Status |awk '{print $3}'"76 else:77 cmd = ""78 stdout, stderr = execute(cmd)79 status = '1'80 p = []81 for i in stdout.splitlines():82 if 'OK' == i.strip().upper():83 pass84 else:85 status = '0'86 break87 item = {88 "Metric": "hw1.cpu.status",89 "Endpoint": ip,90 "Timestamp": timestamp,91 "Step": step,92 "Value": int(status),93 "CounterType": "GAUGE"94 }95 item = json.dumps(item)96 p.append(item)97 return p98def CheckCPUTemp(ip,timestamp,step,manufacturer=Get_manufacturer()):99 if manufacturer == 'Dell Inc.':100 cpu_temp = "/​opt/​dell/​srvadmin/​sbin/​omreport chassis temps | grep -A 1 CPU | grep Reading | awk -F ':' '{ print $2 }' | awk '{ print $1 }'"101 elif manufacturer == 'HP':102 cpu_temp = "hpasmcli -s 'SHOW TEMP' | grep CPU | awk '{print $3}' | cut -b 1-2"103 else:104 cpu_temp = ''105 stdout, stderr = execute(cpu_temp)106 p = []107 x = 1108 for i in stdout.splitlines():109 item = {110 "Metric": "hw1.cpu%s.temp" % x,111 "Endpoint": ip,112 "Timestamp": timestamp,113 "Step": step,114 "Value": i.split('.')[0],115 "CounterType": "GAUGE"116 }117 118 x = x+1 119 item = json.dumps(item)120 p.append(item)121 return p122def CheckDiskCtl(ip,timestamp,step,manufacturer=Get_manufacturer()):123 if manufacturer == 'Dell Inc.':124 cmd = "/​opt/​dell/​srvadmin/​sbin/​omreport storage controller | grep ^ID | awk -F':' '{ print $2 }'"125 stdout, stderr = execute(cmd)126 controller = stdout.splitlines()127 ctl_status = "/​opt/​dell/​srvadmin/​sbin/​omreport storage adisk controller=%s | grep ^Status | awk -F':' '{ print $2 }'" %controller[0].strip()128 elif manufacturer == 'HP':129 cmd = "/​opt/​hp/​hpssacli/​bld/​hpssacli ctrl all show detail | grep 'Slot:' |awk -F':' '{ print $2 }'"130 stdout, stderr = execute(cmd)131 controller = stdout.splitlines()132 ctl_status = "/​opt/​hp/​hpssacli/​bld/​hpssacli ctrl slot=%s pd all show status | grep 'Controller Status'|awk '{print $3}'" %controller[0].strip().strip()133 else:134 ctl_status = ""135 p = []136 status = '1'137 stdout, stderr = execute(ctl_status)138 for i in stdout.splitlines():139 if 'OK' == i.strip().upper():140 pass141 else:142 status = '0'143 break144 item = {145 "Metric": "hw1.ctl.status",146 "Endpoint": ip,147 "Timestamp": timestamp,148 "Step": step,149 "Value": int(status),150 "CounterType": "GAUGE"151 }152 item = json.dumps(item)153 p.append(item)154 return p155def main():156 ip = socket.gethostname()157 timestamp = int(time.time())158 step = 60159 x = []160 for i in CheckMem(ip,timestamp,step):161 x.append(i)162 for i in CheckPower(ip,timestamp,step):163 x.append(i)164 for i in CheckCPU(ip,timestamp,step):165 x.append(i)166 for i in CheckCPUTemp(ip,timestamp,step):167 x.append(i)168 for i in CheckDiskCtl(ip,timestamp,step):169 x.append(i)170 print '[%s]' % ','.join(x)171if __name__ == '__main__':172 cmd = "dmidecode | grep 'Product Name'"173 stdout, stderr = execute(cmd)174 if stdout.split(':')[1].strip() == 'KVM':175 sys.exit() ...

Full Screen

Full Screen

fetch_lib.py

Source: fetch_lib.py Github

copy

Full Screen

...7576 # Generate the help string77 help_str = ""78 for platform in parser_ports_list + device_parser_ports_list:79 help_str += "\n" + platform["common"].get_manufacturer() + ":\n\t"80 x = []81 for c in platform["specific"]:82 x.extend(c.get_ids())83 help_str += ', '.join(x)8485 args_parser = OptionParser(usage="""[options] platform [id1 ...]86Automatic data-mining from supported platforms. Supported platforms/​ids are: %s""" % (help_str))8788 env = Env(args_parser = args_parser, enable_write_db = True)8990 (options, args) = args_parser.parse_args()9192 if len(args) < 1:93 raise error("There must be at least 1 argument.")9495 # Read the platform name passed into argument96 platform_name = args[0]9798 # Read the IDs if any99 id_list = None100 if len(args) > 1:101 id_list = args[1:]102103 # Fetch the manufacturer website104 if platform_name in [x["common"].get_manufacturer() for x in parser_ports_list]:105 for x in parser_ports_list:106 if x["common"].get_manufacturer() == platform_name:107 fetch_manufacturer(env, platform_name, x["specific"], id_list = id_list)108 # Fetch the device specific website109 elif platform_name in [x["common"].get_manufacturer() for x in device_parser_ports_list]:110 for x in device_parser_ports_list:111 if x["common"].get_manufacturer() == platform_name:112 fetch_device(env, x["specific"], id_list = id_list)113 else:114 raise error("Platform unknown (%s)." % (str(platform_name)))115116 # Close the environment ...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

QA&#8217;s and Unit Testing &#8211; Can QA Create Effective Unit Tests

Unit testing is typically software testing within the developer domain. As the QA role expands in DevOps, QAOps, DesignOps, or within an Agile team, QA testers often find themselves creating unit tests. QA testers may create unit tests within the code using a specified unit testing tool, or independently using a variety of methods.

LIVE With Automation Testing For OTT Streaming Devices ????

People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.

Why Agile Is Great for Your Business

Agile project management is a great alternative to traditional methods, to address the customer’s needs and the delivery of business value from the beginning of the project. This blog describes the main benefits of Agile for both the customer and the business.

Options for Manual Test Case Development &#038; Management

The purpose of developing test cases is to ensure the application functions as expected for the customer. Test cases provide basic application documentation for every function, feature, and integrated connection. Test case development often detects defects in the design or missing requirements early in the development process. Additionally, well-written test cases provide internal documentation for all application processing. Test case development is an important part of determining software quality and keeping defects away from customers.

Test strategy and how to communicate it

I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Airtest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful