2017-03-06 93 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

相關問題