Skip to content

[yaml parser] Fix FQN=//node_name when ns is /#299

Merged
dhood merged 3 commits intomasterfrom
root_ns_fix
Sep 21, 2018
Merged

[yaml parser] Fix FQN=//node_name when ns is /#299
dhood merged 3 commits intomasterfrom
root_ns_fix

Conversation

@dhood
Copy link
Copy Markdown
Member

@dhood dhood commented Sep 15, 2018

Consider the parameters file:

/:
    talker:
        ros__parameters:
            some_int: 42

Without this PR, the parameters are stored under the FQN of //talker, so passing the file to a node with ros2 run demo_nodes_cpp talker __params:=demo_parameters.yaml will not set the parameters on the node (ros2 param list /talker is empty).

With this PR, ros2 param list /talker returns the parameter some_int as expected.


Without this change, the parameter file will work if the root namespace is left out completely, but in some cases the user may want to specify explicitly that it is in the root namespace. (I am doing that in https://github.com/ros2/launch/pull/138/files#diff-d78062ac1f3a77c95190e470302b7e69R237 where I write the namespace to a file without considering if it is /ns or just /).

@dhood dhood added the in progress Actively being worked on (Kanban column) label Sep 15, 2018
@dhood dhood self-assigned this Sep 15, 2018
@dhood
Copy link
Copy Markdown
Member Author

dhood commented Sep 15, 2018

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@dhood dhood added in review Waiting for review (Kanban column) in progress Actively being worked on (Kanban column) and removed in progress Actively being worked on (Kanban column) in review Waiting for review (Kanban column) labels Sep 15, 2018
name_len = strlen(name);
sep_len = strlen(sep_str);
tot_len = ns_len + name_len + sep_len + 1U;
if (ns_len == sep_len) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self review: would be better to check the contents of the current ns, and skip appending if it ends with the separator already

@dhood dhood added in review Waiting for review (Kanban column) and removed in progress Actively being worked on (Kanban column) labels Sep 18, 2018
@dhood dhood requested a review from sloretz September 19, 2018 17:53
@dhood
Copy link
Copy Markdown
Member Author

dhood commented Sep 19, 2018

(newer CI):

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@dhood
Copy link
Copy Markdown
Member Author

dhood commented Sep 20, 2018

looking for a review if anyone gets a chance

Copy link
Copy Markdown
Contributor

@sloretz sloretz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should be new tests where the first namespace already has a /, or a parameter that has a ..

tot_len = ns_len + name_len + sep_len + 1U;
// Check the last sep_len characters of the current NS against the separator string.
if (strcmp(cur_ns + ns_len - sep_len, sep_str) == 0) {
// Current NS already ends with the separator: don't put another separator in.
Copy link
Copy Markdown
Contributor

@sloretz sloretz Sep 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the tests I think the intent was that each token in the namespace would be it's own level in the config. Namespace /foo/bar/baz and node name smith would be described by:

foo:
  bar:
    baz:
      smith:
        ros__parameters:

I'm guessing it was not expected that the names could contain / and .. Allowing them does look more convenient though. To support that there is at least one more bug #301. edit: I think that can be a separate PR though

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that case can be covered if we just iteratively strip off the trailing separators, but I considered it as a further enhancement (since I didn't expect we would fail in that case: #301 (comment))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by the way, if we're not sure if we want to support the case where there are trailing slashes in general we can modify the change in this commit d311e0c and go back to just making the exception for the root namespace (maybe error in other cases).

@dhood
Copy link
Copy Markdown
Member Author

dhood commented Sep 20, 2018

From what I've seen, the tests only check that files are parsed. I didn't add a test since the files are going to be parsed fine in either case, they just won't apply to the node correctly. I'll take another look if any tests check what would be passed to rcl.

@mikaelarguedas
Copy link
Copy Markdown
Member

The design document seems to say that a name/namespace should not end with a slash. The implementation does assume that no namespace entry means root namespace. I'm not convinced specifying "/" as a namespace should be supported (at least in the current specification)

@dhood
Copy link
Copy Markdown
Member Author

dhood commented Sep 20, 2018

can you clarify where you got that a namespace shouldn't end with a slash? I see it for a topic name. I would expect that it's reasonable for someone to request that a node be put in the / namespace on the command line, which is why I think it should also be do-able from the yaml file

@sloretz
Copy link
Copy Markdown
Contributor

sloretz commented Sep 20, 2018

The design document seems to say that a name/namespace should not end with a slash.

It does refer to / as a legal namespace later on

 In another example, the name /foo splits into one token, such that it is composed of a topic or service with the base name foo in the / namespace (the root namespace).

I think remapping allows / too, ex __ns:=/

@mikaelarguedas
Copy link
Copy Markdown
Member

My understanding was that this section was referring to namespaces (otherwise it would just be a duplicated version of the constraints on the topic names from the beginning of the document with a lot of constraints omitted)

Namespaces
Topic and service names:

may be split into tokens using a forward slash (/) as a delimiter

see the “Name Tokens” section for more details on tokens
must not end with a forward slash (/)

If not I think we should update that document so that the namespace section defines the constraints of a namespace and add to the list of valid examples the single / namespace as it currently only shows that namespace "None" would expand to /.

Not saying that it shouldn't be possible to pass the / namespace to nodes (via commandline or file) but that the design doc was not clear to me.

@dhood
Copy link
Copy Markdown
Member Author

dhood commented Sep 20, 2018

regression test added in 27fe5ac

@dhood
Copy link
Copy Markdown
Member Author

dhood commented Sep 21, 2018

  • Linux Build Status
  • Linux-aarch64 Build Status
  • macOS Build Status
  • Windows Build Status

@dhood dhood merged commit f1293b7 into master Sep 21, 2018
@dhood dhood deleted the root_ns_fix branch September 21, 2018 21:50
@dhood dhood removed the in review Waiting for review (Kanban column) label Sep 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants