JSNAPY:有没有办法测试 xpath 节点属性
JSNAPY: Is there a way to test on xpath node attributes
我正在尝试确定如何测试 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'
您需要在测试中包含运行时间节点:
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"
}
},
我正在尝试确定如何测试 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'
您需要在测试中包含运行时间节点:
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"
}
},