Merge "Add destroyed container context manager"
This commit is contained in:
commit
5619ec0012
|
@ -202,3 +202,32 @@ def test_patch_container_service(
|
|||
mock.call(container, ["service", service, "restart"])
|
||||
] == docker_run_mock.call_args_list
|
||||
patch_mock.assert_called_once_with(container, prefix, *patches)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("container", ["container"])
|
||||
@pytest.mark.parametrize("container_name", ["container_name"])
|
||||
@pytest.mark.parametrize("is_exception", [True, False])
|
||||
def test_destroyed_container(mocker, container, container_name, is_exception):
|
||||
subprocess_call_mock = mocker.patch("octane.util.subprocess.call")
|
||||
get_name_mock = mocker.patch(
|
||||
"octane.util.docker.get_docker_container_name",
|
||||
return_value=container_name)
|
||||
|
||||
class TestException(Exception):
|
||||
pass
|
||||
|
||||
if is_exception:
|
||||
with pytest.raises(TestException):
|
||||
with docker.destroyed_container(container):
|
||||
raise TestException
|
||||
else:
|
||||
with docker.destroyed_container(container):
|
||||
pass
|
||||
|
||||
assert [
|
||||
mock.call(["dockerctl", "destroy", container_name]),
|
||||
mock.call(["dockerctl", "start", container]),
|
||||
mock.call(["dockerctl", "check", container]),
|
||||
] == subprocess_call_mock.call_args_list
|
||||
|
||||
get_name_mock.assert_called_once_with(container)
|
||||
|
|
|
@ -187,6 +187,17 @@ def start_container(container):
|
|||
_container_action(container, "start")
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def destroyed_container(container):
|
||||
name = get_docker_container_name(container)
|
||||
subprocess.call(["dockerctl", "destroy", name])
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
subprocess.call(["dockerctl", "start", container])
|
||||
subprocess.call(["dockerctl", "check", container])
|
||||
|
||||
|
||||
def wait_for_container(container, attempts=120, delay=5):
|
||||
assert delay > 0
|
||||
_wait_for_start_container(container, attempts, delay)
|
||||
|
|
Loading…
Reference in New Issue