From 8966ec20f2b5b21f3a07c20c8f27182df770944a Mon Sep 17 00:00:00 2001 From: Dmitriy Zayakin Date: Fri, 1 Dec 2023 14:19:10 +0300 Subject: [PATCH] [#135] Add method uptime service Signed-off-by: Dmitriy Zayakin --- src/frostfs_testlib/storage/dataclasses/node_base.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/frostfs_testlib/storage/dataclasses/node_base.py b/src/frostfs_testlib/storage/dataclasses/node_base.py index 1e23c7e..494cf50 100644 --- a/src/frostfs_testlib/storage/dataclasses/node_base.py +++ b/src/frostfs_testlib/storage/dataclasses/node_base.py @@ -1,8 +1,10 @@ from abc import abstractmethod from dataclasses import dataclass +from datetime import datetime, timezone from typing import Optional, TypedDict, TypeVar import yaml +from dateutil import parser from frostfs_testlib.hosting.config import ServiceConfig from frostfs_testlib.hosting.interfaces import Host @@ -164,6 +166,15 @@ class NodeBase(HumanReadableABC): def _get_service_config(self) -> ServiceConfig: return self.host.get_service_config(self.name) + def get_service_uptime(self, service: str) -> datetime: + result = self.host.get_shell().exec( + f"systemctl show {service} --property ActiveEnterTimestamp | cut -d '=' -f 2" + ) + start_time = parser.parse(result.stdout.strip()) + current_time = datetime.now(tz=timezone.utc) + active_time = current_time - start_time + return active_time + ServiceClass = TypeVar("ServiceClass", bound=NodeBase)