标签:ati odi cat something wrong cached login 内容 程序
示例:Check status on Linux OS
# -*- coding: utf-8 -*- import re from SSHLibrary import SSHLibrary class LibraryCheckLinuxOS: """This is an example for creating a library .""" ROBOT_LIBRARY_SCOPE = ‘TEST SUITE‘ #测试库的范围 __version__ = ‘0.1‘ #声明测试库的版本 def creat_ssh_connection(self,ipaddress,port,user,login): ‘‘‘ 根据输入的IP、端口、用户名及密码,建立相应的SSH连接. Example : | creat ssh connection | 10.68.75.111 | 22 | mcadmin | testsc | ‘‘‘ self.mc = SSHLibrary() self.mc.open_connection(ipaddress,port) self.mc.login(user,login) def check_disk(self,quota=80): ‘‘‘ 检查磁盘的空间是否满足特定的要求。默认已使用空间要求小于80%. Example : | check disk | 80 | ‘‘‘ self.mc.start_command("df -h") diskstatus = self.mc.read_command_output() match_one = re.findall(r"\d+\%",diskstatus,re.M) match_two = ‘ ‘.join(match_one) matchobj = re.findall(r"\d+",match_two) if int(max(matchobj)) < int(quota): print "The disk status is OK !" else: raise UserWarning("There‘s something wrong with your disk.") def check_rpm(self,rpmname): ‘‘‘ 检查特定的安装包是否安装. Example: | check rpm | name | ‘‘‘ self.mc.start_command("rpm -qa|grep %s" % rpmname) checkstatus = self.mc.read_command_output() if checkstatus == rpmname: print "The %s is installed !" % rpmname else: raise UserWarning("There‘s something wrong with your rpm.") def check_service(self,servicename): ‘‘‘ 检查特定服务的状态. Example: | check service | name | ‘‘‘ self.mc.start_command("service %s status" % servicename) checkstatus = self.mc.read_command_output() match = re.findall(r"running",checkstatus,re.M) if len(match) > 0: print "The service status is OK !" else: raise UserWarning("The service status is not running.") def check_process(self,processname): ‘‘‘ 检查特定进程的状态. Example: | check process | name | ‘‘‘ self.mc.start_command("ps -ef | grep %s" % processname) checkstatus = self.mc.read_command_output() match = re.findall(r"%s" % processname,checkstatus,re.M) if len(match) >= 2 : print "The process status is OK !" else: raise UserWarning("The %s is not running." % processname) def check_memory(self,value=80): ‘‘‘ 检查内存的使用状态. Example: | check memory | value | ‘‘‘ self.mc.start_command("free -m") checkstatus = self.mc.read_command_output() match = re.findall(r"\d+",checkstatus,re.M) quota =(float(match[1])/float(match[0]))*100 if int(quota) <= int(value): print "The memory is OK !" else: raise UserWarning("Please check the status of memory" ) ##from SSHLibrary import SSHLibrary ## ## def check_memory(self,ipaddress,user,login): ## mc = SSHLibrary() ## mc.open_connection(ipaddress) ## mc.login(user,login) ## mc.start_command(‘free -m‘) ## return mc.read_command_output() ##class LibraryCheckLinuxOS: ## ## ROBOT_LIBRARY_SCOPE = ‘TEST SUITE‘ #测试库的范围 ## __version__ = ‘0.1‘ #声明测试库的版本 ## ## def creat_ssh_connection(self,ipaddress,port,user,login): ## self.mc = SSHLibrary() ## self.mc.open_connection(ipaddress,port) ## self.mc.login(user,login) ## ## def check_loadavg(self): ## self.mc.start_command(‘cat /proc/loadavg‘) ## print self.mc.read_command_output() ## ## def check_memory(self): ## self.mc.start_command(‘free -m‘) ## print self.mc.read_command_output() ## ## def check_disk(self): ## self.mc.start_command(‘df -h‘) ## print self.mc.read_command_output() ## 检查Linux OS的磁盘空间 ## $ df -h ## Filesystem Size Used Avail Use% Mounted on ## /dev/mapper/VG00-sysimg ## 19G 2.7G 16G 15% / ## /dev/sda1 99M 19M 75M 21% /boot ## tmpfs 2.0G 20K 2.0G 1% /dev/shm ## /dev/mapper/vg01-mmsc_var ## 35G 435M 33G 2% /var/mnt/mmsc_var ## /dev/mapper/vg03-ldap ## 985M 114M 821M 13% /var/mnt/local/ldap ## /dev/mapper/vg02-clusterlvol.001 ## 2.0G 37M 1.8G 2% /var/mnt/cluster_lvol ## 检查Linux OS的内存状态 ## $ free -m ## total used free shared buffers cached ## Mem: 3949 1911 2037 0 336 1245 ## -/+ buffers/cache: 329 3619 ## Swap: 0 0 0 ## 检查Linux OS是否安装了特定的程序包 ## $ rpm -qa |grep SS_MMSC-5.0.6 ## SS_MMSC-5.0.6-30 ## 检查Linux OS特定进程的状态 ## # ps -ef |grep xkrmanmx ## mcadmin 19215 19200 1 11:16 ? 00:00:05 xkrmanmx ## root 21723 17643 0 11:24 pts/0 00:00:00 grep xkrmanmx
实现如下功能:
标签:ati odi cat something wrong cached login 内容 程序
原文地址:https://www.cnblogs.com/anliven/p/10010299.html