mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-07 23:09:21 +01:00
* 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>
119 lines
3.1 KiB
Python
119 lines
3.1 KiB
Python
import configobj
|
|
|
|
from dvc.cli import parse_args
|
|
from dvc.command.machine import (
|
|
CmdMachineAdd,
|
|
CmdMachineCreate,
|
|
CmdMachineDestroy,
|
|
CmdMachineList,
|
|
CmdMachineModify,
|
|
CmdMachineRemove,
|
|
CmdMachineSsh,
|
|
CmdMachineStatus,
|
|
)
|
|
|
|
DATA = {
|
|
".dvc": {
|
|
"config": (
|
|
"[feature]\n"
|
|
" machine = true\n"
|
|
"['machine \"foo\"']\n"
|
|
" cloud = aws"
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
def test_add(tmp_dir):
|
|
tmp_dir.gen({".dvc": {"config": "[feature]\n machine = true"}})
|
|
cli_args = parse_args(["machine", "add", "foo", "aws"])
|
|
assert cli_args.func == CmdMachineAdd
|
|
cmd = cli_args.func(cli_args)
|
|
assert cmd.run() == 0
|
|
config = configobj.ConfigObj(str(tmp_dir / ".dvc" / "config"))
|
|
assert config['machine "foo"']["cloud"] == "aws"
|
|
|
|
|
|
def test_remove(tmp_dir):
|
|
tmp_dir.gen(DATA)
|
|
cli_args = parse_args(["machine", "remove", "foo"])
|
|
assert cli_args.func == CmdMachineRemove
|
|
cmd = cli_args.func(cli_args)
|
|
assert cmd.run() == 0
|
|
config = configobj.ConfigObj(str(tmp_dir / ".dvc" / "config"))
|
|
assert list(config.keys()) == ["feature"]
|
|
|
|
|
|
def test_create(tmp_dir, dvc, mocker):
|
|
cli_args = parse_args(["machine", "create", "foo"])
|
|
assert cli_args.func == CmdMachineCreate
|
|
|
|
cmd = cli_args.func(cli_args)
|
|
m = mocker.patch.object(
|
|
cmd.repo.machine, "create", autospec=True, return_value=0
|
|
)
|
|
|
|
assert cmd.run() == 0
|
|
m.assert_called_once_with("foo")
|
|
|
|
|
|
def test_status(tmp_dir, dvc, mocker):
|
|
cli_args = parse_args(["machine", "status", "foo"])
|
|
assert cli_args.func == CmdMachineStatus
|
|
|
|
cmd = cli_args.func(cli_args)
|
|
m = mocker.patch.object(
|
|
cmd.repo.machine, "status", autospec=True, return_value=[]
|
|
)
|
|
|
|
assert cmd.run() == 0
|
|
m.assert_called_once_with("foo")
|
|
|
|
|
|
def test_destroy(tmp_dir, dvc, mocker):
|
|
cli_args = parse_args(["machine", "destroy", "foo"])
|
|
assert cli_args.func == CmdMachineDestroy
|
|
|
|
cmd = cli_args.func(cli_args)
|
|
m = mocker.patch.object(
|
|
cmd.repo.machine, "destroy", autospec=True, return_value=0
|
|
)
|
|
|
|
assert cmd.run() == 0
|
|
m.assert_called_once_with("foo")
|
|
|
|
|
|
def test_ssh(tmp_dir, dvc, mocker):
|
|
cli_args = parse_args(["machine", "ssh", "foo"])
|
|
assert cli_args.func == CmdMachineSsh
|
|
|
|
cmd = cli_args.func(cli_args)
|
|
m = mocker.patch.object(
|
|
cmd.repo.machine, "run_shell", autospec=True, return_value=0
|
|
)
|
|
|
|
assert cmd.run() == 0
|
|
m.assert_called_once_with("foo")
|
|
|
|
|
|
def test_list(tmp_dir, mocker):
|
|
from dvc.ui import ui
|
|
|
|
tmp_dir.gen(DATA)
|
|
cli_args = parse_args(["machine", "list", "foo"])
|
|
assert cli_args.func == CmdMachineList
|
|
cmd = cli_args.func(cli_args)
|
|
m = mocker.patch.object(ui, "write", autospec=True)
|
|
assert cmd.run() == 0
|
|
m.assert_called_once_with("cloud=aws")
|
|
|
|
|
|
def test_modified(tmp_dir):
|
|
tmp_dir.gen(DATA)
|
|
cli_args = parse_args(["machine", "modify", "foo", "cloud", "azure"])
|
|
assert cli_args.func == CmdMachineModify
|
|
cmd = cli_args.func(cli_args)
|
|
assert cmd.run() == 0
|
|
config = configobj.ConfigObj(str(tmp_dir / ".dvc" / "config"))
|
|
assert config['machine "foo"']["cloud"] == "azure"
|