How to use scp_to_remote method in autotest

Best Python code snippet using autotest_python

tcpdump_bussiness.py

Source:tcpdump_bussiness.py Github

copy

Full Screen

...23 print '备份remote主机的文件%s%s成功'%(dir,filename)24 #在本地打开下载的文件,清空原内容并写入需要新内容25 public_control.modify_file('./data/%s'%filename,content)26 #通过scp再传输给remote主机27 tcpdump_control.scp_to_remote('./data/%s'%filename,d[0],d[1],d[2],dir)28 print '修改remote主机文件%s%s成功'%(dir,filename)29 #删除本地到文件30 subprocess.call('rm -rf ./data/%s'%filename,shell=True)31#描述:本函数实现通过路由的ssh的默认ip,用户名,密码登录后tcpdump抓取路由器WAN口的包32#输入:wan-wan接口的接口名33#输出:封包保持的文件名:/tmp/wanlog34def capture_wan_packet():35 #调用ssh的默认登录ip,用户名和密码36 d = data.ssh_user()37 tcpdump_control.tcpdump_command(d[1],d[0],d[2],'tcpdump -i eth1 -s0 -w /tmp/wanlog')38 return '/tmp/wanlog'39#描述:本函数实现通过路由的ssh的默认ip,用户名,密码登录后tcpdump抓取路由器WAN口的包40#输入:wlan-wlan接口的接口名41#输出:封包保持的文件名:/tmp/wlanlog42def capture_wlan_packet():43 #调用ssh的默认登录ip,用户名和密码44 d = data.ssh_user()45 tcpdump_control.tcpdump_command(d[1],d[0],d[2],'tcpdump -i wlan0 -s0 -w /tmp/wlanlog')46 return '/tmp/wlanlog'47###############################################48#以下是所需要抓包的测试用例的测试步骤49###############################################50#描述:#描述:测试用例100msh0287测试步骤----ping报文内容字段检查51def step_100msh0287(self):52 #修改门户认证的检查间隔为60s53 general_control.set_checkInterval(self,'60')54 general_control.apply(self)55 time.sleep(60)56 #上传tcpdump到路由器57 #调用ssh的默认登录ip,用户名和密码58 d = data.ssh_user()59 tcpdump_control.scp_to_remote('./data/BHU_tcpdump/tcpdump',d[0],d[1],d[2],'/usr/sbin/')60 tcpdump_control.scp_to_remote('./data/BHU_tcpdump/libpcap.so.1.3',d[0],d[1],d[2],'/usr/lib/')61 #ssh登录路由输入tcpdump抓包62 wanlog = capture_wan_packet()63 #将抓到的封包传输回本地pc64 tcpdump_control.scp_to_local(d[0],d[1],d[2],wanlog,'./data/')65 #打开本地下载的文件,读取文件内容66 f = open('./data/wanlog')67 log = f.read()68 f.close()69 '''#获取路由网关ID70 gw = general_control.get_gatewayId(self)71 #路由mac72 r_mac = ssh.ssh_cmd2("ifconfig eth0 | grep HWaddr | awk '{print$5}'")73 R_MAC = r_mac.upper()74 #路由版本75 r_version = ssh.ssh_cmd2('cat /etc/version/version')76 R_VERSION = r_version.upper()77 #路由无线mac78 wlan_mac = ssh.ssh_cmd2("ifconfig wlan0 | grep HWaddr | awk '{print$5}'")79 WLAN_MAC = wlan_mac.upper()'''80 #正确的心跳ping信息字符如下81 ping_str1 = 'GET /index/ping/?gw_id='82 #ping_str2 = 'route_mac=%s&route_version=%s&wlan_mac_0=%s'%(R_MAC,R_VERSION,WLAN_MAC)83 if ping_str1 in log:84 #ping信息在log信息中,说明有心跳信息,结果赋值185 result = 186 else:87 #ping信息不在log信息中,说明没有心跳信息,结果赋值088 result = 089 #结果返回给函数90 return result91#描述:#描述:测试用例100msh0286测试步骤----分区域管理路由器功能检查92def step_100msh0286(self):93 #修改请求管理接口的时间间隔为1分钟94 content = ['0 2 * * * /bin/rand_upgrade_msh\n',95 '0 4 * * * /sbin/rand_reboot\n',96 '0 6 * * * /etc/init.d/sysntpd restart\n',97 '*/1 * * * * /sbin/get_manage\n',98 '0 1 * * * /sbin/cwifi_pwd\n']99 modify_remote_file('/etc/crontabs/','root',content)100 #重启路由定时机制101 ssh.ssh_cmd2('/etc/init.d/cron restart')102 time.sleep(10)103 #上传tcpdump到路由器104 #上个用例已经上传了,这里就不再上传了105 d = data.ssh_user()106 #tcpdump_control.scp_to_remote('./data/BHU_tcpdump/tcpdump',d[0],d[1],d[2],'/usr/sbin/')107 #tcpdump_control.scp_to_remote('./data/BHU_tcpdump/libpcap.so.1.3',d[0],d[1],d[2],'/usr/lib/')108 #ssh登录路由输入tcpdump抓包109 wanlog = capture_wan_packet()110 #将抓到的封包传输回本地pc111 tcpdump_control.scp_to_local(d[0],d[1],d[2],wanlog,'./data/')112 #打开本地下载的文件,读取文件内容113 f = open('./data/wanlog')114 log = f.read()115 f.close()116 '''#获取路由网关ID117 gw = general_control.get_gatewayId(self)118 #路由mac119 r_mac = ssh.ssh_cmd2("ifconfig eth0 | grep HWaddr | awk '{print$5}'")120 R_MAC = r_mac.upper()121 #路由版本...

Full Screen

Full Screen

sync_data.py

Source:sync_data.py Github

copy

Full Screen

...10 if dry_run:11 cmd += ' --dry-run'12 print cmd13 check_call(cmd, shell=True)14def scp_to_remote(local, remote):15 cmd = 'scp -r %s %s' % (local, remote)16 check_call(cmd, shell=True)17def tar_scp_to_remote(local, remote, dry_run=False):18 tar_file = local + '.tar'19 tar_cmd = 'tar -cvf %s %s' % (tar_file, local)20 print tar_cmd21 check_call(tar_cmd, shell=True)22 scp_to_remote(tar_file, remote)23if __name__ == '__main__':...

Full Screen

Full Screen

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 autotest 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