diff --git a/src/privateer2/backup.py b/src/privateer2/backup.py index 372e66d..c8b2ee4 100644 --- a/src/privateer2/backup.py +++ b/src/privateer2/backup.py @@ -1,6 +1,6 @@ import docker from privateer2.keys import check -from privateer2.util import match_value, mounts_str, run_docker_command +from privateer2.util import match_value, mounts_str, run_container_with_command def backup(cfg, name, volume, *, server=None, dry_run=False): @@ -38,7 +38,9 @@ def backup(cfg, name, volume, *, server=None, dry_run=False): print("in the directory /privateer/keys") else: print(f"Backing up '{volume}' from '{name}' to '{server}'") - run_docker_command("Backup", image, command=command, mounts=mounts) + run_container_with_command( + "Backup", image, command=command, mounts=mounts + ) # TODO: also copy over some metadata at this point, via # ssh; probably best to write tiny utility in the client # container that will do this for us. diff --git a/src/privateer2/restore.py b/src/privateer2/restore.py index 99667a5..20656b0 100644 --- a/src/privateer2/restore.py +++ b/src/privateer2/restore.py @@ -1,7 +1,7 @@ import docker from privateer2.config import find_source from privateer2.keys import check -from privateer2.util import match_value, mounts_str, run_docker_command +from privateer2.util import match_value, mounts_str, run_container_with_command def restore(cfg, name, volume, *, server=None, source=None, dry_run=False): @@ -38,4 +38,6 @@ def restore(cfg, name, volume, *, server=None, source=None, dry_run=False): print("in the directory /privateer/keys") else: print(f"Restoring '{volume}' from '{server}'") - run_docker_command("Restore", image, command=command, mounts=mounts) + run_container_with_command( + "Restore", image, command=command, mounts=mounts + ) diff --git a/src/privateer2/util.py b/src/privateer2/util.py index 51e4d7a..9dbd5b8 100644 --- a/src/privateer2/util.py +++ b/src/privateer2/util.py @@ -222,7 +222,7 @@ def take_ownership(filename, directory, *, command_only=False): # tar ) -def run_docker_command(display, image, **kwargs): +def run_container_with_command(display, image, **kwargs): ensure_image(image) client = docker.from_env() container = client.containers.run(image, **kwargs, detach=True) diff --git a/tests/test_backup.py b/tests/test_backup.py index 0fdcd31..a999a60 100644 --- a/tests/test_backup.py +++ b/tests/test_backup.py @@ -33,7 +33,9 @@ def test_can_print_instructions_to_run_backup(capsys, managed_docker): def test_can_run_backup(monkeypatch, managed_docker): mock_run = MagicMock() - monkeypatch.setattr(privateer2.backup, "run_docker_command", mock_run) + monkeypatch.setattr( + privateer2.backup, "run_container_with_command", mock_run + ) with vault_dev.Server(export_token=True) as server: cfg = read_config("example/simple.json") cfg.vault.url = server.url() diff --git a/tests/test_restore.py b/tests/test_restore.py index c99c098..9a09ad6 100644 --- a/tests/test_restore.py +++ b/tests/test_restore.py @@ -34,7 +34,9 @@ def test_can_print_instructions_to_run_restore(capsys, managed_docker): def test_can_run_restore(monkeypatch, managed_docker): mock_run = MagicMock() - monkeypatch.setattr(privateer2.restore, "run_docker_command", mock_run) + monkeypatch.setattr( + privateer2.restore, "run_container_with_command", mock_run + ) with vault_dev.Server(export_token=True) as server: cfg = read_config("example/simple.json") cfg.vault.url = server.url() diff --git a/tests/test_server.py b/tests/test_server.py index 04ac922..e4abe26 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -176,7 +176,10 @@ def test_can_stop_server(monkeypatch, managed_docker, capsys): server_stop(cfg, "alice") assert mock_container_if_exists.call_count == 3 assert mock_container.stop.call_count == 1 - assert capsys.readouterr().out == f"Container '{name}' for 'alice' does not exist\n" + assert ( + capsys.readouterr().out + == f"Container '{name}' for 'alice' does not exist\n" + ) def test_can_get_server_status(monkeypatch, capsys, managed_docker): diff --git a/tests/test_util.py b/tests/test_util.py index b9f1caf..a743b23 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -95,7 +95,7 @@ def test_can_tail_logs_from_container(managed_docker): def test_can_run_long_command(capsys, managed_docker): name = managed_docker("container") command = ["seq", "1", "3"] - privateer2.util.run_docker_command( + privateer2.util.run_container_with_command( "Test", "alpine", name=name, command=command ) out = capsys.readouterr().out @@ -111,7 +111,7 @@ def test_can_run_failing_command(capsys, managed_docker): command = ["false"] msg = f"Test failed; see {name} logs for details" with pytest.raises(Exception, match=msg): - privateer2.util.run_docker_command( + privateer2.util.run_container_with_command( "Test", "alpine", name=name, command=command ) out = capsys.readouterr().out