Article
STAF start guide
STAF(Software Testing Automation Framework) 是用来构建自动化测试的框架,用来部署测试环境。包括跨平台自动化部署的各种组件:config、process、handle、fs、log、monitor、queue、var、security等各种服务,还可以轻松的扩展。机器通过STAFProc启动的端口来进行通讯(set、query等)。
STAF的作用实际上就是提供了机器之间的通信通道并提供基于这个通道的基础服务。
# 安装
直接用 InstallAnywhere(IA) 的方式安装。文档介绍了整个安装过程中做的所有事情,非常非常的详细。下面针对Linux的安装配置步骤:
- 安装配置项(选项),三种方式选一种: 交互方式 文件方式 默认值
- 环境变量:使用InstallAnywhere的方式会把环境变量配置好,文档中介绍了使用的环境变量。
- 启动:shell脚本、开机启动(centos7的服务配置可以参考文档的[Fedora 15 and later]部分)
#安装(默认值)
./STAF3426-setup-linux-amd64-NoJVM.bin -i silent -DACCEPT_LICENSE=1
#启动
su -
/usr/local/staf/bin/STAFProc
或者
./startSTAFProc.sh
#测试
[root@cdb1 staf]# staf local ping ping
Response
--------
PONG
[root@cdb1 staf]# staf local process start command ifconfig
Response
--------
5
#staf远程控制 产生的输出是在运行的机器上的!
[root@cdb1 staf]# less nohup.out
Machine : cdb1
Machine nickname : cdb1
Startup time : 20171006-08:50:55
STAFProc version 3.4.26 initialized
ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.193.101 netmask 255.255.192.0 broadcast 192.168.255.255
inet6 fe80::932a:7b98:cc20:f791 prefixlen 64 scopeid 0x20<link>
inet6 fe80::9ba3:ce9e:cc9c:477d prefixlen 64 scopeid 0x20<link>
inet6 fe80::7d8c:b318:d441:70b2 prefixlen 64 scopeid 0x20<link>
ether 00:50:56:92:26:93 txqueuelen 1000 (Ethernet)
RX packets 11020400 bytes 3439058707 (3.2 GiB)
RX errors 0 dropped 717 overruns 0 frame 0
TX packets 9067587 bytes 3110097659 (2.8 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 70483 bytes 10164575 (9.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 70483 bytes 10164575 (9.6 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
#多机测试
[root@cdb2 staf]# vi bin/STAF.cfg
trust machine 192.168.193.101 level 5
[root@cdb1 staf]# staf cdb2 ping ping
[root@cdb1 staf]# staf cdb2 process start command ifconfig
[root@cdb2 staf]# less nohup.out
#安全退出
STAF local SHUTDOWN SHUTDOWN
C:\STAF\bin\STAF.exe local SHUTDOWN SHUTDOWN
# Getting Started
http://staf.sourceforge.net/current/STAFGS.pdf
STAFGS 对所有的知识点都做了简单的介绍和归纳。更详细的需要看 User Guide 文档。
STAF is an Open Source automation framework designed around the idea of reusable components. It is intended to make it easier to create automated testcases and workloads. STAF can help you increase the efficiency, productivity, and quality of your testing by improving your level of automation and reuse in your individual testcases as well as your overall test environment.
STAF operates in a peer-to-peer environment; in other words, there is no client-server hierarchy among machines running STAF.
# Basic STAF Concepts
STAF Instances Since multiple instances of STAF can be run at the same time on the same system, a STAF Instance name is used to specify a name for each STAF instance. You specify the instance name to be used by setting the environment variable STAF_INSTANCE_NAME. The default instance name is “STAF”.
A basic description of each level follows
Level 0 - No access
Level 1 - Restricted access. Only PING and helps available.
Level 2 - Limited access. Only query/view facilities available.
Level 3 - Standard access. Non-destructive updates allowed, e.g., logging.
Level 4 - Advanced access. Update abilities, e.g., copying files, deleting log files.
Level 5 - All access, e.g., SHUTDOWN, Process invocation, Trust definition manipulation
STAF requests submitted from the command line are generally used to query information from STAF services.
# STAF Commands
You can also start STAFProc by simply typing STAFProc at a command prompt window. ( /usr/local/staf/bin is in your PATH )
STAF <Endpoint>/[<Interface>://]<System Identifier>[@<Port>] <Service> <Request>
[root@cdb1 staf]# staf local ping ping
Response
--------
PONG
#没运行
[root@cdb1 staf]# staf cdb2 ping ping
Error submitting request, RC: 16
Additional info
---------------
STAFConnectionProviderConnect: Error performing test read on connected endpoint: recv() RC=111: 22, Endpoint: ssl://cdb2
[root@cdb1 staf]# staf cdb2 ping ping
Response
--------
PONG
[root@cdb1 staf]# staf local service help
Response
--------
*** SERVICE Service Help ***
LIST [ SERVICES | SERVICELOADERS | AUTHENTICATORS |
REQUESTS <[PENDING] [COMPLETE] [LONG]> | [SUMMARY] ]
QUERY SERVICE <Service Name> | SERVICELOADER <ServiceLoader Name> |
AUTHENTICATOR <Authenticator Name> | REQUEST <Request Number>
ADD SERVICE <Service Name> LIBRARY <Library Name>
[EXECUTE <Executable>] [OPTION <Name[=Value]>]...
[PARMS <Parameters>]
REMOVE SERVICE <Service Name>
FREE REQUEST <Request Number> [FORCE]
HELP
[root@cdb1 staf]# staf local shutdown help
Response
--------
*** SHUTDOWN Service Help ***
SHUTDOWN
NOTIFY REGISTER [MACHINE <Machine>] [HANDLE <Handle> | NAME <Name>]
[PRIORITY <Priority>]
NOTIFY UNREGISTER [MACHINE <Machine>] [HANDLE <Handle> | NAME <Name>]
[PRIORITY <Priority>]
NOTIFY LIST
HELP
>>>> The information returned by Help show us the options we can place after "STAF local shutdown ....."
in command requests
[root@cdb1 staf]# staf local service list
Response
--------
Name Library Executable
--------- ---------- ----------
CONFIG <Internal> <None>
DELAY <Internal> <None>
DIAG <Internal> <None>
ECHO <Internal> <None>
FS <Internal> <None>
HANDLE <Internal> <None>
HELP <Internal> <None>
LIFECYCLE <Internal> <None>
MISC <Internal> <None>
PING <Internal> <None>
PROCESS <Internal> <None>
QUEUE <Internal> <None>
SEM <Internal> <None>
SERVICE <Internal> <None>
SHUTDOWN <Internal> <None>
TRACE <Internal> <None>
TRUST <Internal> <None>
VAR <Internal> <None>
[root@cdb1 staf]# staf local var list
Response
--------
STAF/Config/BootDrive : /
STAF/Config/CodePage : UTF-8
STAF/Config/ConfigFile : /usr/local/staf/bin/STAF.cfg
STAF/Config/DefaultAuthenticator : none
STAF/Config/DefaultInterface : ssl
STAF/Config/InstanceName : STAF
STAF/Config/Machine : cdb1
STAF/Config/MachineNickname : cdb1
STAF/Config/Mem/Physical/Bytes : 3974971392
STAF/Config/Mem/Physical/KB : 3881808
STAF/Config/Mem/Physical/MB : 3790
STAF/Config/OS/MajorVersion : 3.10.0-693.el7.x86_64
STAF/Config/OS/MinorVersion : #1 SMP Tue Aug 22 21:09:27 UTC 2017
STAF/Config/OS/Name : Linux
STAF/Config/OS/Revision : x86_64
STAF/Config/Processor/NumAvail : 4
STAF/Config/Sep/Command : ;
STAF/Config/Sep/File : /
STAF/Config/Sep/Line :
STAF/Config/Sep/Path : :
STAF/Config/STAFRoot : /usr/local/staf
STAF/Config/StartupTime : 20171006-10:33:42
STAF/DataDir : /usr/local/staf/data/STAF
STAF/Env/_ : /usr/bin/nohup
STAF/Env/CLASSPATH : /usr/local/staf/lib/JSTAF.jar:/usr/local/staf/samples/demo/STAFDemo.jar:/usr/local/staf/samples/demo/STAFDemo.jar:/usr/local/staf/lib/JSTAF.jar:
STAF/Env/HISTCONTROL : ignoredups
STAF/Env/HISTSIZE : 1000
STAF/Env/HOME : /root
STAF/Env/HOSTNAME : cdb1
STAF/Env/JAVA_HOME : /usr/local/jdk
STAF/Env/LANG : en_US.UTF-8
STAF/Env/LD_LIBRARY_PATH : /usr/local/staf/lib:/usr/local/staf/lib:
STAF/Env/LESSOPEN : ||/usr/bin/lesspipe.sh %s
STAF/Env/LOGNAME : root
STAF/Env/LS_COLORS : rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:
STAF/Env/MAIL : /var/spool/mail/root
STAF/Env/PATH : /usr/local/staf/bin:/usr/local/staf/bin:/usr/local/jdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
STAF/Env/PWD : /usr/local/staf
STAF/Env/SELINUX_LEVEL_REQUESTED :
STAF/Env/SELINUX_ROLE_REQUESTED :
STAF/Env/SELINUX_USE_CURRENT_RANGE:
STAF/Env/SHELL : /bin/bash
STAF/Env/SHLVL : 2
STAF/Env/SSH_AUTH_SOCK : /tmp/ssh-yEmD907zdB/agent.28259
STAF/Env/SSH_CLIENT : 192.168.193.10 34774 22
STAF/Env/SSH_CONNECTION : 192.168.193.10 34774 192.168.193.101 22
STAF/Env/SSH_TTY : /dev/pts/2
STAF/Env/STAF_INSTANCE_NAME : STAF
STAF/Env/STAFCONVDIR : /usr/local/staf/codepage
STAF/Env/TERM : vt100
STAF/Env/USER : root
STAF/Env/XDG_DATA_DIRS : /root/.local/share/flatpak/exports/share/:/var/lib/flatpak/exports/share/:/usr/local/share/:/usr/share/
STAF/Env/XDG_RUNTIME_DIR : /run/user/0
STAF/Env/XDG_SESSION_ID : 2080
STAF/Version : 3.4.26
>>>> STAF predefines many useful variables, including information about the machine's Operating System
and File/Line/Path separators.
[root@cdb1 staf]# staf local var resolve system string {STAF/Config/Sep/File}
Response
--------
/
[root@cdb1 staf]# staf local handle list handles
Response
--------
Handle Handle Name State Last Used Date-Time
------ ------------------------------- ---------- -------------------
1 STAF_Process InProcess 20171006-10:33:42
2 STAF/Service/STAFServiceLoader1 InProcess 20171006-10:33:42
11 STAF/Client Registered 20171006-10:41:39
>>>> handle 1 is assigned to STAFProc. Each of the STAF/Client requests represent each
of the three "STAF local handle list handles" commands you submitted. Note that each request is assigned a new handle
number, and that the previous handles have been deleted
# Configuring STAF
[root@cdb1 staf]# staf local log log machine logname log1 level info message test-message
Response
--------
[root@cdb1 staf]# staf local log list machines
Response
--------
cdb1
[root@cdb1 staf]# staf local log query machine cdb1 logname log1
Response
--------
Date-Time Level Message
----------------- ----- ------------
20171006-10:54:33 Info test-message
#配置
[root@cdb1 staf]# echo "MACHINENICKNAME cdb1.dev" >>bin/STAF.cfg
[root@cdb1 staf]# staf local shutdown shutdown
[root@cdb1 staf]# ./startSTAFProc.sh
[root@cdb1 staf]# staf local log log machine logname log3 level info message test-message
Response
--------
[root@cdb1 staf]# staf local log list machines
Response
--------
cdb1
cdb1.dev
[root@cdb1 staf]# staf local log query machine cdb1.dev logname log3
Response
--------
Date-Time Level Message
----------------- ----- ------------
20171006-10:57:59 Info test-message
>>>> This primarily effects the data stored by
services such as the Log and Monitor services, which store data based on the machine from which it came by using the
STAF/Config/MachineNickname system variable as part of the directory path when creating logs and monitor data. By
allowing the STAF/Config/MachineNickname system variable to be overridden, it allows you to better manage your
data.
Note that the machine nickname is not used to communicate with other systems and does not have any effect on trust.
#配置
echo "SET DATADIR /data" >>bin/STAF.cfg
...
SET SYSTEM VAR Test/TestABC=websphere
SET SYSTEM VAR Test/TestXYZ=150
restart STAFProc and from a command prompt, try the STAF local var list command
TRUST LEVEL 2 DEFAULT
TRUST LEVEL 5 MACHINE 192.168.193.*
TRUST LEVEL 4 MACHINE tcp://9.3.41.*
TRUST LEVEL 5 MACHINE tcP://9.41.53.147
[root@cdb1 staf]# staf local trust list
Response
--------
Type Entry Trust Level
------- ----------------- -----------
Default <None> 2
Machine *://192.168.193.* 5
Machine local://local 5
Machine tcp://9.3.41.* 4
Machine tcP://9.41.53.147 5
# Using the Help Service
[root@cdb1 staf]# staf local help help
Response
--------
*** HELP Service Help ***
REGISTER SERVICE <Name> ERROR <Number> INFO <String> DESCRIPTION <String>
UNREGISTER SERVICE <Name> ERROR <Number>
[SERVICE <Name>] ERROR <Number>
LIST SERVICES | [SERVICE <Name>] ERRORS
HELP
#错误码详情
[root@cdb1 staf]# staf local error list
Error submitting request, RC: 2
Additional info
---------------
error
[root@cdb1 staf]# staf local help error 2
Response
--------
Description: Unknown service
Details : You have tried to submit a request to a service that is unknown to STAFProc. Verify that you have correctly registered the service.
# Registering STAF Services
http://staf.sourceforge.net/getservices.php 下载EventV315.tar
[root@cdb1 staf]# tar xf EventV315.tar
[root@cdb1 staf]# vi bin/STAF.cfg
...
service Event library JSTAF execute /usr/local/staf/event/STAFEvent.jar
[root@cdb1 staf]# staf local shutdown shutdown
[root@cdb1 staf]# ./startSTAFProc.sh
[root@cdb1 staf]# staf local service list
Response
--------
Name Library Executable
--------- ---------- -----------------------------------
...
EVENT JSTAF /usr/local/staf/event/STAFEvent.jar
...
#帮助文档: http://staf.sourceforge.net/current/event.htm
# STAF Demo(** 前提得安装上面的EVENT,并且STAFProc也得在图形界面Terminal启动!! **)
- each machine must give the other machine a TRUST level of 5
- samples\demo\STAFDemo.jar在CLASSPATH里面.
- java STAFDemoController是图形界面程序!!
- 弹出的窗口【An Arbitrary Process:Handle X】的标题(界面没看到的话,可能是被遮住了)。
** However, the STAFProcess window should be displayed on your remote machine。**
具体的代码解析查阅【8.2. STAF Demo Code - Leveraging STAF】这个章节。
# User’s Guide
# STAX Getting Started
http://staf.sourceforge.net/current/staxgs.pdf
Verify that the CLASSPATH environment variable contains the JSTAF.jar file. JSTAF.jar contains the STAF Java APIs to communicate with STAF from Java programs and is required to register STAF services written in Java.
[root@cdb1 staf]# tar xf ~/STAXV3517.tar
[root@cdb1 staf]# vi bin/STAF.cfg
...
SERVICE STAX LIBRARY JSTAF EXECUTE {STAF/Config/STAFRoot}/stax/STAX.jar OPTION J2=-Xmx2048m
SERVICE EVENT LIBRARY JSTAF EXECUTE {STAF/Config/STAFRoot}/stax/STAFEvent.jar
SET MAXQUEUESIZE 10000
If you do not want to include the JVM bin directory in your PATH, then you can use the “OPTION JVM=xxx” to specify which Java executable to use for the services.
[root@cdb1 staf]# staf local stax version
Response
--------
3.5.17
[root@cdb1 staf]# staf local stax version jython
Response
--------
2.5.2-staf-v1
[root@cdb1 staf]#
Errors that occur when running the STAX service will be stored in its JVM log. This log is data/STAF/lang/java/jvm/STAFJVM1/JVMLog.1 in your root STAF directory
source /etc/profile
cd stax
java -jar STAXMon.jar
>>>> You use script elements within your STAX jobs to define Python variables and execute Python code. However, also note that in most cases, all of
the element content and element attributes in your STAX jobs will also be evaluated as Python code.
<script>testName = 'CoolTest1'</script>
<testcase name="testName">
<testcase name="'%s Part A' % testName">
<testcase name="'%s Part A on machine %s' % (testName, machineName)">
#DoesNothing.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "stax.dtd">
<stax>
<defaultcall function="main"/>
<function name="main">
<nop/>
</function>
</stax>
#generate dtd for xml editor
set STAF_QUIET_MODE=1 (or if on Unix: export STAF_QUIET_MODE=1)
STAF local STAX GET DTD > stax.dtd
set STAF_QUIET_MODE= (or if on Unix: unset STAF_QUIET_MODE)
#RunNotepadProcess.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "stax.dtd">
<stax>
<defaultcall function="main"/>
<function name="main">
<process>
<location>'local'</location>
<command>'notepad'</command>
</process>
</function>
</stax>
结束任务,打开的程序也会被kill掉!!!
–END
Related
Related posts
-
基于对象存储的 Spark 数据读写实战:从末尾追加到任意更新
2025-10-28
-
心流iFlow:超越 CLI,研究更出彩,成果更惊艳
2025-09-06
-
sed debug: sedsed
2017-11-20
-
命令行调用Jenkins2.63打包
2017-08-30