cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1398
Views
0
Helpful
3
Replies

Validate yang model by custom rules

DTtb
Level 1
Level 1

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.

3 Replies 3

uavsec001
Level 1
Level 1

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). 

gmuloche
Cisco Employee
Cisco Employee

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"?

 

 

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.