Service restart

Signed-off-by: Vladislav Karakozov <v.karakozov@yadro.com>
This commit is contained in:
Vladislav Karakozov 2023-02-07 13:13:57 +03:00 committed by Vlad K
parent 469ab4db43
commit 11d65091ad
4 changed files with 24 additions and 4 deletions

View file

@ -5,7 +5,7 @@ repos:
- id: black - id: black
language_version: python3.9 language_version: python3.9
- repo: https://github.com/pycqa/isort - repo: https://github.com/pycqa/isort
rev: 5.10.1 rev: 5.12.0
hooks: hooks:
- id: isort - id: isort
name: isort (python) name: isort (python)

View file

@ -9,7 +9,7 @@ requests==2.28.1
# Dev dependencies # Dev dependencies
black==22.8.0 black==22.8.0
bumpver==2022.1118 bumpver==2022.1118
isort==5.10.1 isort==5.12.0
pre-commit==2.20.0 pre-commit==2.20.0
# Packaging dependencies # Packaging dependencies

View file

@ -54,8 +54,8 @@ class ServiceAttributes(ParsedAttributes):
container_name: str container_name: str
volume_name: Optional[str] = None volume_name: Optional[str] = None
start_timeout: int = 60 start_timeout: int = 90
stop_timeout: int = 60 stop_timeout: int = 90
class DockerHost(Host): class DockerHost(Host):
@ -117,6 +117,18 @@ class DockerHost(Host):
timeout=service_attributes.stop_timeout, 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: def delete_storage_node_data(self, service_name: str, cache_only: bool = False) -> None:
service_attributes = self._get_service_attributes(service_name) service_attributes = self._get_service_attributes(service_name)

View file

@ -104,6 +104,14 @@ class Host(ABC):
service_name: Name of the service to stop. 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 @abstractmethod
def delete_storage_node_data(self, service_name: str, cache_only: bool = False) -> None: def delete_storage_node_data(self, service_name: str, cache_only: bool = False) -> None:
"""Erases all data of the storage node with specified name. """Erases all data of the storage node with specified name.