-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
machine: Add a new command
dvc machine status
(#6649)
* machine: Add a new command `dvc machine status` fix#6482 1. add a new command `dvc machien status` 2. add a unit test for the cli call. 3. add a unit test for the shown result. * Update dvc/command/machine.py Co-authored-by: Saugat Pachhai <[email protected]> * Update dvc/command/machine.py Co-authored-by: Saugat Pachhai <[email protected]> * Update machine.py * Remove sensitive fields * Update dvc/machine/__init__.py Co-authored-by: Casper da Costa-Luis <[email protected]> * Update tests/func/machine/__init__.py Co-authored-by: Casper da Costa-Luis <[email protected]> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Use white list to limit shown fields Co-authored-by: Saugat Pachhai <[email protected]> Co-authored-by: Casper da Costa-Luis <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
6d96ecb
commit 966dc8a
Showing
6 changed files
with
103 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import textwrap | ||
|
||
CONFIG_TEXT = textwrap.dedent( | ||
"""\ | ||
[feature] | ||
machine = true | ||
['machine "foo"'] | ||
cloud = aws | ||
""" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import json | ||
|
||
from tpi.terraform import TerraformBackend | ||
|
||
from dvc.command.machine import CmdMachineStatus | ||
from dvc.main import main | ||
|
||
from . import CONFIG_TEXT | ||
|
||
STATUS = """{ | ||
"aws_security_group": null, | ||
"cloud": "aws", | ||
"id": "iterative-2jyhw8j9ieov6", | ||
"image": "ubuntu-bionic-18.04-amd64-server-20210818", | ||
"instance_gpu": null, | ||
"instance_hdd_size": 35, | ||
"instance_ip": "123.123.123.123", | ||
"instance_launch_time": "2021-08-25T07:13:03Z", | ||
"instance_type": "m", | ||
"name": "test-resource", | ||
"region": "us-west", | ||
"spot": false, | ||
"spot_price": -1, | ||
"ssh_name": null, | ||
"ssh_private": "-----BEGIN RSA PRIVATE KEY-----\\n", | ||
"startup_script": "IyEvYmluL2Jhc2g=", | ||
"timeouts": null | ||
}""" | ||
|
||
|
||
def test_status(tmp_dir, scm, dvc, mocker, capsys): | ||
(tmp_dir / ".dvc" / "config").write_text(CONFIG_TEXT) | ||
status = json.loads(STATUS) | ||
|
||
mocker.patch.object( | ||
TerraformBackend, "instances", autospec=True, return_value=[status] | ||
) | ||
|
||
assert main(["machine", "status", "foo"]) == 0 | ||
cap = capsys.readouterr() | ||
assert "instance_num_1:" in cap.out | ||
for key in CmdMachineStatus.SHOWN_FIELD: | ||
assert f"\t{key:20}: {status[key]}" in cap.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters