selfcheck.py: add network check

This commit is contained in:
Oleg Kalachev
2019-11-15 09:58:36 +03:00
parent f574637a3f
commit 0574f4cc46

View File

@@ -9,6 +9,7 @@
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
import os
import math
import subprocess
import re
@@ -692,9 +693,32 @@ def check_preflight_status():
failure(' '.join([match.groups()[1], 'check:', check_status]))
@check('Network')
def check_network():
ros_hostname = os.environ.get('ROS_HOSTNAME').strip()
if not ros_hostname:
failure('No ROS_HOSTNAME is set')
elif ros_hostname.endswith('.local'):
# using mdns hostname
hosts = open('/etc/hosts', 'r')
for line in hosts:
parts = line.split()
if len(parts) < 2:
continue
ip = parts.pop(0).split('.')
if ip[0] == '127': # loopback ip
if ros_hostname in parts:
break
else:
failure('Not found %s in /etc/hosts, ROS will malfunction if network interfaces are down, https://clever.coex.tech/hostname', ros_hostname)
def selfcheck():
check_image()
check_clever_service()
check_network()
check_fcu()
check_imu()
check_local_position()