mockslurm.mock_squeue
Mock of the squeue command of slurm.
The squeue -o, --format argument is supported except for the %all directive
Functions:
| Name | Description |
|---|---|
count_nodes |
Count the number of nodes requested by users in the nodelist. |
parse_squeue_format |
Convert squeue format argument (-o format) to a python format string and |
count_nodes
Count the number of nodes requested by users in the nodelist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodelist
|
str
|
Nodelist string in slurm format: comma separated list of nodes or node ranges example: "cp12,cp18", "cp[10-14],cp28" |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of nodes concerned by the nodelist |
Source code in src/mockslurm/mock_squeue.py
parse_squeue_format
Convert squeue format argument (-o format) to a python format string and list of function filling the values of the format string for each job DB row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
squeue_format_str
|
str
|
Squeue format string, eg "%.18i %.9P %.8j %.8u %.2t %.10M %.6D %R". |
required |
Warning
Does not support squeue's "%all" formatting string.
Returns:
| Type | Description |
|---|---|
tuple[str, list[str], list[Callable]]
|
python format string, and a list of callable that should be used to fill the values in the formatted string with a job DB row and job_index. |
Examples:
>>> job_DB_row = {
... "PID": -1,
... "NAME": b"jobname",
... "USER": b"bob",
... "ACCOUNT": b"bob_name",
... "PARTITION": b"",
... "RESERVATION": b"",
... "NODELIST": b"mocknode1",
... "TIME": 0,
... "START_TIME": datetime.datetime.now().timestamp(),
... "CMD": "",
... "STATE": JobState.PENDING,
... "REASON": JobReason.WaitingForScheduling,
... "EXIT_CODE": np.iinfo(np.int16).max,
... }
>>> row_idx = 0
>>> format_str, fields_header, fields_filler_fcts = parse_squeue_format("%.18i %.9P %.8j %.8u %.2t %.10M %.6D %R")
>>> squeue_output = format_str.format(*[fct(job_DB_row, row_idx) for fct in fields_filler_fcts])