Skip to content

Commit 9f28544

Browse files
author
Claire Wang
authored
Add network configuration check and report to ros2doctor (#319)
* add network checks and report Signed-off-by: claireyywang <[email protected]> * network shenanigens Signed-off-by: claireyywang <[email protected]> * network shenanigens Signed-off-by: claireyywang <[email protected]> * network shenanigens Signed-off-by: claireyywang <[email protected]> * add network check and report Signed-off-by: claireyywang <[email protected]> * update code format Signed-off-by: claireyywang <[email protected]> * revised code format Signed-off-by: claireyywang <[email protected]> * add ifcfg-pip rosdep key waiting for rosdistro PR approval ros/rosdistro#22071 * added rosdep key ifcfg-pip Signed-off-by: claireyywang <[email protected]> * revise code Signed-off-by: claireyywang <[email protected]>
1 parent 10c89eb commit 9f28544

File tree

6 files changed

+110
-26
lines changed

6 files changed

+110
-26
lines changed

ros2doctor/package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<depend>ros2cli</depend>
1111

12-
<exec_depend>python3-numpy</exec_depend>
12+
<exec_depend>ifcfg_vendor</exec_depend>
1313
<exec_depend>python3-rosdistro-modules</exec_depend>
1414

1515
<test_depend>ament_copyright</test_depend>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2019 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
16+
def print_term(k, v):
17+
"""Print term only if it exists."""
18+
if v:
19+
# TODO(clairewang): 20 padding needs to be dynamically set
20+
print('{:20}: {}'.format(k, v))
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright 2019 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
import sys
17+
18+
import ifcfg
19+
20+
from ros2doctor.api.format import print_term
21+
22+
23+
def _is_unix_like_platform():
24+
"""Return True if conforms to UNIX/POSIX-style APIs."""
25+
return os.name == 'posix'
26+
27+
28+
def check_network_config_helper():
29+
"""Check if loopback and multicast IP addresses are found."""
30+
has_loopback, has_non_loopback, has_multicast = False, False, False
31+
for name, iface in ifcfg.interfaces().items():
32+
flags = iface.get('flags')
33+
if 'LOOPBACK' in flags:
34+
has_loopback = True
35+
else:
36+
has_non_loopback = True
37+
if 'MULTICAST' in flags:
38+
has_multicast = True
39+
return has_loopback, has_non_loopback, has_multicast
40+
41+
42+
def check_network_config():
43+
"""Conduct network checks and output error/warning messages."""
44+
has_loopback, has_non_loopback, has_multicast = check_network_config_helper()
45+
if not has_loopback:
46+
sys.stderr.write('ERROR: No loopback IP address is found.\n')
47+
if not has_non_loopback:
48+
sys.stderr.write('WARNING: Only loopback IP address is found.\n')
49+
if not has_multicast:
50+
sys.stderr.write('WARNING: No multicast IP address is found.\n')
51+
return has_loopback and has_non_loopback and has_multicast
52+
53+
54+
def print_network():
55+
"""Print all system and ROS network information."""
56+
print('NETWORK CONFIGURATION')
57+
for name, iface in ifcfg.interfaces().items():
58+
for k, v in iface.items():
59+
print_term(k, v)
60+
print('\n')

ros2doctor/ros2doctor/api/platform.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import platform
1717
import sys
1818

19+
from ros2doctor.api.format import print_term
20+
1921
import rosdistro
2022

2123

@@ -24,37 +26,38 @@ def print_platform_info():
2426
platform_name = platform.system()
2527
# platform info
2628
print('PLATFORM INFORMATION')
27-
print('system : ', platform_name)
28-
print('Platform Info : ', platform.platform())
29+
print_term('system', platform_name)
30+
print_term('platform info', platform.platform())
2931
if platform_name == 'Darwin':
30-
print('Mac OS version : ', platform.mac_ver())
31-
print('release : ', platform.release())
32-
print('processor : ', platform.processor())
32+
print_term('mac OS version', platform.mac_ver())
33+
print_term('release', platform.release())
34+
print_term('processor', platform.processor())
3335

3436
# python info
3537
print('PYTHON INFORMATION')
36-
print('version : ', platform.python_version())
37-
print('compiler : ', platform.python_compiler())
38-
print('build : ', platform.python_build())
38+
print_term('version', platform.python_version())
39+
print_term('compiler', platform.python_compiler())
40+
print_term('build', platform.python_build())
41+
print('\n')
3942

4043

4144
def check_platform_helper():
4245
"""Check ROS_DISTRO related environment variables and distribution name."""
4346
distro_name = os.environ.get('ROS_DISTRO')
4447
if not distro_name:
45-
sys.stderr.write('WARNING: ROS_DISTRO is not set.')
48+
sys.stderr.write('WARNING: ROS_DISTRO is not set.\n')
4649
return
4750
else:
4851
distro_name = distro_name.lower()
4952
u = rosdistro.get_index_url()
5053
if not u:
51-
sys.stderr.write('WARNING: Unable to access ROSDISTRO_INDEX_URL\
52-
or DEFAULT_INDEX_URL.')
54+
sys.stderr.write('WARNING: Unable to access ROSDISTRO_INDEX_URL '
55+
'or DEFAULT_INDEX_URL.\n')
5356
return
5457
i = rosdistro.get_index(u)
5558
distro_info = i.distributions.get(distro_name)
5659
if not distro_info:
57-
sys.stderr.write("WARNING: Distribution name '%s' is not found" % distro_name)
60+
sys.stderr.write("WARNING: Distribution name '%s' is not found\n" % distro_name)
5861
return
5962
distro_data = rosdistro.get_distribution(i, distro_name).get_data()
6063
return distro_name, distro_info, distro_data
@@ -68,10 +71,11 @@ def print_ros2_info():
6871
distro_name, distro_info, distro_data = distros
6972

7073
print('ROS INFORMATION')
71-
print('distribution name : ', distro_name)
72-
print('distribution type : ', distro_info.get('distribution_type'))
73-
print('distribution status : ', distro_info.get('distribution_status'))
74-
print('release platforms : ', distro_data.get('release_platforms'))
74+
print_term('distribution name', distro_name)
75+
print_term('distribution type', distro_info.get('distribution_type'))
76+
print_term('distribution status', distro_info.get('distribution_status'))
77+
print_term('release platforms', distro_data.get('release_platforms'))
78+
print('\n')
7579

7680

7781
def check_platform():
@@ -84,15 +88,13 @@ def check_platform():
8488

8589
# check distro status
8690
if distro_info.get('distribution_status') == 'prerelease':
87-
sys.stderr.write('WARNING: Distribution is not fully supported or tested.\
88-
To get more stable features,\
89-
Download a stable version at\
90-
https://index.ros.org/doc/ros2/Installation/')
91+
sys.stderr.write('WARNING: Distribution is not fully supported or tested. '
92+
'To get more stable features, download a stable version at '
93+
'https://index.ros.org/doc/ros2/Installation/\n')
9194
elif distro_info.get('distribution_status') == 'end-of-life':
92-
sys.stderr.write('WARNING: Distribution is no longer supported or deprecated.\
93-
To get the latest features,\
94-
Download the latest version at\
95-
https://index.ros.org/doc/ros2/Installation/')
95+
sys.stderr.write('WARNING: Distribution is no longer supported or deprecated. '
96+
'To get the latest features, download the latest version at '
97+
'https://index.ros.org/doc/ros2/Installation/')
9698
else:
9799
passed = True
98100
return passed

ros2doctor/ros2doctor/command/doctor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ def main(self, *, parser, args):
4141

4242

4343
class WtfCommand(DoctorCommand):
44-
"""Add `wtf` as alias to `doctor`."""
44+
"""Use `wtf` as alias to `doctor`."""
4545

4646
pass

ros2doctor/setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@
3232
],
3333
'ros2doctor.checks': [
3434
'check_platform = ros2doctor.api.platform:check_platform',
35+
'check_network_config = ros2doctor.api.network:check_network_config',
3536
],
3637
'ros2doctor.report': [
3738
'report_platform = ros2doctor.api.platform:print_platform_info',
3839
'report_ros_distro = ros2doctor.api.platform:print_ros2_info',
40+
'report_network_config = ros2doctor.api.network:print_network',
3941
],
4042
}
4143
)

0 commit comments

Comments
 (0)