2017-03-06 94 views
1

。我想知道为什么不放错误?它确实如果我使用了错误的前缀。为什么在这种情况下,当条件指的是一个不存在的节点时,为什么在这种情况下不会出现错误

请问您可以查看何时条件(嵌入模块中)。

是否允许(在表达式中)引用架构中的扩展本身?

module mod-w-1 { 
    namespace "http://example.org/tests/mod-w-1"; 
    prefix m1; 

    container m1 { 
    leaf b1 { 
     type string; 
    } 
    } 
} 

module when-tests { 
    namespace "http://example.org/tests/when-tests"; 
    prefix wt; 

    import mod-w-1 { 
    prefix m1; 
    } 

    augment "/m1:m1" { 
     // when "/m1:m1/b3 = 'abc'"; 
     // there is no b3, so, should be invalid. 

     // when "/m1:m1/b1 = 'abc'"; 
     // a payload or data situation that has m1/b1 != 'abc' will cause the 
     // data that fits this augment content will be invalid/rejected. 
     /* for ex; 
      <m1> 
      <b1>fff</b1> 
      <x>sfsf</x> 
      <conditional> 
       <foo>dddd</foo> 
      </conditional> 
      </m1> 
      is invalid, hence, the <x> and <conditional> parts will be 
      rejected. 
     */ 
     leaf x { 
     type string; 
     } 
     container conditional { 
      leaf foo { 
       type string; 
      } 
     } 
    } 
} 

回答

1

这是因为pyang完全不验证XPath表达式的语义,只有他们的语法 - 和几个额外的检查,如函数和前缀使用。您将需要另一个YANG编译器来正确验证这些编译器。

def v_xpath(ctx, stmt): 
    try: 
     toks = xpath.tokens(stmt.arg) 
     for (tokname, s) in toks: 
      if tokname == 'name' or tokname == 'prefix-match': 
       i = s.find(':') 
       if i != -1: 
        prefix = s[:i] 
        prefix_to_module(stmt.i_module, prefix, stmt.pos, 
            ctx.errors) 
      elif tokname == 'literal': 
       # kind of hack to detect qnames, and mark the prefixes 
       # as being used in order to avoid warnings. 
       if s[0] == s[-1] and s[0] in ("'", '"'): 
        s = s[1:-1] 
        i = s.find(':') 
        # make sure there is just one : present 
        if i != -1 and s[i+1:].find(':') == -1: 
         prefix = s[:i] 
         # we don't want to report an error; just mark the 
         # prefix as being used. 
         my_errors = [] 
         prefix_to_module(stmt.i_module, prefix, stmt.pos, 
             my_errors) 
         for (pos, code, arg) in my_errors: 
          if code == 'PREFIX_NOT_DEFINED': 
           err_add(ctx.errors, pos, 
             'WPREFIX_NOT_DEFINED', arg) 
      elif ctx.lax_xpath_checks == True: 
       pass 
      elif tokname == 'variable': 
       err_add(ctx.errors, stmt.pos, 'XPATH_VARIABLE', s) 
      elif tokname == 'function': 
       if not (s in xpath.core_functions or 
         s in yang_xpath_functions or 
         (stmt.i_module.i_version != '1' and 
         s in yang_1_1_xpath_functions) or 
         s in extra_xpath_functions): 
        err_add(ctx.errors, stmt.pos, 'XPATH_FUNCTION', s) 
    except SyntaxError as e: 
     err_add(ctx.errors, stmt.pos, 'XPATH_SYNTAX_ERROR', e) 

Line 1993 of statements.py

请注意,引用不存在节点的XPath表达式在技术上不是无效的,而不是从XPath规范的角度来看。这只是意味着一个空节点集将通过位置路径选择(和你的病情会false永远)。

是的,您可以引用位于扩展的目标节点“上方”或是其兄弟的节点 - 实际上,当语句处于运行状态时(应该不会引用由它作为条件的任何节点) 。另外,您不应该尝试用非前缀节点测试(例如b3b1)打破“模块限制”。 XPath表达式只能看到在定义模块和定义模块本身的导入中定义的名称。例如,即使b3后来被一些不知名的第三个模块的增强,你的病情仍然会评估为false。最好假定非前缀名属于定义模块的名称空间。

+0

嗨,谢谢。有什么方法可以直接与您联系。我可能需要咨询(我将支付)的几个小时,你似乎是积极帮助杨相关问题的唯一一个。 – user19937

+0

是否有其他的阳工具超出了刚刚提供的阳工具。我知道libyang,但是,我需要一个被认可的,被称为阳1.1兼容和可靠的。有没有(不是说libyang不是那些,我只想听到一个知道第一手的人)? – user19937

+0

@ user19937,哦,我不是唯一一个 - 我只是恰好是第一个回答,我只回答我知道我可以回答的问题。 NETMOD WG最近已经开始[编译](http://www.claise.be/IETFYANGPageCompilation.html)他们几个编译器(检查列表)模块,虽然我不知道他们是否是1.1兼容。有NETCONF /杨与实现的列表[这里](https://trac.ietf.org/trac/netconf)。我知道MG-SOFT有杨工具链(包括IDE),已经开始推出支持1.1和验证XPath表达式(免责声明:我的员工)。 – predi

相关问题