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

tools, vtysh: add the cli write callback, unhide an NB show command #14764

Merged
merged 3 commits into from
Jan 30, 2024

Conversation

mjstapp
Copy link
Contributor

@mjstapp mjstapp commented Nov 9, 2023

Add the cli_show (config write) callback when emitting the create or modify callback in the northbound template. These are pretty necessary, and if they're not in the template, they have to be hand-crafted. Also unhide the "show configuration running" cli that interrogates the NB: this is pretty darn useful when doing NB work, and it's hard to use if it's hidden.

The CI checkpatch script complains because I've added the bare copyright line to the auto-gen nb template file.

@mjstapp
Copy link
Contributor Author

mjstapp commented Nov 9, 2023

CI:rerun

Copy link
Contributor

@idryzhov idryzhov left a comment

Choose a reason for hiding this comment

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

I don't think this is correct. Config output is context-specific – sometimes we implement a single callback for the whole container and sometimes we implement it for leafs but not the container. We shouldn't blindly generate the code for all containers and leafs in a schema.

@mjstapp
Copy link
Contributor Author

mjstapp commented Nov 10, 2023

Sure - I was just trying to extend the example that's already there. It's useful (at least, I found it useful) to have the auto-gen tool emit the xpaths, and offer the core callbacks. I don't disagree that not every node needs a config-cli callback - but not every node needs all of the other callbacks either? I found that using the auto-generated template as a reference helped me see how the tooling was seeing changes I made to a model; perhaps that's more helpful to newbies than to real first-class yang-ers? But it was helpful, and it was easier to skip 'write' callbacks that I didn't need than to manually add them in.

I don't think this is correct. Config output is context-specific – sometimes we implement a single callback for the whole container and sometimes we implement it for leafs but not the container. We shouldn't blindly generate the code for all containers and leafs in a schema.

@idryzhov
Copy link
Contributor

Actually all other generated callbacks are required. If they are not defined then daemon fails on initialization. But anyway your idea sounds reasonable. How about we add some comment before the callback definition mentioning that it's optional and can be deleted if not needed? Also, can we change cli_write to cli_show. Most (if not all) of the code uses something_cli_show as function names.

@mjstapp
Copy link
Contributor Author

mjstapp commented Nov 10, 2023

sure, I'll add a comment and push an update.

I'm glad you asked about that callback name - I did want to raise the question about the existing convention. I've found the "show" function name confusing: we really use "show" to mean "show operational state", to mean "show xxx" cli commands. These callbacks don't have anything to do with oper state - just the opposite - and now that we're trying to talk about incorporating state retrieval into the northbound, it seemed like an opportunity to try to make the naming less ambiguous. What do you think about that?

Actually all other generated callbacks are required. If they are not defined then daemon fails on initialization. But anyway your idea sounds reasonable. How about we add some comment before the callback definition mentioning that it's optional and can be deleted if not needed? Also, can we change cli_write to cli_show. Most (if not all) of the code uses something_cli_show as function names.

@mjstapp
Copy link
Contributor Author

mjstapp commented Nov 10, 2023

When I look at it, a comment per function is kind of a lot - would a single comment at the top of the output be enough, do you think? Or is it better to have each generated line get the comment? Here's an example:

{
	.xpath = "/frr-nexthop:frr-nexthop-group/nexthop-groups/frr-nexthops/nexthop/weight",
	.cbs = {
		.modify = frr_nexthop_group_nexthop_groups_frr_nexthops_nexthop_weight_modify,
		/* Note: this cli callback is optional; the cli output may not need to be done at each node. */
		.cli_show = cli_write_frr_nexthop_group_nexthop_groups_frr_nexthops_nexthop_weight,
		.destroy = frr_nexthop_group_nexthop_groups_frr_nexthops_nexthop_weight_destroy,
	}
},

Actually all other generated callbacks are required. If they are not defined then daemon fails on initialization. But anyway your idea sounds reasonable. How about we add some comment before the callback definition mentioning that it's optional and can be deleted if not needed? Also, can we change cli_write to cli_show. Most (if not all) of the code uses something_cli_show as function names.

@idryzhov
Copy link
Contributor

Okay, cli_write naming sounds good, thanks. Regarding the comment, how about we put it inside the function prototype in generate_config_write_callback? You already have TODO: implement me. comment there, just mention that it is actually optional.

@mjstapp
Copy link
Contributor Author

mjstapp commented Nov 13, 2023

sounds good - I've pushed a change that updates the comment in the generated 'write' function.

@mjstapp
Copy link
Contributor Author

mjstapp commented Nov 13, 2023

retrying CI...

@mjstapp
Copy link
Contributor Author

mjstapp commented Nov 13, 2023

CI:rerun

@frrbot frrbot bot added the documentation label Nov 21, 2023
@github-actions github-actions bot added size/L rebase PR needs rebase and removed size/M labels Nov 21, 2023
@mjstapp
Copy link
Contributor Author

mjstapp commented Nov 21, 2023

Added a doc entry too, after some discussion at today's dev meeting.

@mjstapp
Copy link
Contributor Author

mjstapp commented Nov 30, 2023

Rebasing, let's see if we can get through CI now

@mjstapp
Copy link
Contributor Author

mjstapp commented Dec 5, 2023

CI:rerun

@mjstapp
Copy link
Contributor Author

mjstapp commented Dec 12, 2023

Hi @idryzhov I think CI has finally passed - the 'checkout' error is from the presence of the copyright string for the auto-generated skeleton file.

Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@mjstapp
Copy link
Contributor Author

mjstapp commented Jan 12, 2024

rebased to current master, resolved conflicts

@mjstapp
Copy link
Contributor Author

mjstapp commented Jan 23, 2024

@idryzhov any chance you could re-visit this one?

@idryzhov
Copy link
Contributor

idryzhov commented Jan 25, 2024

Hi Mark, sorry for the late response. I actually used this code to generate callbacks for my zebra conversion. It helps and overall works fine.

I have two suggestions:

  1. Let's move cli_write to the end of the function name. Currently, all configuration callbacks look like: lib_interface_zebra_multicast_modify/create/etc and this new callback is cli_write_lib_interface_zebra_multicast. Would be better to have lib_interface_zebra_multicast_cli_write.
  2. As we're actively working on mgmtd conversion, we now have configuration and CLI callbacks in different structures. For example, you can look at staticd - in static_nb.c we have configuration callbacks and in static_vty.c we have CLI callbacks. So it may be more convenient if the generator prints them as two different structures as well.

@mjstapp
Copy link
Contributor Author

mjstapp commented Jan 25, 2024

Thanks: I'll move the _cli_write to be a suffix, sure.

I didn't understand exactly what you'd like in your (2) though. It looks like staticd has two structs with the same name, in two different modules. that seems a little weird? but staticd aside, are you saying you'd like the tool to generate two module_info structs - one with cli_show, cli_cmp, and cli_show_end (if generated), and another with everything else that's generated?

[...] I have two suggestions:

1. Let's move `cli_write` to the end of the function name. Currently, all configuration callbacks look like: `lib_interface_zebra_multicast_modify/create/etc` and this new callback is `cli_write_lib_interface_zebra_multicast`. Would be better to have `lib_interface_zebra_multicast_cli_write`.

2. As we're actively working on mgmtd conversion, we now have configuration and CLI callbacks in different structures. For example, you can look at staticd - in `static_nb.c` we have configuration callbacks and in `static_vty.c` we have CLI callbacks. So it may be more convenient if the generator prints them as two different structures as well.

@idryzhov
Copy link
Contributor

idryzhov commented Jan 25, 2024

I agree the naming is confusing, the second one is going to be renamed to frr_staticd_cli_info. So yes, it would be convenient to have two separate structures - frr_daemon_info with config callbacks and frr_daemon_cli_info with cli_show/show_end/cmp callbacks.

@mjstapp
Copy link
Contributor Author

mjstapp commented Jan 25, 2024

ok, got that: do you want the cli_show_end and cli_cmp callbacks to be generated now? the current code is only doing the 'write' callback (and prototype, etc).

I agree the naming is confusing, the second one is going to be renamed to frr_staticd_cli_info. So yes, it would be convenient to have two separate structures - frr_daemon_info with config callbacks and frr_daemon_cli_info with cli_show/show_end/cmp callbacks.

@idryzhov
Copy link
Contributor

No, I think cli_show is enough. Others are rarely used, so I think it would be less convenient to have them in the output.

@mjstapp
Copy link
Contributor Author

mjstapp commented Jan 26, 2024

argh - needed to finish rebasing, not leave a temp commit hanging out...

@mjstapp
Copy link
Contributor Author

mjstapp commented Jan 26, 2024

ok, what's present now should include those changes...

No, I think cli_show is enough. Others are rarely used, so I think it would be less convenient to have them in the output.

@mjstapp
Copy link
Contributor Author

mjstapp commented Jan 29, 2024

looks like CI has passed now?

@idryzhov
Copy link
Contributor

@mjstapp everything is good now, thanks for the updates!

But we need to update yang_module_load(argv[0]) call on line 462 to yang_module_load(argv[0], NULL) due to recent changes in master. Otherwise it doesn't build.

Mark Stapp added 3 commits January 30, 2024 08:09
Add the cli_show (config write) callback when emitting the
create or modify callback in the northbound template. Split
the config-handling and config-output callbacks into two
structs/arrays; this seems to be helpful when doing mgmtd
conversion.

Signed-off-by: Mark Stapp <[email protected]>
The "show configuration running" cli is pretty useful when
doing NB work; unhide it so it's easier to use.

Signed-off-by: Mark Stapp <[email protected]>
Add a doc entry for the newly-unhidden 'show configuration
running ...' command.

Signed-off-by: Mark Stapp <[email protected]>
@mjstapp
Copy link
Contributor Author

mjstapp commented Jan 30, 2024

and rebased again, to catch up with current master

@idryzhov idryzhov merged commit 2a572ba into FRRouting:master Jan 30, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants