From 11d65091ad6f593eea3487a397b151a06f0a8b69 Mon Sep 17 00:00:00 2001 From: Vladislav Karakozov Date: Tue, 7 Feb 2023 13:13:57 +0300 Subject: [PATCH] Service restart Signed-off-by: Vladislav Karakozov --- .pre-commit-config.yaml | 2 +- requirements.txt | 2 +- src/neofs_testlib/hosting/docker_host.py | 16 ++++++++++++++-- src/neofs_testlib/hosting/interfaces.py | 8 ++++++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ad9846a..0603040 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: - id: black language_version: python3.9 - repo: https://github.com/pycqa/isort - rev: 5.10.1 + rev: 5.12.0 hooks: - id: isort name: isort (python) diff --git a/requirements.txt b/requirements.txt index adca8f9..af0ee32 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,7 +9,7 @@ requests==2.28.1 # Dev dependencies black==22.8.0 bumpver==2022.1118 -isort==5.10.1 +isort==5.12.0 pre-commit==2.20.0 # Packaging dependencies diff --git a/src/neofs_testlib/hosting/docker_host.py b/src/neofs_testlib/hosting/docker_host.py index 257847b..3b36e31 100644 --- a/src/neofs_testlib/hosting/docker_host.py +++ b/src/neofs_testlib/hosting/docker_host.py @@ -54,8 +54,8 @@ class ServiceAttributes(ParsedAttributes): container_name: str volume_name: Optional[str] = None - start_timeout: int = 60 - stop_timeout: int = 60 + start_timeout: int = 90 + stop_timeout: int = 90 class DockerHost(Host): @@ -117,6 +117,18 @@ class DockerHost(Host): timeout=service_attributes.stop_timeout, ) + def restart_service(self, service_name: str) -> None: + service_attributes = self._get_service_attributes(service_name) + + client = self._get_docker_client() + client.restart(service_attributes.container_name) + + self._wait_for_container_to_be_in_state( + container_name=service_attributes.container_name, + expected_state="running", + timeout=service_attributes.start_timeout, + ) + def delete_storage_node_data(self, service_name: str, cache_only: bool = False) -> None: service_attributes = self._get_service_attributes(service_name) diff --git a/src/neofs_testlib/hosting/interfaces.py b/src/neofs_testlib/hosting/interfaces.py index ddb07b7..2d36045 100644 --- a/src/neofs_testlib/hosting/interfaces.py +++ b/src/neofs_testlib/hosting/interfaces.py @@ -104,6 +104,14 @@ class Host(ABC): service_name: Name of the service to stop. """ + @abstractmethod + def restart_service(self, service_name: str) -> None: + """Restarts the service with specified name and waits until it starts. + The service must be hosted on this host. + Args: + service_name: Name of the service to restart. + """ + @abstractmethod def delete_storage_node_data(self, service_name: str, cache_only: bool = False) -> None: """Erases all data of the storage node with specified name.