Repository: valohai/valohai-cli

Issue:
Add support for autorestart flag

Discussion:
codecov[bot]: # [Codecov](https://codecov.io/gh/valohai/valohai-cli/pull/210?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valohai) Report
> Merging [#210](https://codecov.io/gh/valohai/valohai-cli/pull/210?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valohai) (40b57a2) into [master](https://codecov.io/gh/valohai/valohai-cli/commit/9a91dcd7c39db91621b69d7ab94262a178063557?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valohai) (9a91dcd) will **increase** coverage by `0.03%`.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff             @@
##           master     #210      +/-   ##
==========================================
+ Coverage   85.94%   85.97%   +0.03%     
==========================================
  Files         118      118              
  Lines        3842     3851       +9     
  Branches      635      636       +1     
==========================================
+ Hits         3302     3311       +9     
  Misses        377      377              
  Partials      163      163              
```


| [Impacted Files](https://codecov.io/gh/valohai/valohai-cli/pull/210?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valohai) | Coverage Δ | |
|---|---|---|
| [tests/commands/execution/test\_run.py](https://codecov.io/gh/valohai/valohai-cli/pull/210/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valohai#diff-dGVzdHMvY29tbWFuZHMvZXhlY3V0aW9uL3Rlc3RfcnVuLnB5) | `100.00% <100.00%> (ø)` | |
| [...hai\_cli/commands/execution/run/frontend\_command.py](https://codecov.io/gh/valohai/valohai-cli/pull/210/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valohai#diff-dmFsb2hhaV9jbGkvY29tbWFuZHMvZXhlY3V0aW9uL3J1bi9mcm9udGVuZF9jb21tYW5kLnB5) | `92.53% <100.00%> (+0.34%)` | :arrow_up: |

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=valohai)


Patch:
diff --git a/valohai_cli/commands/execution/run/frontend_command.py b/valohai_cli/commands/execution/run/frontend_command.py
index e6d2a44..57fa273 100644
--- a/valohai_cli/commands/execution/run/frontend_command.py
+++ b/valohai_cli/commands/execution/run/frontend_command.py
@@ -37,6 +37,7 @@ run_epilog = (
 @click.option('--yaml', default=None, help='The path to the configuration YAML (valohai.yaml) file to use.')
 @click.option('--debug-port', type=int)
 @click.option('--debug-key-file', type=click.Path(file_okay=True, readable=True, writable=False))
+@click.option('--autorestart/--no-autorestart', help='Enable Automatic Restart on Spot Instance Interruption')
 @click.argument('args', nargs=-1, type=click.UNPROCESSED, metavar='STEP-OPTIONS...')
 @click.pass_context
 def run(
@@ -57,6 +58,7 @@ def run(
     watch: bool,
     debug_port: int,
     debug_key_file: Optional[str],
+    autorestart: bool,
 ) -> Any:
     """
     Start an execution of a step.
@@ -109,6 +111,8 @@ def run(
                     f"does not seem valid (it should start with `ssh`)"
                 )
         runtime_config["debug_key"] = key
+    if autorestart:
+        runtime_config["autorestart"] = autorestart
 
     rc = RunCommand(
         project=project,


Test patch:
diff --git a/tests/commands/execution/test_run.py b/tests/commands/execution/test_run.py
index 6352b86..53f195d 100644
--- a/tests/commands/execution/test_run.py
+++ b/tests/commands/execution/test_run.py
@@ -58,6 +58,16 @@ def test_run_tags(run_test_setup):
     run_test_setup.run()
 
 
+def test_run_spot_restart(run_test_setup):
+    run_test_setup.args.append('--environment=018161d4-2911-7bbb-85ea-8820559cce89')
+    run_test_setup.values['environment'] = '018161d4-2911-7bbb-85ea-8820559cce89'
+    run_test_setup.args.append('--autorestart')
+    run_test_setup.run()
+    assert run_test_setup.run_api_mock.last_create_execution_payload["runtime_config"] == {
+        'autorestart': True
+    }
+
+
 def test_run_with_yaml_path(run_test_setup):
     run_test_setup.args.remove('train')
     # Use a step which is only present in the evaluation YAML