Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
Use more descriptive name for utility
Browse files Browse the repository at this point in the history
  • Loading branch information
richfitz committed Oct 19, 2023
1 parent 6bc9e1c commit 6765c34
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/privateer2/backup.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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.
6 changes: 4 additions & 2 deletions src/privateer2/restore.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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
)
2 changes: 1 addition & 1 deletion src/privateer2/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion tests/test_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion tests/test_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 6765c34

Please sign in to comment.