09-04-2019 06:45 AM - edited 09-04-2019 06:46 AM
Hi all,
I want to validate the yang model by custom rules additonally to the default rules.
For example:
1. I want to validate, that the description is set with a text inside the yang module.
2. Validate, that a mandatory module is imported
Is it possible?
Example yang model:
module testservice{ namespace "http://example.com/testservice"; prefix testservice; import ietf-inet-types { prefix inet; } import tailf-common { prefix tailf; } import tailf-ncs { prefix ncs; } description "This is a description"; revision 2019-08-13 { description "Initial revision."; } augment /ncs:services { list testservice{ description "What the service is doing"; [Omitted output]
Thanks.
09-05-2019 01:15 AM
Hey,
As I understand you want to make sure that your YANG developer will always write a description and import a specific module?
Hm, I bet you could modify pynag or yang compiler to do that for you (don't ask me how).
09-06-2019 03:33 AM
Hello
1. I want to validate, that the description is set with a text inside the yang module.
In pyang you have a flag --ietf that will check compliance with RFC 8407 (I am using pyang 2.0.1 for pyang shipped with NSO version 1.5 it will be RFC 6087) and it will include the missing description (and probably a lot of other rules you dont really want) cf last line for this specific error
pyang --ietf test.yang test.yang:1: warning: RFC 8407: 4.1: the module name should start with one of the strings "ietf-" or "iana-" test.yang:1: error: RFC 8407: 4.8: statement "module" must have a "contact" substatement test.yang:1: error: RFC 8407: 4.8: statement "module" must have a "organization" substatement test.yang:1: error: RFC 8407: 4.8: statement "module" must have a "description" substatement
...
I am not aware of a similar feature for yanger but I may be wrong.
2. Validate, that a mandatory module is imported
This one I am not really sure what you are looking for - either you import a module that is used and you get no error (for this ) while compiling OR you don't import it and then you have compilation errors because the prefix you will try to use is not defined.
For example if you remove the tailf-ncs import statement and try to compile a module that uses it (e.g. uses ncs:service-data;)
yanger test.yang test.yang:29: error: undefined prefix ncs
So I would tend to say this verification is done for you. Or are you looking for something else when you use the wording "mandatory module"?
09-09-2019 05:47 AM
Thanks for the feedback.
I am validating an option to create custom yang rules to enforce internally commitments, like to set always a description to yang module.
Thanks.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide