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
123456
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 )
[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
1234567891011121314151617181920212223242526
[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
12345678910111213141516171819
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
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.
123456
[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.
123456789
[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>