Skip to content

Commit cb68329

Browse files
committed
Use explicit ping function for AG device checks
1 parent 59906c4 commit cb68329

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/gort/devices/ag.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010

1111
import asyncio
1212

13-
from lvmopstools.utils import is_host_up
14-
1513
from gort.devices.core import GortDevice, GortDeviceSet
1614
from gort.exceptions import GortDeviceError
1715
from gort.gort import Gort
18-
from gort.tools import run_lvmapi_task
16+
from gort.tools import ping_host, run_lvmapi_task
1917

2018

2119
__all__ = ["AG", "AGSet"]
@@ -135,11 +133,16 @@ async def check_camera(self, ping: bool = True, status: bool = True):
135133

136134
if ping:
137135
for side, ip in self.ips.items():
136+
name = f"{self.name}-{side}"
137+
138138
if ip is None:
139139
continue
140140

141-
if not await is_host_up(ip):
142-
failed.add(side)
141+
if not await ping_host(ip):
142+
self.write_to_log(f"AG {name} did not ping.", "warning")
143+
failed.add(name)
144+
else:
145+
self.write_to_log(f"AG {name} pinged back.", "debug")
143146

144147
if status:
145148
try:
@@ -151,8 +154,7 @@ async def check_camera(self, ping: bool = True, status: bool = True):
151154
return True
152155

153156
raise GortDeviceError(
154-
f"The following {self.name} AG cameras are not responding: "
155-
f"{', '.join(failed)}."
157+
f"The following AG cameras are not responding: {', '.join(failed)}."
156158
)
157159

158160

src/gort/tools.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import os
1818
import pathlib
1919
import re
20+
import subprocess
2021
import tempfile
2122
import warnings
2223
from contextlib import asynccontextmanager, contextmanager, suppress
@@ -104,6 +105,7 @@
104105
"try_or_pass",
105106
"record_overheads",
106107
"OverheadDict",
108+
"ping_host",
107109
]
108110

109111
AnyPath = str | os.PathLike
@@ -1204,3 +1206,16 @@ def record_overheads(payload: Sequence[OverheadDict] | OverheadDict):
12041206

12051207
table_name = config["services.database.tables.overheads"]
12061208
insert_to_database(table_name, payload_dict)
1209+
1210+
1211+
async def ping_host(host: str):
1212+
"""Pings a host."""
1213+
1214+
cmd = await asyncio.create_subprocess_exec(
1215+
*["ping", "-c", "1", "-W", "5", host],
1216+
stdout=subprocess.PIPE,
1217+
stderr=subprocess.PIPE,
1218+
)
1219+
1220+
return_code = await cmd.wait()
1221+
return return_code == 0

0 commit comments

Comments
 (0)