Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix loading parameter behavior from yaml file. #864

Open
wants to merge 1 commit into
base: rolling
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ros2param/ros2param/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def load_parameter_file(*, node, node_name, parameter_file, use_wildcard):
raise RuntimeError('Wait for service timed out waiting for '
f'parameter services for node {node_name}')
future = client.load_parameter_file(parameter_file, use_wildcard)
parameters = list(parameter_dict_from_yaml_file(parameter_file, use_wildcard).values())
parameters = list(parameter_dict_from_yaml_file(
parameter_file, use_wildcard, target_nodes=[node_name]).values())
fujitatomoya marked this conversation as resolved.
Show resolved Hide resolved
rclpy.spin_until_future_complete(node, future)
response = future.result()
assert len(response.results) == len(parameters), 'Not all parameters set'
Expand Down
31 changes: 29 additions & 2 deletions ros2param/test/test_verb_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@
' ros__parameters:\n'
' str_param: Override\n'
)
INPUT_NS_NODE_OVERLAY_PARAMETER_FILE = (
f'{TEST_NAMESPACE}:\n'
f' {TEST_NODE}:\n'
fujitatomoya marked this conversation as resolved.
Show resolved Hide resolved
' ros__parameters:\n'
' str_param: Override\n'
)

# Skip cli tests on Windows while they exhibit pathological behavior
# https://github.com/ros2/build_farmer/issues/248
Expand Down Expand Up @@ -318,7 +324,7 @@ def test_verb_load_wildcard(self):
assert param_load_command.wait_for_shutdown(timeout=TEST_TIMEOUT)
assert param_load_command.exit_code != launch_testing.asserts.EXIT_OK
assert launch_testing.tools.expect_output(
expected_lines=['Param file does not contain selected parameters'],
expected_lines=['Param file does not contain any valid parameters'],
text=param_load_command.output,
strict=False
)
Expand All @@ -344,7 +350,7 @@ def test_verb_load_wildcard(self):
assert params['str_param'] == 'Wildcard'
assert params['int_param'] == 12345

# Concatenate wildcard + some overlays
# Concatenate wildcard + some overlays with absolute node name
filepath = self._write_param_file(tmpdir, 'params.yaml',
INPUT_WILDCARD_PARAMETER_FILE + '\n' +
INPUT_NODE_OVERLAY_PARAMETER_FILE)
Expand All @@ -364,3 +370,24 @@ def test_verb_load_wildcard(self):
params = loaded_params[f'{TEST_NAMESPACE}/{TEST_NODE}']['ros__parameters']
assert params['str_param'] == 'Override' # Overriden
assert params['int_param'] == 12345 # Wildcard namespace

# Concatenate wildcard + some overlays with namespace and base node name
filepath = self._write_param_file(tmpdir, 'params.yaml',
INPUT_WILDCARD_PARAMETER_FILE + '\n' +
INPUT_NS_NODE_OVERLAY_PARAMETER_FILE)
with self.launch_param_load_command(
arguments=[f'{TEST_NAMESPACE}/{TEST_NODE}', filepath]
) as param_load_command:
assert param_load_command.wait_for_shutdown(timeout=TEST_TIMEOUT)
assert param_load_command.exit_code == launch_testing.asserts.EXIT_OK

# Dump and check that wildcard parameters were overriden if in node namespace
with self.launch_param_dump_command(
arguments=[f'{TEST_NAMESPACE}/{TEST_NODE}']
) as param_dump_command:
assert param_dump_command.wait_for_shutdown(timeout=TEST_TIMEOUT)
assert param_dump_command.exit_code == launch_testing.asserts.EXIT_OK
loaded_params = yaml.safe_load(param_dump_command.output)
params = loaded_params[f'{TEST_NAMESPACE}/{TEST_NODE}']['ros__parameters']
assert params['str_param'] == 'Override' # Overriden
assert params['int_param'] == 12345 # Wildcard namespace