59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
import xml.etree.ElementTree as ET
|
|
|
|
import pytest
|
|
|
|
from exporter.netconf_client import parse_netconf_response
|
|
|
|
|
|
RUJIE_SAMPLE_XML = """\
|
|
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
|
|
<data>
|
|
<components xmlns="http://openconfig.net/yang/platform">
|
|
<component>
|
|
<name>TRANSCEIVER-1/0/129-FH0/1:1</name>
|
|
<state>
|
|
<type>TRANSCEIVER</type>
|
|
</state>
|
|
<transceiver xmlns="http://openconfig.net/yang/platform/transceiver">
|
|
<state>
|
|
<serial-no>ABC123</serial-no>
|
|
</state>
|
|
<physical-channels>
|
|
<channel>
|
|
<index>1</index>
|
|
<state>
|
|
<description>TRANSCEIVER-1/0/129/1-FH0/1:1</description>
|
|
</state>
|
|
</channel>
|
|
</physical-channels>
|
|
</transceiver>
|
|
</component>
|
|
</components>
|
|
</data>
|
|
</rpc-reply>
|
|
"""
|
|
|
|
|
|
def test_vendor_none_with_ruijie_sample_uses_h3c_strategy():
|
|
txs, chs = parse_netconf_response(RUJIE_SAMPLE_XML, "dev-rj", vendor=None)
|
|
assert len(chs) == 1
|
|
ch = chs[0]
|
|
# H3C 默认策略:冒号前为端口
|
|
assert ch.logical_port == "TRANSCEIVER-1/0/129/1-FH0/1"
|
|
assert ch.logical_channel == "TRANSCEIVER-1/0/129/1-FH0/1:1"
|
|
|
|
|
|
def test_vendor_none_to_ruijie_changes_labels():
|
|
_, chs_none = parse_netconf_response(RUJIE_SAMPLE_XML, "dev-rj", vendor=None)
|
|
_, chs_ruijie = parse_netconf_response(RUJIE_SAMPLE_XML, "dev-rj", vendor="ruijie")
|
|
|
|
assert len(chs_none) == len(chs_ruijie) == 1
|
|
ch_none = chs_none[0]
|
|
ch_rj = chs_ruijie[0]
|
|
|
|
assert ch_none.logical_port.startswith("TRANSCEIVER-")
|
|
# Ruijie 策略应清洗出短端口 FH0/1
|
|
assert ch_rj.logical_port == "FH0/1"
|
|
assert ch_rj.logical_channel == "FH0/1:1"
|
|
|