【问题标题】:JSNAPY: Is there a way to test on xpath node attributesJSNAPY:有没有办法测试 xpath 节点属性
【发布时间】:2020-02-15 18:28:18
【问题描述】:

我正在尝试确定如何测试 junos 偶尔使用的节点属性。在这种特殊情况下,我想查找在 20w 和 1y 之间关闭的所有 BGP 会话。秒值包含在节点属性中,但我无法弄清楚如何访问它以进行测试。

我已经尝试了使用整个显式 xpath 的各种方法,一直到我在代码下面的内容。

这是我尝试访问的 xpath(为简洁而编辑):

<rpc-reply xmlns:junos="http://xml.juniper.net/junos/18.2R3/junos">
    <bgp-information xmlns="http://xml.juniper.net/junos/18.2R3/junos-routing">
        <bgp-peer junos:style="terse" heading="Peer                     AS      InPkt     OutPkt    OutQ   Flaps Last Up/Dwn State|#Active/Received/Accepted/Damped...">
            <elapsed-time junos:seconds="263788">3d 1:16:28</elapsed-time>
        </bgp-peer>
    </bgp-information>
</rpc-reply>
test_bgp_summ:
  - rpc: get-bgp-summary-information
  - iterate:
      xpath: /bgp-information/bgp-peer
      id: ./peer-address
      tests:
        - in-range: //@junos:seconds, 12096000, 31449600
          err: ""
          info: 'Peer session <{{id_0}}> is likely stale'

【问题讨论】:

    标签: xpath junos-automation pyez


    【解决方案1】:

    您需要在测试中包含经过时间节点:

    show_bgp_sum:
      - command: show bgp summary
      - iterate:
          xpath: '//bgp-information/bgp-peer'
          id: ./peer-address
          tests:
            - exists: elapsed-time/@seconds
              err: "elpased-time doesn't exist"
              info: "Elapsed-time is: <{{post['elapsed-time/@seconds']}}>"
    

    和输出:

                       "passed": [
                            {
                                "actual_node_value": "1309804", 
                                "id": {
                                    "./peer-address": "10.10.12.100"
                                }, 
                                "message": "Elapsed-time is: <1309804>", 
                                "post": {
                                    "elapsed-time/@seconds": "1309804"
                                }, 
                                "pre": {
                                    "elapsed-time/@seconds": "1309802"
                                }
                            }, 
    

    【讨论】:

      最近更新 更多