fix: refactor stop and kill

This commit is contained in:
Roman 2025-02-13 19:25:05 +08:00
parent 9c61ae1f9d
commit 5a8455c22d
No known key found for this signature in database
GPG Key ID: B8FE070B54E11B75
3 changed files with 32 additions and 38 deletions

View File

@ -8,7 +8,7 @@ from src.libs.custom_logger import get_custom_logger
from tenacity import retry, stop_after_delay, wait_fixed
from src.cli.cli_vars import nomos_cli
from src.docker_manager import DockerManager
from src.docker_manager import DockerManager, stop, kill
from src.env_vars import DOCKER_LOG_DIR, NOMOS_CLI
from src.steps.da import remove_padding
@ -107,24 +107,8 @@ class NomosCli:
@retry(stop=stop_after_delay(5), wait=wait_fixed(0.1), reraise=True)
def stop(self):
if self._container:
logger.debug(f"Stopping container with id {self._container.short_id}")
self._container.stop()
try:
self._container.remove()
except:
pass
self._container = None
logger.debug("Container stopped.")
self._container = stop(self._container)
@retry(stop=stop_after_delay(5), wait=wait_fixed(0.1), reraise=True)
def kill(self):
if self._container:
logger.debug(f"Killing container with id {self._container.short_id}")
self._container.kill()
try:
self._container.remove()
except:
pass
self._container = None
logger.debug("Container killed.")
self._container = kill(self._container)

View File

@ -168,3 +168,29 @@ class DockerManager:
else:
logger.debug("No keywords found in the nomos logs.")
return None
def stop(container):
if container:
logger.debug(f"Stopping container with id {container.short_id}")
container.stop()
try:
container.remove()
except:
pass
logger.debug("Container stopped.")
return None
def kill(container):
if container:
logger.debug(f"Killing container with id {container.short_id}")
container.kill()
try:
container.remove()
except:
pass
logger.debug("Container killed.")
return None

View File

@ -5,7 +5,7 @@ from src.libs.custom_logger import get_custom_logger
from tenacity import retry, stop_after_delay, wait_fixed
from src.api_clients.rest import REST
from src.docker_manager import DockerManager
from src.docker_manager import DockerManager, stop, kill
from src.env_vars import DOCKER_LOG_DIR
from src.node.node_vars import nomos_nodes
from src.test_data import LOG_ERROR_KEYWORDS
@ -84,27 +84,11 @@ class NomosNode:
@retry(stop=stop_after_delay(5), wait=wait_fixed(0.1), reraise=True)
def stop(self):
if self._container:
logger.debug(f"Stopping container with id {self._container.short_id}")
self._container.stop()
try:
self._container.remove()
except:
pass
self._container = None
logger.debug("Container stopped.")
self._container = stop(self._container)
@retry(stop=stop_after_delay(5), wait=wait_fixed(0.1), reraise=True)
def kill(self):
if self._container:
logger.debug(f"Killing container with id {self._container.short_id}")
self._container.kill()
try:
self._container.remove()
except:
pass
self._container = None
logger.debug("Container killed.")
self._container = kill(self._container)
def restart(self):
if self._container: