使用STAF进行自动化安装测试
2014-08-26 16:57
651 查看
首先安装STAF
在实体机和目标机器中均需要安装,STAF拥有对Python支持的库函数,可以直接调用,比较方便,所以测试脚本决定用Python来写。
需要注意的是,在/staf/bin中有一个STAF.cfg文件需要修改server和client端的trustlevel = 5.注意不同的command的trust level的要求不一样,所以在我的测试环境里面直接设定成为5比较方便。
安装之后,需要将STAF在实验机中设定为开机自启动。以便可以直接进行连接操作,不过我是使用虚拟机进行测试,只要直接载入一个开机的snapshot就可以了。
具体可以参照这个网址的开机自启动设置。
点击打开链接
这次测试环境为windows,方法是目标机要从server上面检查并且下载一个安装文件,并且执行安装。所以,windows 必须执行静默安装,并且通过STAF执行ftp命令时候需要通过载入一个conf文件来执行下载任务。
同时在Python中需要操作exsi,这个API可以直接Google到。Python真的很方便额。。。
需要注意的是在操作时候,安装和check的代码之间需要有一个sleep等待,以保证client端执行成功。
在实体机和目标机器中均需要安装,STAF拥有对Python支持的库函数,可以直接调用,比较方便,所以测试脚本决定用Python来写。
需要注意的是,在/staf/bin中有一个STAF.cfg文件需要修改server和client端的trustlevel = 5.注意不同的command的trust level的要求不一样,所以在我的测试环境里面直接设定成为5比较方便。
安装之后,需要将STAF在实验机中设定为开机自启动。以便可以直接进行连接操作,不过我是使用虚拟机进行测试,只要直接载入一个开机的snapshot就可以了。
具体可以参照这个网址的开机自启动设置。
点击打开链接
这次测试环境为windows,方法是目标机要从server上面检查并且下载一个安装文件,并且执行安装。所以,windows 必须执行静默安装,并且通过STAF执行ftp命令时候需要通过载入一个conf文件来执行下载任务。
同时在Python中需要操作exsi,这个API可以直接Google到。Python真的很方便额。。。
需要注意的是在操作时候,安装和check的代码之间需要有一个sleep等待,以保证client端执行成功。
#------------------------------------------------------------------------------- # Name: STAF_test # Purpose: Used for staf automation test. rollback a snapshot, download and # install a program from server # # Author: Levin # # Requirement: You need to install the Staf on your local machine and add your # machine's ip to the */staf/bin/STAF.cfg. And add the */staf/bin # to your python path. # # Created: 25/08/2014 # Copyright: (c) Levin 2014 # Licence: <your licence> #------------------------------------------------------------------------------- from PySTAF import * import pysphere from xml.etree import ElementTree as ET import sys from time import sleep ##-----------Prepare the variables need to use-----------------## nodeall = ET.parse('config.xml') IPnode = nodeall.find('SETTING') EXSIIP = IPnode.getchildren()[0].text UserName = IPnode.getchildren()[1].text PassWord = IPnode.getchildren()[2].text ClientIP = IPnode.getchildren()[3].text VirtualMachine = IPnode.getchildren()[4].text Snapshot = IPnode.getchildren()[5].text Pathnode = nodeall.find('WORKINGPATH') ClientPath = Pathnode.getchildren()[0].text LocalPath = Pathnode.getchildren()[1].text ##------------------installation process------------## def staf_install(): try: handle = STAFHandle("test") except STAFException, e: print "Error registering with STAF, RC: %d" % e.rc sys.exit(e.rc) while (True): result = handle.submit(ClientIP, "ping", "ping") if (result.rc == 0): break print "Error submitting request, RC: %d, Result: %s" % (result.rc, result.result) print "connected" result = handle.submit("local", "FS", "COPY File "+LocalPath+r"\ftpSample.conf TODIRECTORY "+ClientPath+" TOMACHINE "+ClientIP) if (result.rc == 0): print "Upload config file succeed!" else : print "Upload config file failed!" print "%s" % result.result sys.exit(1) result = handle.submit(ClientIP, "process", "start shell command" + "\"ftp -s:ftpSample.conf\"" + "workdir " + ClientPath) if (result.rc == 0): print "Download install file succeed!" else : print "Download install file failed!" print "%s" % result.result sys.exit(2) print "Now wait 6 seconds" sleep(6) result = handle.submit(ClientIP,"process", "start shell command" + "\"ActivePerl-5.16.3.1604-MSWin32-x86-298023.msi/qn\""+ " workdir " + ClientPath) print "Now wait 23 seconds for installation complete" sleep(23) result = handle.submit(ClientIP,"fs", "list directory " + r"C:\Perl\bin") if ("perl.exe" in result.resultObj): print "Installation succeed!" else : print "Installation failed!" sys.exit(3) ##--------------reset the exsi to clean the environment-------## def Reset_Virtualmachine(): server = pysphere.VIServer() try : server.connect(EXSIIP, UserName, PassWord) except pysphere.VIException, e : print "Can not connect to exsi. Exit now!" sys.exit(e.rc) print "Connected to EXSI" vm = server.get_vm_by_name("win2k3-R2-32bits") vm.revert_to_named_snapshot(Snapshot) if __name__ == '__main__': Reset_Virtualmachine() print "Enter to Staf install." staf_install()
相关文章推荐
- 安装和使用Karma-Jasmine进行自动化测试
- 使用Robot进行自动化测试
- 使用QTP进行非GUI的自动化测试
- 目前大家对Python都有一个共识,就是他对测试非常有用,自动化测试里Python用途也很广,但是Python到底怎么进行自动化测试呢?今天就简单的向大家介绍一下怎么使用Python进行自动化测试
- 【Android自动化测试之Robotium】03. 当只有一个APK的时候使用robotium进行自动化测试
- 使用Tcl扩展包cwind进行界面自动化测试
- 使用简单的shell脚本进行自动化测试
- 使用UIAutomation进行 iOS 自动化测试
- 使用python进行windows自动化测试
- 使用WatiN进行自动化Web界面测试
- 手工测试用例就是自动化测试脚本——使用ruby 1.9新特性进行自动化脚本的编写
- 在windows下使用cmd命令通过adb shell自动调用android模拟或真机的InstrumentRunner进行android 自动化测试
- [转]简单介绍如何使用robotium进行自动化测试
- MSDN Webcast - 使用Windows Mobile Test Framework进行自动化测试(Level 300)
- 开源的软件自动化测试框架STAF使用特色
- 使用Fitnesse进行接口自动化测试
- 安卓自动化测试工具MonkeyRunner之使用ID进行参数化,以及List选择某项和弹出框点击确定的写法
- 使用selenium进行自动化测试
- 安卓自动化测试工具MonkeyRunner之使用ID进行参数化,以及List选择某项和弹出框点击确定的写法