Automation and testing
Run your first scenario
Create automation-demo/data.xml with the following recording. The communities public and private are sample values for a local test. The recording contains a description and one interface status object.
<?xml version="1.0" encoding="UTF-8"?>
<SnmpSimulatorData sysUpTimeOffset="0">
<Instances interval="1" readCommunity="public"
writeCommunity="private">
<Instance oid=".1.3.6.1.2.1.1.1.0" valueType="OctetString">
<Value><![CDATA[Release 1 demonstration]]></Value>
</Instance>
<Instance oid=".1.3.6.1.2.1.2.2.1.8.1" valueType="Integer">
<Value><![CDATA[1]]></Value>
</Instance>
</Instances>
</SnmpSimulatorData>
Create automation-demo/lab.prj. File references in a local project are resolved relative to that project file. The local scenario runner assigns agent-0 to the first agent, agent-1 to the second, and so on.
<?xml version="1.0" encoding="UTF-8"?>
<Networks name="Release 1 demonstration">
<Simulator name="Router" ipAddress="127.0.0.1"
port="1161" initialState="up">
<dataFile name="data.xml"/>
</Simulator>
</Networks>
Create automation-demo/scenario.json. It starts the agent, changes ifOperStatus to down after one second, introduces a one-second outage, and restores the recorded value. Times and durations are in milliseconds.
{
"schemaVersion": 1,
"name": "outage-and-recovery",
"seed": "42",
"durationMs": 6000,
"actions": [
{"id":"start", "atMs":0, "kind":"start",
"agentIds":["agent-0"]},
{"id":"interface-down", "atMs":1000,
"kind":"applyOverrides", "agentIds":["agent-0"],
"values":[{"oid":".1.3.6.1.2.1.2.2.1.8.1",
"type":"Integer", "value":"2"}]},
{"id":"outage", "atMs":2000, "kind":"applyFault",
"agentIds":["agent-0"],
"fault":{"id":"temporary-outage", "kind":"outage",
"durationMs":1000}},
{"id":"recover", "atMs":4000, "kind":"clearOverrides",
"agentIds":["agent-0"]}
],
"assertions": []
}
Run the scenario. Replace /path/to/license.dat or C:\private\license.dat. Use the same workspace only after the previous process has exited.
macOS/Linux
java -cp "lib/*:classpath/*" \
com.ireasoning.simulator.cli.SimulatorMain run \
--workspace automation-demo/run-workspace \
--license-file /path/to/license.dat \
--project automation-demo/lab.prj \
--scenario automation-demo/scenario.json \
--report-dir automation-demo/reports
Windows PowerShell
java -cp "lib/*;classpath/*" `
com.ireasoning.simulator.cli.SimulatorMain run `
--workspace automation-demo/run-workspace `
--license-file C:\private\license.dat `
--project automation-demo/lab.prj `
--scenario automation-demo/scenario.json `
--report-dir automation-demo/reports
The runner resets the lab before execution and stops its agents when the scenario finishes. It writes report.json and report.xml, a JUnit report, to the report directory. The first example has no assertions: success means the scenario completed without a reported operational failure. It does not prove that an SNMP manager detected the outage.
To observe the changes, configure your SNMP manager to poll 127.0.0.1:1161 using SNMPv2c and the public community. Query .1.3.6.1.2.1.2.2.1.8.1 frequently enough to see the short phases. Expect value 1 initially, value 2 after one second, no responses during the outage, value 2 after the outage, and value 1 after recovery. Allow for request timing and manager retries.
For a traffic check, replace the empty assertions array with the example below. Start the external poller before running the scenario and keep it polling throughout. The simulator observes traffic but does not create the manager requests for you.
"assertions": [
{"kind":"requestCount", "agentId":"agent-0",
"oid":".1.3.6.1.2.1.2.2.1.8.1",
"fromMs":0, "toMs":2000, "min":1},
{"kind":"outagePacketCount", "agentId":"agent-0",
"fromMs":2000, "toMs":3000, "min":1},
{"kind":"requestCount", "agentId":"agent-0",
"fromMs":4000, "toMs":6000, "min":1}
]
Exit code | Meaning |
0 | The run passed. |
1 | An assertion failed. |
2 | Setup, execution, or evidence was incomplete or failed. |
130 | The run was cancelled or interrupted. |
In a shell, inspect $? immediately after the command. In PowerShell, inspect $LASTEXITCODE. Check the report state as well as the exit code when integrating with a test pipeline.