From 3a309e5b7f802b2f4a36ba2bcdf91702df7fef12 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 16 Feb 2023 14:11:51 -0800 Subject: [PATCH] Fix normalize_parameters_dict for multiple nodes in the same namespace (backport #347) (#350) Co-authored-by: Alexey Merzlyakov <60094858+AlexeyMerzlyakov@users.noreply.github.com> --- .../utilities/to_parameters_list.py | 4 +- .../example_parameters_multiple_nodes.yaml | 9 ++++ .../actions/test_load_composable_nodes.py | 48 ++++++++++++++++++- 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 test_launch_ros/test/test_launch_ros/actions/example_parameters_multiple_nodes.yaml diff --git a/launch_ros/launch_ros/utilities/to_parameters_list.py b/launch_ros/launch_ros/utilities/to_parameters_list.py index 534ec7e9..6aad2032 100644 --- a/launch_ros/launch_ros/utilities/to_parameters_list.py +++ b/launch_ros/launch_ros/utilities/to_parameters_list.py @@ -48,8 +48,8 @@ def normalize_parameters_dict(dictionary, keys, result_dict): if isinstance(value, dict): keys.append(key.lstrip('/')) result_dict = normalize_parameters_dict(value, keys, result_dict) - # Reset keys in case there are multiple ros__parameter entries - keys = [] + # Clean-up keys for the case of multiple nodes/ros__parameter entries + keys.pop() return result_dict diff --git a/test_launch_ros/test/test_launch_ros/actions/example_parameters_multiple_nodes.yaml b/test_launch_ros/test/test_launch_ros/actions/example_parameters_multiple_nodes.yaml new file mode 100644 index 00000000..e8fa7d08 --- /dev/null +++ b/test_launch_ros/test/test_launch_ros/actions/example_parameters_multiple_nodes.yaml @@ -0,0 +1,9 @@ +/ns_1: + /node_1: + ros__parameters: + param_1: 11 + param_2: 22 + node_2: + ros__parameters: + param_3: 33 + param_4: 44 diff --git a/test_launch_ros/test/test_launch_ros/actions/test_load_composable_nodes.py b/test_launch_ros/test/test_launch_ros/actions/test_load_composable_nodes.py index 95be78b7..953cd1c8 100644 --- a/test_launch_ros/test/test_launch_ros/actions/test_load_composable_nodes.py +++ b/test_launch_ros/test/test_launch_ros/actions/test_load_composable_nodes.py @@ -375,7 +375,53 @@ def test_load_node_with_param_file(mock_component_container): assert request.parameters[1].name == 'param_3' assert request.parameters[1].value.integer_value == 3 - # Case 7: node name not found + # Case 7: multiple nodes in one namespace + context = _assert_launch_no_errors([ + LoadComposableNodes( # Load in same action so it happens sequentially + target_container=f'/{TEST_CONTAINER_NAME}', + composable_node_descriptions=[ + ComposableNode( + package='foo_package', + plugin='bar_plugin', + name='node_1', + namespace='ns_1', + parameters=[ + parameters_file_dir / 'example_parameters_multiple_nodes.yaml' + ] + ), + ComposableNode( + package='foo_package', + plugin='bar_plugin', + name='node_2', + namespace='ns_1', + parameters=[ + parameters_file_dir / 'example_parameters_multiple_nodes.yaml' + ] + ) + ] + ) + ]) + request = mock_component_container.requests[-2] + assert get_node_name_count(context, '/ns_1/node_1') == 1 + assert request.node_name == 'node_1' + assert request.node_namespace == '/ns_1' + assert len(request.parameters) == 2 + assert request.parameters[0].name == 'param_1' + assert request.parameters[0].value.integer_value == 11 + assert request.parameters[1].name == 'param_2' + assert request.parameters[1].value.integer_value == 22 + + request = mock_component_container.requests[-1] + assert get_node_name_count(context, '/ns_1/node_2') == 1 + assert request.node_name == 'node_2' + assert request.node_namespace == '/ns_1' + assert len(request.parameters) == 2 + assert request.parameters[0].name == 'param_3' + assert request.parameters[0].value.integer_value == 33 + assert request.parameters[1].name == 'param_4' + assert request.parameters[1].value.integer_value == 44 + + # Case 8: node name not found context = _assert_launch_no_errors([ _load_composable_node( package='foo_package',