Skip to content

Commit

Permalink
status: add timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed May 9, 2024
1 parent 828d815 commit 2cbe0a4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions framework/internal/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ def is_running(status: dict):

return 'State' in status and status['State'] == "running"

def exec(service: str, command: list[str]) -> tuple[int, bytes]:
def exec(service: str, command: list[str], timeout: int = 120) -> tuple[int, bytes]:
"""
Execute a command in a docker compose service
"""

cmd = ['docker', 'compose', 'exec', service] + command
result = subprocess.run(cmd, stdout=subprocess.PIPE)
result = subprocess.run(cmd, stdout=subprocess.PIPE, timeout=timeout)
return result.returncode, result.stdout

def up(service: str):
Expand Down
6 changes: 3 additions & 3 deletions framework/status-json.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_services():
def get_nfd():
print('Getting NFD status', file=sys.stderr)
nfd = {}
_, stdout = compose.exec('nfd', ['nfdc', 'status'])
_, stdout = compose.exec('nfd', ['nfdc', 'status'], timeout=5)
for line in stdout.decode('utf-8').splitlines():
line = line.strip()
if '=' in line:
Expand All @@ -37,7 +37,7 @@ def get_nfd():
def get_nlsr():
print('Getting NLSR status', file=sys.stderr)
nlsr = {}
_, stdout = compose.exec('nlsr', ['nlsr', '-V'])
_, stdout = compose.exec('nlsr', ['nlsr', '-V'], timeout=5)
nlsr['version'] = stdout.decode('utf-8').strip()
return nlsr

Expand All @@ -55,7 +55,7 @@ def get_ndnping():

if ping_prefix:
print(f'ndnping {host_name} with prefix {ping_prefix}', file=sys.stderr)
code, _ = compose.exec('ndnpingserver', ['ndnping', '-c', '3', '-i', '10', ping_prefix])
code, _ = compose.exec('ndnpingserver', ['ndnping', '-c', '3', '-i', '10', ping_prefix], timeout=10)
result[host_name] = code == 0

return result
Expand Down

0 comments on commit 2cbe0a4

Please sign in to comment.