Every Moler device is a state machine. The state machine tracks which shell or environment the device is currently operating in and handles all transitions between those environments automatically. Your test code just says “go to this state” — Moler figures out the sequence of commands needed to get there.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nokia/moler/llms.txt
Use this file to discover all available pages before exploring further.
Device states
States represent distinct environments on (or leading to) a device. The built-in states in the Unix device hierarchy are:| State | Meaning |
|---|---|
NOT_CONNECTED | Initial state; no connection established yet |
UNIX_LOCAL | Connected to the local shell on the test host |
PROXY_PC | On a jump host / proxy machine (optional) |
UNIX_REMOTE | SSH’d into the remote target machine |
UNIX_REMOTE_ROOT | Elevated to root on the remote machine via su |
UNIX_LOCAL_ROOT | Root on the local machine |
DeviceFactory.get_device()), Moler automatically opens the connection and drives the state machine from NOT_CONNECTED to the device’s initial state (UNIX_LOCAL for a local device, or UNIX_REMOTE if initial_state is configured that way).
CONNECTION_HOPS: defining transitions in config
The state machine’s transitions are entirely defined in the YAML configuration file underCONNECTION_HOPS. This is the key design decision in Moler: client code never knows how to reach a state — only the config file does.
Here is the RebexTestMachine config from the Moler README:
UNIX_LOCAL to UNIX_REMOTE, run the ssh command with these parameters.”
Calling goto_state()
To move the device to a target state, callgoto_state():
UNIX_LOCAL, it knows it must run the ssh command to reach UNIX_REMOTE. If the device is in NOT_CONNECTED, it knows it must first connect (reach UNIX_LOCAL) and then SSH.
Multi-hop state transitions
Moler can traverse multiple hops automatically. The internal_state_hops configuration defines intermediate states. For example, the UnixRemote device knows:
NOT_CONNECTED→UNIX_REMOTE: go viaUNIX_LOCALfirst (connect), then SSH.UNIX_REMOTE→NOT_CONNECTED: go viaPROXY_PC(orUNIX_LOCAL) first, then disconnect.
Full example: go remote, run ls, inspect result
moler.RebexTestMachine.log) records every step of the state transition:
Auto-reconnect after dropped connection
One of the most valuable properties of the state machine is automatic recovery. If the connection to a device drops unexpectedly (network blip, session timeout, etc.), Moler detects the unexpected state change and can re-drive the state machine back to the desired state. The device has atimeout_keep_state property (default: 10 seconds) that controls how long Moler waits before attempting to restore the previous state after an unexpected transition. This means that transient disconnections are handled automatically without any test code changes.
Configuring a device without a proxy
For direct SSH (no jump host), theCONNECTION_HOPS is simpler:
Configuring a device with a proxy / jump host
For environments with a jump host (proxy), add an additional hop viaPROXY_PC:
goto_state(state="UNIX_REMOTE") automatically SSH’s to the jump host first, then SSH’s from there to the target — all without any changes to test code.
The
DEVICE_CLASS field determines which state machine implementation is used. moler.device.unixremote.UnixRemote provides the full UNIX_LOCAL → PROXY_PC → UNIX_REMOTE → UNIX_REMOTE_ROOT hierarchy. moler.device.unixlocal.UnixLocal provides only NOT_CONNECTED and UNIX_LOCAL.