ConfD User Community

Put submodule yang files in the same directory as the module

Normally, when I have submodule yang files, I will put these files into a directory which is named as the module name, and this directory will be in the same level as module, e.g.

network.yang
network :
      -- network_sub0.yang
      -- network_sub1.yang

This structure is clear and works well when I compile these yang files using confdc.
But in some cases for some reasons, which I can’t create a directory for these submodules, I have put the submodules at the same level as module:

network.yang
network_sub0.yang
network_sub1.yang 

I try to compiled and I got errors like

error: cannot compile submodules; compile the module instead

But finally I think the compilation still succeed. I restart confd and I think I can see the proper structure thru confd_cli.
So I want to confirm putting submodule yang files in the same directory as the module is legal, there should not be any problem for compilation/load although I got error message during compilation, correct ?

Thanks.

This is not because you have the submodules in the same directory as the main module per se, but because (as the error message says) you attempt to compile the submodules “themselves”. I.e. you have some Makefile or script that amounts to “compile all files in this directory that have a name ending in .yang”. E.g. confdc -c network_sub0.yang will report that error (and do nothing) if network_sub0.yang is a submodule. You can have a look at $CONFD_DIR/src/confd/yang/Makefile in the release for a way to avoid such compilation without having to explicitly list all “main” modules (or submodules).

You can put the submodules wherever you want as long as it is in a directory included in the path that the compiler searches when the main module is compiled. I would say that having the submodules in the same directory as the main module is the norm, and the current directory (".") is included in the search path by default - for your “submodules in a subdirectory” structure, you need to add the name of the subdirectory via the --yangpath option. Also, regarding “load”, note that the compilation creates a single .fxs file for the main module and all its submodules - i.e. the submodules aren’t loaded as such.

I checked the $CONFD_DIR/src/confd/yang/Makefile, it is helpful.
Thanks very much.