[#135] Add method uptime service

Signed-off-by: Dmitriy Zayakin <d.zayakin@yadro.com>
This commit is contained in:
Dmitriy Zayakin 2023-12-01 14:19:10 +03:00 committed by Dmitriy Zayakin
parent 74eb72f59d
commit 8966ec20f2

View file

@ -1,8 +1,10 @@
from abc import abstractmethod from abc import abstractmethod
from dataclasses import dataclass from dataclasses import dataclass
from datetime import datetime, timezone
from typing import Optional, TypedDict, TypeVar from typing import Optional, TypedDict, TypeVar
import yaml import yaml
from dateutil import parser
from frostfs_testlib.hosting.config import ServiceConfig from frostfs_testlib.hosting.config import ServiceConfig
from frostfs_testlib.hosting.interfaces import Host from frostfs_testlib.hosting.interfaces import Host
@ -164,6 +166,15 @@ class NodeBase(HumanReadableABC):
def _get_service_config(self) -> ServiceConfig: def _get_service_config(self) -> ServiceConfig:
return self.host.get_service_config(self.name) 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) ServiceClass = TypeVar("ServiceClass", bound=NodeBase)