Project: Nomad (Orchestration & Management / Scheduling & Orchestration)
File: mock-driver.md

This repo includes a mock task driver in the package that implements a minimal task driver interface for development work. This driver is loaded as the other are, but only when Nomad is [not compiled with the release tag][]. ```hcl task "mocktask" { driver = "mock_driver" config { run_for = "10s" exit_code = 7 exiterrmsg = "the application crashed" } } ``` The `mock_driver` driver supports the following configuration in the job spec: `run_for` `(duration: "0s")` - The duration for which the fake task runs for. After this period the driver responds indicating the task has terminated. `signal_error` `(string: "")` - The error message the task returns if signalled. `stderrrepeatduration` `(duration: "0s")` - The duration between repeated stderr outputs. `stderrrepeat` `(number: 0)` - The number of times the `stderrstring` will be written. `stderr_string` `(string: "")` - The string that the task writes to stderr. `stdoutrepeatduration` `(string: "")` - The duration between repeated stdout outputs. `stdoutrepeat` `(number: 0)` - The number of times the `stdoutstring` will be written. `stdout_string` `(string: "")` - The string that the task writes to stdout. The driver has configurable startup and shutdown for the tasks: `exit_code` `(number: 0)` - The exit code the driver should return for the exiting task. `exiterrmsg` `(string: "")` - The error message the task returns while exiting. `exit_signal` `(number: 0)` - The signal with which the driver indicates the task has been killed. `kill_after` `(duration: "0s")` - Duration after which the driver indicates the task has exited with `SIGINT`. `pluginexitafter` `(string: "")` - Duration after which the driver indicates the plugin exited via the `WaitTask` call. `startblockfor` `(duration: "0s")` - Duration to block before returning when started. `starterrorrecoverable` `(bool: false)` - Marks whether the error returned when starting the driver is recoverable. `start_error` `(string: "")` - The error that is returned when starting the driver. The driver can present information to the client about the task as though it had networking: `driver_advertise` `(bool: false)` - Returned as `DriverNetwork.AutoAdvertise` from `Start()` `driver_ip` `(string: "")` - The address returned as the `DriverNetwork.IP` from `Start()` `driverportmap` `(string: "")` - Parse a label:number pair and return it as `DriverNetwork.PortMap` from `Start()`. ```hcl plugin "mock_driver" { fs_isolation = "none" shutdownperiodicafter = false shutdownperiodicduration = 0 } ``` `fs_isolation` `(string: "none")` - The type of file system isolation to report to the client. Must be one of `"none"`, `"chroot"`, or `"image"`. `shutdownperiodicafter` `(bool: false)` - A toggle that can be used during tests to "stop" a previously-functioning driver, allowing for testing of periodic drivers and fingerprinters. `shutdownperiodicduration` `(number: 0)` - The duration after which to stop a previously-functioning driver, in seconds. An example job that could be used for testing task `kill_timeout`: ``` job "mock" { group "group" { task "task" { driver = "mock_driver" kill_timeout = "5s" config { exit_code = 0 exiterrmsg = "error on exit" exit_signal = 9 kill_after = "3s" run_for = "30s" signal_error = "got signal" startblockfor = "1s" stdout_repeat = 1 stdoutrepeatduration = "10s" stdout_string = "hello, world!\n" } resources { cpu = 128 memory = 128 } } } } ``` This results in the following allocation events: ``` Recent Events: Time Type Description 2023-03-20T16:22:39-04:00 Restarting Task restarting in 17.426443129s 2023-03-20T16:22:39-04:00 Terminated Exit Code: 0, Signal: 9, Exit Message: "error on exit" 2023-03-20T16:22:09-04:00 Started Task started by client 2023-03-20T16:22:07-04:00 Task Setup Building Task Directory 2023-03-20T16:22:07-04:00 Received Task received by client ```