scrapli / scrapli_netconf

Fast and flexible Python 3.7+ netconf client specifically for network devices
https://scrapli.github.io/scrapli_netconf/
MIT License
92 stars 6 forks source link

Error message in netconf get parsing #142

Closed hroyd closed 5 months ago

hroyd commented 6 months ago

Hello,

We switched from nclient to scrapli for netconf operations. We issue a get request against a Nokia router for the card state, which contains some text with special characters, and this causes scrapli to throw an error message presumable in lxml parsing. The response.xml_result is exactly what we expect, but do not want to see that error message, or think it needs to be handled better in some way?

Thanks

Dean

Return element length invalid, expected 303 got 301 for element: b' <software-code-version>TiMOS-B-21.10.R9 both/hops64 Nokia 7750 SR Copyright (c) 2000-2022 Nokia.\nAll rights reserved. All use subject to applicable license agreements.\nBuilt on Wed Nov 30 13:05:52 PST 2022 by builder in /builds/c/2110B/R9/panos/main/sros\n</software-code-version>\n\n'

{'channel_input': '#258\n'
                  "<?xml version='1.0' encoding='utf-8'?>\n"
                  '<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" '
                  'message-id="102"><get><filter type="subtree"><state '
                  'xmlns="urn:nokia.com:sros:ns:yang:sr:state"><card><slot-number>1</slot-number></card></state></filter></get></rpc>\n'
                  '##',
 'elapsed_time': 0.227452,
 'error_messages': [],
 'failed': True,
 'failed_when_contains': [b'</rpc-error>',
                          b'</rpc-errors>',
                          b'<rpc-error>',
                          b'<rpc-errors>'],
 'finish_time': datetime.datetime(2024, 4, 17, 5, 20, 45, 49055),
 'genie_platform': '',
 'host': 'use1.ab1',
 'netconf_version': <NetconfVersion.VERSION_1_1: '1.1'>,
 'raw_result': b'\n#38\n<?xml version="1.0" encoding="UTF-8"?>\n#1\n\n\n#10'
               b'\n<rpc-reply\n#17\n message-id="102"\n#48\n xmlns="urn:ietf:p'
               b'arams:xml:ns:netconf:base:1.0"\n#1\n>\n#1\n\n\n#11\n    <da'
               b'ta>\n\n#60\n        <state xmlns="urn:nokia.com:sros:ns:yan'
               b'g:sr:state">\n\n#19\n            <card>\n\n#45\n              '
               b'  <slot-number>1</slot-number>\n\n#53\n                <equ'
               b'ipped-type>iom-1</equipped-type>\n\n#50\n                <c'
               b'lock-source>none</clock-source>\n\n#61\n                <av'
               b'ailable-mda-slots>2</available-mda-slots>\n\n#61\n         '
               b'       <installed-mda-slots>2</installed-mda-slots>\n\n#49'
               b'\n                <memory-size>16384</memory-size>\n\n#69\n '
               b'               <last-bootup-reason>hard-reboot</last-bootup-'
               b'reason>\n\n#52\n                <equipped-level>he</equippe'
               b'd-level>\n\n#52\n                <licensed-level>he</licens'
               b'ed-level>\n\n#32\n                <hardware-data>\n\n#62\n    '
               b'                <part-number>3HE12299BARA01</part-number>\n\n#'
               b'63\n                    <serial-number>NS180562392</serial-nu'
               b'mber>\n\n#70\n                    <manufacturing-date>02072'
               b'018</manufacturing-date>\n\n#108\n                    <comm'
               b'on-language-equipment-identifier>INM4D10CRA</common-language'
               b'-equipment-identifier>\n\n#74\n                    <field-r'
               b'eplaceable-unit>true</field-replaceable-unit>\n\n#59\n     '
               b'               <contained-in>Chassis 1</contained-in>\n\n#'
               b'56\n                    <oper-state>in-service</oper-stat'
               b'e>\n\n#54\n                    <failure-reason></failure-re'
               b'ason>\n\n#84\n                    <contains-temperature-sen'
               b'sor>true</contains-temperature-sensor>\n\n#50\n            '
               b'        <temperature>41</temperature>\n\n#70\n             '
               b'       <temperature-threshold>75</temperature-threshold>\n\n#6'
               b'1\n                    <alarm-state>alarm-cleared</alarm-stat'
               b'e>\n\n#74\n                    <manufacturing-deviations></'
               b'manufacturing-deviations>\n\n#83\n                    <equi'
               b'pped-platform-type>platform-7750</equipped-platform-type>\n\n#'
               b'94\n                    <manufacturing-assembly-number>82-110'
               b'3-01</manufacturing-assembly-number>\n\n#65\n              '
               b'      <power-zone-location>1</power-zone-location>\n\n#75\n'
               b'                    <base-mac-address>40:7c:7d:b3:5f:35</bas'
               b'e-mac-address>\n\n#113\n                    <boot-code-vers'
               b'ion>X-21.10.R6 on Wed Aug 17 14:55:03 PDT 2022 by builder</b'
               b'oot-code-version>\n\n#303\n                    <software-co'
               b'de-version>TiMOS-B-21.10.R9 both/hops64 Nokia 7750 SR Copyri'
               b'ght (c) 2000-2022 Nokia.\nAll rights reserved. All use subjec'
               b't to applicable license agreements.\nBuilt on Wed Nov 30 13:0'
               b'5:52 PST 2022 by builder in /builds/c/2110B/R9/panos/main/sr'
               b'os\n</software-code-version>\n\n#94\n                    <so'
               b'ftware-last-boot-time>2024-01-27T21:47:27.0Z</software-last-'
               b'boot-time>\n\n#75\n                    <software-image-sour'
               b'ce>unknown</software-image-source>\n\n#68\n                '
               b'    <firmware-code-version></firmware-code-version>\n\n#84'
               b'\n                    <firmware-revision-status>acceptable</f'
               b'irmware-revision-status>\n\n#33\n                </hardware'
               b'-data>\n\n#22\n                <cpu>\n\n#53\n                 '
               b'   <sample-period>1</sample-period>\n\n#37\n               '
               b'     <hqos-algorithm>\n\n#49\n                        <cpu-'
               b'time>977</cpu-time>\n\n#51\n                        <cpu-us'
               b'age>0.0</cpu-usage>\n\n#62\n                        <capaci'
               b'ty-usage>0.09</capacity-usage>\n\n#38\n                    '
               b'</hqos-algorithm>\n\n#38\n                    <hqos-statist'
               b'ics>\n\n#50\n                        <cpu-time>3221</cpu-ti'
               b'me>\n\n#52\n                        <cpu-usage>0.02</cpu-us'
               b'age>\n\n#62\n                        <capacity-usage>0.32</'
               b'capacity-usage>\n\n#39\n                    </hqos-statisti'
               b'cs>\n\n#26\n                    <iom>\n\n#53\n                '
               b'        <cpu-time>2809170</cpu-time>\n\n#53\n              '
               b'          <cpu-usage>17.61</cpu-usage>\n\n#63\n            '
               b'            <capacity-usage>94.49</capacity-usage>\n\n#27\n'
               b'                    </iom>\n\n#30\n                    <sum'
               b'mary>\n\n#32\n                        <total>\n\n#58\n        '
               b'                    <cpu-time>15951767</cpu-time>\n\n#57\n '
               b'                           <cpu-usage>100.0</cpu-usage>\n\n#33'
               b'\n                        </total>\n\n#31\n                 '
               b'       <idle>\n\n#58\n                            <cpu-time'
               b'>13138399</cpu-time>\n\n#57\n                            <c'
               b'pu-usage>82.36</cpu-usage>\n\n#32\n                        '
               b'</idle>\n\n#32\n                        <usage>\n\n#57\n      '
               b'                      <cpu-time>2813368</cpu-time>\n\n#57\n'
               b'                            <cpu-usage>17.63</cpu-usage>\n\n#3'
               b'3\n                        </usage>\n\n#51\n                '
               b'        <busiest-core-utilization>\n\n#56\n                '
               b'            <cpu-time>669403</cpu-time>\n\n#57\n           '
               b'                 <cpu-usage>67.13</cpu-usage>\n\n#52\n     '
               b'                   </busiest-core-utilization>\n\n#31\n    '
               b'                </summary>\n\n#23\n                </cpu>\n\n'
               b'#22\n                <cpu>\n\n#54\n                    <samp'
               b'le-period>60</sample-period>\n\n#37\n                    <h'
               b'qos-algorithm>\n\n#51\n                        <cpu-time>57'
               b'353</cpu-time>\n\n#51\n                        <cpu-usage>0'
               b'.0</cpu-usage>\n\n#62\n                        <capacity-us'
               b'age>0.09</capacity-usage>\n\n#38\n                    </hqo'
               b's-algorithm>\n\n#38\n                    <hqos-statistics>\n'
               b'\n#52\n                        <cpu-time>175023</cpu-time>'
               b'\n\n#52\n                        <cpu-usage>0.01</cpu-usage'
               b'>\n\n#62\n                        <capacity-usage>0.29</cap'
               b'acity-usage>\n\n#39\n                    </hqos-statistics>'
               b'\n\n#26\n                    <iom>\n\n#54\n                   '
               b'     <cpu-time>57550229</cpu-time>\n\n#52\n                '
               b'        <cpu-usage>6.01</cpu-usage>\n\n#62\n               '
               b'         <capacity-usage>7.63</capacity-usage>\n\n#27\n    '
               b'                </iom>\n\n#30\n                    <summary'
               b'>\n\n#32\n                        <total>\n\n#59\n            '
               b'                <cpu-time>957086533</cpu-time>\n\n#57\n    '
               b'                        <cpu-usage>100.0</cpu-usage>\n\n#3'
               b'3\n                        </total>\n\n#31\n                '
               b'        <idle>\n\n#59\n                            <cpu-tim'
               b'e>899303928</cpu-time>\n\n#57\n                            '
               b'<cpu-usage>93.96</cpu-usage>\n\n#32\n                      '
               b'  </idle>\n\n#32\n                        <usage>\n\n#58\n    '
               b'                        <cpu-time>57782605</cpu-time>\n\n#'
               b'56\n                            <cpu-usage>6.03</cpu-usag'
               b'e>\n\n#33\n                        </usage>\n\n#51\n          '
               b'              <busiest-core-utilization>\n\n#57\n          '
               b'                  <cpu-time>6231646</cpu-time>\n\n#57\n    '
               b'                        <cpu-usage>10.41</cpu-usage>\n\n#5'
               b'2\n                        </busiest-core-utilization>\n\n#'
               b'31\n                    </summary>\n\n#23\n                <'
               b'/cpu>\n\n#22\n                <cpu>\n\n#55\n                  '
               b'  <sample-period>300</sample-period>\n\n#37\n              '
               b'      <hqos-algorithm>\n\n#52\n                        <cpu'
               b'-time>283762</cpu-time>\n\n#51\n                        <cp'
               b'u-usage>0.0</cpu-usage>\n\n#62\n                        <ca'
               b'pacity-usage>0.09</capacity-usage>\n\n#38\n                '
               b'    </hqos-algorithm>\n\n#38\n                    <hqos-sta'
               b'tistics>\n\n#52\n                        <cpu-time>876259</'
               b'cpu-time>\n\n#52\n                        <cpu-usage>0.01</'
               b'cpu-usage>\n\n#62\n                        <capacity-usage>'
               b'0.29</capacity-usage>\n\n#39\n                    </hqos-st'
               b'atistics>\n\n#26\n                    <iom>\n\n#55\n          '
               b'              <cpu-time>269941096</cpu-time>\n\n#52\n      '
               b'                  <cpu-usage>5.64</cpu-usage>\n\n#61\n     '
               b'                   <capacity-usage>7.7</capacity-usage>\n\n#27'
               b'\n                    </iom>\n\n#30\n                    <su'
               b'mmary>\n\n#32\n                        <total>\n\n#59\n       '
               b'                     <cpu-time>490504188</cpu-time>\n\n#57'
               b'\n                            <cpu-usage>100.0</cpu-usage'
               b'>\n\n#33\n                        </total>\n\n#31\n           '
               b'             <idle>\n\n#59\n                            <cp'
               b'u-time>219403071</cpu-time>\n\n#57\n                       '
               b'     <cpu-usage>94.33</cpu-usage>\n\n#32\n                 '
               b'       </idle>\n\n#32\n                        <usage>\n\n#59'
               b'\n                            <cpu-time>271101117</cpu-time>\n'
               b'\n#56\n                            <cpu-usage>5.66</cpu-usage>'
               b'\n\n#33\n                        </usage>\n\n#51\n            '
               b'            <busiest-core-utilization>\n\n#58\n            '
               b'                <cpu-time>25854440</cpu-time>\n\n#56\n     '
               b'                       <cpu-usage>8.64</cpu-usage>\n\n#52\n'
               b'                        </busiest-core-utilization>\n\n#31'
               b'\n                    </summary>\n\n#23\n                </c'
               b'pu>\n\n#31\n                <memory-pools>\n\n#26\n           '
               b'         <iom>\n\n#64\n                        <current-siz'
               b'e>4153409536</current-size>\n\n#60\n                       '
               b' <max-so-far>4417650688</max-so-far>\n\n#52\n              '
               b'          <in-use>4003125808</in-use>\n\n#27\n             '
               b'       </iom>\n\n#30\n                    <summary>\n\n#76\n  '
               b'                      <current-total-size>4153409536</curren'
               b't-total-size>\n\n#64\n                        <total-in-use'
               b'>4003125808</total-in-use>\n\n#73\n                        '
               b'<available-memory>11629756416</available-memory>\n\n#31\n  '
               b'                  </summary>\n\n#32\n                </memo'
               b'ry-pools>\n\n#40\n                <subscriber-management>\n\n'
               b'#33\n                    <statistics>\n\n#37\n              '
               b'          <ipv4-hosts>\n\n#52\n                            '
               b'<counter>ipcp</counter>\n\n#61\n                           '
               b' <current-value>0</current-value>\n\n#38\n                 '
               b'       </ipv4-hosts>\n\n#37\n                        <ipv4-'
               b'hosts>\n\n#52\n                            <counter>dhcp</c'
               b'ounter>\n\n#61\n                            <current-value>'
               b'0</current-value>\n\n#38\n                        </ipv4-ho'
               b'sts>\n\n#37\n                        <ipv4-hosts>\n\n#51\n    '
               b'                        <counter>arp</counter>\n\n#61\n    '
               b'                        <current-value>0</current-value>\n\n#3'
               b'8\n                        </ipv4-hosts>\n\n#37\n           '
               b'             <ipv4-hosts>\n\n#54\n                         '
               b'   <counter>static</counter>\n\n#61\n                      '
               b'      <current-value>0</current-value>\n\n#38\n            '
               b'            </ipv4-hosts>\n\n#37\n                        <'
               b'ipv4-hosts>\n\n#62\n                            <counter>da'
               b'ta-triggered</counter>\n\n#61\n                            '
               b'<current-value>0</current-value>\n\n#38\n                  '
               b'      </ipv4-hosts>\n\n#37\n                        <ipv4-h'
               b'osts>\n\n#51\n                            <counter>aaa</cou'
               b'nter>\n\n#61\n                            <current-value>0<'
               b'/current-value>\n\n#38\n                        </ipv4-host'
               b's>\n\n#37\n                        <ipv4-hosts>\n\n#51\n      '
               b'                      <counter>gtp</counter>\n\n#61\n      '
               b'                      <current-value>0</current-value>\n\n'
               b'#38\n                        </ipv4-hosts>\n\n#37\n         '
               b'               <ipv4-hosts>\n\n#55\n                       '
               b'     <counter>bonding</counter>\n\n#61\n                   '
               b'         <current-value>0</current-value>\n\n#38\n         '
               b'               </ipv4-hosts>\n\n#37\n                      '
               b'  <ipv4-hosts>\n\n#56\n                            <counter'
               b'>dhcp-bsm</counter>\n\n#61\n                            <cu'
               b'rrent-value>0</current-value>\n\n#38\n                     '
               b'   </ipv4-hosts>\n\n#37\n                        <ipv4-host'
               b's>\n\n#58\n                            <counter>static-bsm<'
               b'/counter>\n\n#61\n                            <current-valu'
               b'e>0</current-value>\n\n#38\n                        </ipv4-'
               b'hosts>\n\n#37\n                        <ipv4-hosts>\n\n#66\n  '
               b'                          <counter>dhcp-bsm-antispoof</count'
               b'er>\n\n#61\n                            <current-value>0</c'
               b'urrent-value>\n\n#38\n                        </ipv4-hosts>'
               b'\n\n#37\n                        <ipv4-hosts>\n\n#68\n        '
               b'                    <counter>static-bsm-antispoof</counter>\n'
               b'\n#61\n                            <current-value>0</current-v'
               b'alue>\n\n#38\n                        </ipv4-hosts>\n\n#37\n  '
               b'                      <ipv4-hosts>\n\n#56\n                '
               b'            <counter>pfcp-ppp</counter>\n\n#61\n           '
               b'                 <current-value>0</current-value>\n\n#38\n '
               b'                       </ipv4-hosts>\n\n#37\n              '
               b'          <ipv4-hosts>\n\n#57\n                            '
               b'<counter>pfcp-ipoe</counter>\n\n#61\n                      '
               b'      <current-value>0</current-value>\n\n#38\n            '
               b'            </ipv4-hosts>\n\n#37\n                        <'
               b'ipv6-hosts>\n\n#57\n                            <counter>pp'
               b'p-slaac</counter>\n\n#61\n                            <curr'
               b'ent-value>0</current-value>\n\n#38\n                       '
               b' </ipv6-hosts>\n\n#37\n                        <ipv6-hosts>'
               b'\n\n#60\n                            <counter>ppp-dhcp6-na<'
               b'/counter>\n\n#61\n                            <current-valu'
               b'e>0</current-value>\n\n#38\n                        </ipv6-'
               b'hosts>\n\n#37\n                        <ipv6-hosts>\n\n#60\n  '
               b'                          <counter>ppp-dhcp6-pd</counter>\n\n#'
               b'61\n                            <current-value>0</current-val'
               b'ue>\n\n#38\n                        </ipv6-hosts>\n\n#37\n    '
               b'                    <ipv6-hosts>\n\n#67\n                  '
               b'          <counter>ppp-dhcp6-pd-mngdrt</counter>\n\n#61\n  '
               b'                          <current-value>0</current-value>\n\n'
               b'#38\n                        </ipv6-hosts>\n\n#37\n         '
               b'               <ipv6-hosts>\n\n#58\n                       '
               b'     <counter>ipoe-slaac</counter>\n\n#61\n                '
               b'            <current-value>0</current-value>\n\n#38\n      '
               b'                  </ipv6-hosts>\n\n#37\n                   '
               b'     <ipv6-hosts>\n\n#61\n                            <coun'
               b'ter>ipoe-dhcp6-na</counter>\n\n#61\n                       '
               b'     <current-value>0</current-value>\n\n#38\n             '
               b'           </ipv6-hosts>\n\n#37\n                        <i'
               b'pv6-hosts>\n\n#61\n                            <counter>ipo'
               b'e-dhcp6-pd</counter>\n\n#61\n                            <c'
               b'urrent-value>0</current-value>\n\n#38\n                    '
               b'    </ipv6-hosts>\n\n#37\n                        <ipv6-hos'
               b'ts>\n\n#68\n                            <counter>ipoe-dhcp6'
               b'-pd-mngdrt</counter>\n\n#61\n                            <c'
               b'urrent-value>0</current-value>\n\n#38\n                    '
               b'    </ipv6-hosts>\n\n#37\n                        <ipv6-hos'
               b'ts>\n\n#63\n                            <counter>ipoe-stati'
               b'c-wan</counter>\n\n#61\n                            <curren'
               b't-value>0</current-value>\n\n#38\n                        <'
               b'/ipv6-hosts>\n\n#37\n                        <ipv6-hosts>\n\n'
               b'#63\n                            <counter>ipoe-static-pfx</co'
               b'unter>\n\n#61\n                            <current-value>0'
               b'</current-value>\n\n#38\n                        </ipv6-hos'
               b'ts>\n\n#37\n                        <ipv6-hosts>\n\n#66\n     '
               b'                       <counter>ipoe-mngd-data-wan</counter>'
               b'\n\n#61\n                            <current-value>0</curr'
               b'ent-value>\n\n#38\n                        </ipv6-hosts>\n\n#'
               b'37\n                        <ipv6-hosts>\n\n#66\n           '
               b'                 <counter>ipoe-mngd-data-pfx</counter>\n\n'
               b'#61\n                            <current-value>0</current-va'
               b'lue>\n\n#38\n                        </ipv6-hosts>\n\n#37\n   '
               b'                     <ipv6-hosts>\n\n#73\n                 '
               b'           <counter>ipoe-mngd-data-pfx-mngdrt</counter>\n\n#61'
               b'\n                            <current-value>0</current-value'
               b'>\n\n#38\n                        </ipv6-hosts>\n\n#37\n      '
               b'                  <ipv6-hosts>\n\n#61\n                    '
               b'        <counter>ipoe-mngd-aaa</counter>\n\n#61\n          '
               b'                  <current-value>0</current-value>\n\n#38\n'
               b'                        </ipv6-hosts>\n\n#37\n             '
               b'           <ipv6-hosts>\n\n#61\n                           '
               b' <counter>ipoe-mngd-gtp</counter>\n\n#61\n                 '
               b'           <current-value>0</current-value>\n\n#38\n       '
               b'                 </ipv6-hosts>\n\n#37\n                    '
               b'    <ipv6-hosts>\n\n#65\n                            <count'
               b'er>ipoe-mngd-bonding</counter>\n\n#61\n                    '
               b'        <current-value>0</current-value>\n\n#38\n          '
               b'              </ipv6-hosts>\n\n#37\n                       '
               b' <ipv6-hosts>\n\n#65\n                            <counter>'
               b'ipoe-dhcp6-na-bsm</counter>\n\n#61\n                       '
               b'     <current-value>0</current-value>\n\n#38\n             '
               b'           </ipv6-hosts>\n\n#37\n                        <i'
               b'pv6-hosts>\n\n#65\n                            <counter>ipo'
               b'e-dhcp6-pd-bsm</counter>\n\n#61\n                          '
               b'  <current-value>0</current-value>\n\n#38\n                '
               b'        </ipv6-hosts>\n\n#37\n                        <ipv6'
               b'-hosts>\n\n#62\n                            <counter>pfcp-p'
               b'pp-slaac</counter>\n\n#61\n                            <cur'
               b'rent-value>0</current-value>\n\n#38\n                      '
               b'  </ipv6-hosts>\n\n#37\n                        <ipv6-hosts'
               b'>\n\n#59\n                            <counter>pfcp-ppp-na<'
               b'/counter>\n\n#61\n                            <current-valu'
               b'e>0</current-value>\n\n#38\n                        </ipv6-'
               b'hosts>\n\n#37\n                        <ipv6-hosts>\n\n#59\n  '
               b'                          <counter>pfcp-ppp-pd</counter>\n\n#6'
               b'1\n                            <current-value>0</current-valu'
               b'e>\n\n#38\n                        </ipv6-hosts>\n\n#37\n     '
               b'                   <ipv6-hosts>\n\n#63\n                   '
               b'         <counter>pfcp-ipoe-slaac</counter>\n\n#61\n       '
               b'                     <current-value>0</current-value>\n\n#'
               b'38\n                        </ipv6-hosts>\n\n#37\n          '
               b'              <ipv6-hosts>\n\n#60\n                        '
               b'    <counter>pfcp-ipoe-na</counter>\n\n#61\n               '
               b'             <current-value>0</current-value>\n\n#38\n     '
               b'                   </ipv6-hosts>\n\n#37\n                  '
               b'      <ipv6-hosts>\n\n#60\n                            <cou'
               b'nter>pfcp-ipoe-pd</counter>\n\n#61\n                       '
               b'     <current-value>0</current-value>\n\n#38\n             '
               b'           </ipv6-hosts>\n\n#38\n                        <t'
               b'otal-hosts>\n\n#56\n                            <counter>su'
               b'bhosts</counter>\n\n#61\n                            <curre'
               b'nt-value>0</current-value>\n\n#39\n                        '
               b'</total-hosts>\n\n#38\n                        <total-hosts'
               b'>\n\n#51\n                            <counter>ppp</counter'
               b'>\n\n#61\n                            <current-value>0</cur'
               b'rent-value>\n\n#39\n                        </total-hosts>\n'
               b'\n#38\n                        <total-hosts>\n\n#52\n        '
               b'                    <counter>ipoe</counter>\n\n#61\n       '
               b'                     <current-value>0</current-value>\n\n#'
               b'39\n                        </total-hosts>\n\n#38\n         '
               b'               <total-hosts>\n\n#52\n                      '
               b'      <counter>ipv4</counter>\n\n#61\n                     '
               b'       <current-value>0</current-value>\n\n#39\n           '
               b'             </total-hosts>\n\n#38\n                       '
               b' <total-hosts>\n\n#52\n                            <counter'
               b'>ipv6</counter>\n\n#61\n                            <curren'
               b't-value>0</current-value>\n\n#39\n                        <'
               b'/total-hosts>\n\n#38\n                        <total-hosts>'
               b'\n\n#62\n                            <counter>ipv6-pd-mngdr'
               b't</counter>\n\n#61\n                            <current-va'
               b'lue>0</current-value>\n\n#39\n                        </tot'
               b'al-hosts>\n\n#38\n                        <total-hosts>\n\n#5'
               b'6\n                            <counter>l2tp-lac</counter'
               b'>\n\n#61\n                            <current-value>0</cur'
               b'rent-value>\n\n#39\n                        </total-hosts>\n'
               b'\n#38\n                        <total-hosts>\n\n#56\n        '
               b'                    <counter>l2tp-lns</counter>\n\n#61\n   '
               b'                         <current-value>0</current-value>\n\n#'
               b'39\n                        </total-hosts>\n\n#38\n         '
               b'               <total-hosts>\n\n#56\n                      '
               b'      <counter>internal</counter>\n\n#61\n                 '
               b'           <current-value>0</current-value>\n\n#39\n       '
               b'                 </total-hosts>\n\n#38\n                   '
               b'     <total-hosts>\n\n#62\n                            <cou'
               b'nter>nonsub-traffic</counter>\n\n#61\n                     '
               b'       <current-value>0</current-value>\n\n#39\n           '
               b'             </total-hosts>\n\n#38\n                       '
               b' <total-hosts>\n\n#59\n                            <counter'
               b'>dhcp-leases</counter>\n\n#61\n                            '
               b'<current-value>0</current-value>\n\n#39\n                  '
               b'      </total-hosts>\n\n#38\n                        <total'
               b'-hosts>\n\n#60\n                            <counter>dhcp6-'
               b'leases</counter>\n\n#61\n                            <curre'
               b'nt-value>0</current-value>\n\n#39\n                        '
               b'</total-hosts>\n\n#38\n                        <total-hosts'
               b'>\n\n#52\n                            <counter>pfcp</counte'
               b'r>\n\n#61\n                            <current-value>0</cu'
               b'rrent-value>\n\n#39\n                        </total-hosts>'
               b'\n\n#35\n                        <sessions>\n\n#78\n          '
               b'                  <counter>ppp-sessions-total-established</c'
               b'ounter>\n\n#61\n                            <current-value>'
               b'0</current-value>\n\n#36\n                        </session'
               b's>\n\n#35\n                        <sessions>\n\n#75\n        '
               b'                    <counter>ppp-sessions-total-in-setup</co'
               b'unter>\n\n#61\n                            <current-value>0'
               b'</current-value>\n\n#36\n                        </sessions'
               b'>\n\n#35\n                        <sessions>\n\n#72\n         '
               b'                   <counter>ppp-sessions-local-pppoe</counte'
               b'r>\n\n#61\n                            <current-value>0</cu'
               b'rrent-value>\n\n#36\n                        </sessions>\n\n#'
               b'35\n                        <sessions>\n\n#74\n             '
               b'               <counter>ppp-sessions-local-pppoeoa</counter>'
               b'\n\n#61\n                            <current-value>0</curr'
               b'ent-value>\n\n#36\n                        </sessions>\n\n#35'
               b'\n                        <sessions>\n\n#72\n               '
               b'             <counter>ppp-sessions-local-pppoa</counter>\n\n#6'
               b'1\n                            <current-value>0</current-valu'
               b'e>\n\n#36\n                        </sessions>\n\n#35\n       '
               b'                 <sessions>\n\n#75\n                       '
               b'     <counter>ppp-sessions-local-l2tp-lns</counter>\n\n#61'
               b'\n                            <current-value>0</current-value'
               b'>\n\n#36\n                        </sessions>\n\n#35\n        '
               b'                <sessions>\n\n#72\n                        '
               b'    <counter>ppp-sessions-local-total</counter>\n\n#61\n   '
               b'                         <current-value>0</current-value>\n\n#'
               b'36\n                        </sessions>\n\n#35\n            '
               b'            <sessions>\n\n#70\n                            '
               b'<counter>ppp-sessions-lac-pppoe</counter>\n\n#61\n         '
               b'                   <current-value>0</current-value>\n\n#36'
               b'\n                        </sessions>\n\n#35\n              '
               b'          <sessions>\n\n#72\n                            <c'
               b'ounter>ppp-sessions-lac-pppoeoa</counter>\n\n#61\n         '
               b'                   <current-value>0</current-value>\n\n#36'
               b'\n                        </sessions>\n\n#35\n              '
               b'          <sessions>\n\n#70\n                            <c'
               b'ounter>ppp-sessions-lac-pppoa</counter>\n\n#61\n           '
               b'                 <current-value>0</current-value>\n\n#36\n '
               b'                       </sessions>\n\n#35\n                '
               b'        <sessions>\n\n#73\n                            <cou'
               b'nter>ppp-sessions-lac-l2tp-lts</counter>\n\n#61\n          '
               b'                  <current-value>0</current-value>\n\n#36\n'
               b'                        </sessions>\n\n#35\n               '
               b'         <sessions>\n\n#70\n                            <co'
               b'unter>ppp-sessions-lac-total</counter>\n\n#61\n            '
               b'                <current-value>0</current-value>\n\n#36\n  '
               b'                      </sessions>\n\n#35\n                 '
               b'       <sessions>\n\n#79\n                            <coun'
               b'ter>ipoe-sessions-total-established</counter>\n\n#61\n     '
               b'                       <current-value>0</current-value>\n\n#36'
               b'\n                        </sessions>\n\n#35\n              '
               b'          <sessions>\n\n#76\n                            <c'
               b'ounter>ipoe-sessions-total-in-setup</counter>\n\n#61\n     '
               b'                       <current-value>0</current-value>\n\n#36'
               b'\n                        </sessions>\n\n#35\n              '
               b'          <sessions>\n\n#65\n                            <c'
               b'ounter>subscribers-total</counter>\n\n#61\n                '
               b'            <current-value>0</current-value>\n\n#36\n      '
               b'                  </sessions>\n\n#34\n                    <'
               b'/statistics>\n\n#41\n                </subscriber-managemen'
               b't>\n\n#22\n                <mda>\n\n#43\n                    <'
               b'mda-slot>1</mda-slot>\n\n#69\n                    <equipped'
               b'-type>me12-100gb-qsfp28</equipped-type>\n\n#54\n           '
               b'         <maximum-ports>12</maximum-ports>\n\n#56\n        '
               b'            <equipped-ports>12</equipped-ports>\n\n#88\n   '
               b'                 <transmit-timing-selected>not-applicable</t'
               b'ransmit-timing-selected>\n\n#82\n                    <sync-'
               b'if-timing-status>not-applicable</sync-if-timing-status>\n\n#58'
               b'\n                    <capabilities>ethernet</capabilitie'
               b's>\n\n#77\n                    <minimum-channelization>unkn'
               b'own</minimum-channelization>\n\n#77\n                    <m'
               b'aximum-channelization>unknown</maximum-channelization>\n\n'
               b'#59\n                    <maximum-channels>0</maximum-channel'
               b's>\n\n#57\n                    <channels-in-use>0</channels'
               b'-in-use>\n\n#36\n                    <hardware-data>\n\n#66\n '
               b'                       <part-number>3HE12334AARA01</part-num'
               b'ber>\n\n#67\n                        <serial-number>NS19466'
               b'2579</serial-number>\n\n#74\n                        <manuf'
               b'acturing-date>11262019</manufacturing-date>\n\n#112\n      '
               b'                  <common-language-equipment-identifier>IPPA'
               b'ACEBAA</common-language-equipment-identifier>\n\n#78\n     '
               b'                   <field-replaceable-unit>true</field-repla'
               b'ceable-unit>\n\n#60\n                        <contained-in>'
               b'Slot 1</contained-in>\n\n#60\n                        <oper'
               b'-state>in-service</oper-state>\n\n#58\n                    '
               b'    <failure-reason></failure-reason>\n\n#88\n             '
               b'           <contains-temperature-sensor>true</contains-tempe'
               b'rature-sensor>\n\n#54\n                        <temperature'
               b'>48</temperature>\n\n#74\n                        <temperat'
               b'ure-threshold>75</temperature-threshold>\n\n#65\n          '
               b'              <alarm-state>alarm-cleared</alarm-state>\n\n'
               b'#84\n                        <manufacturing-deviations>D04615'
               b'</manufacturing-deviations>\n\n#87\n                       '
               b' <equipped-platform-type>platform-7750</equipped-platform-ty'
               b'pe>\n\n#98\n                        <manufacturing-assembly'
               b'-number>82-1024-02</manufacturing-assembly-number>\n\n#69\n'
               b'                        <power-zone-location>1</power-zone-l'
               b'ocation>\n\n#79\n                        <base-mac-address>'
               b'40:55:82:a1:e5:83</base-mac-address>\n\n#64\n              '
               b'          <boot-code-version></boot-code-version>\n\n#72\n '
               b'                       <software-code-version></software-cod'
               b'e-version>\n\n#98\n                        <software-last-b'
               b'oot-time>2024-01-27T21:48:16.0Z</software-last-boot-time>\n\n#'
               b'79\n                        <software-image-source>unknown</s'
               b'oftware-image-source>\n\n#72\n                        <firm'
               b'ware-code-version></firmware-code-version>\n\n#92\n        '
               b'                <firmware-revision-status>not-applicable</fi'
               b'rmware-revision-status>\n\n#37\n                    </hardw'
               b'are-data>\n\n#33\n                    <egress-xpl>\n\n#65\n   '
               b'                     <error-occurrences>0</error-occurrences'
               b'>\n\n#34\n                    </egress-xpl>\n\n#34\n          '
               b'          <ingress-xpl>\n\n#65\n                        <er'
               b'ror-occurrences>0</error-occurrences>\n\n#35\n             '
               b'       </ingress-xpl>\n\n#44\n                    <subscrib'
               b'er-management>\n\n#37\n                       <statistics>\n'

               <snip>
           '      </card>\n'
           '    </state>\n'
           '  </data>\n'
           '</rpc-reply>\n',
 'start_time': datetime.datetime(2024, 4, 17, 5, 20, 44, 821603),
 'strip_namespaces': False,
 'textfsm_platform': '',
 'xml_input': <Element {urn:ietf:params:xml:ns:netconf:base:1.0}rpc at 0x7fbc6e0f4900>,
 'xml_result': <Element {urn:ietf:params:xml:ns:netconf:base:1.0}rpc-reply at 0x7fbc6688a0c0>}
carlmontanari commented 6 months ago

hey @hroyd 👋

I'm pretty sure this is actually unrelated to lxml parsing -- this result should only ever be set if we dont think the actual chunk size matches what the router told us it should be.

what version of scrapli_netconf are you using? using latest this looks like it "should" work as intended, here is a down and dirty script that takes that chunk and rips out the response parsing bits into a simple little setup:

import re

CHUNK_MATCH_1_1 = re.compile(rb"(?P<size>\d+)\n(?P<content>.*?)^#", flags=re.M | re.S)
RAW = rb"""#303
                    <software-code-version>TiMOS-B-21.10.R9 both/hops64 Nokia 7750 SR Copyright(c) 2000-2022 Nokia.\nAll rights reserved. All use subject to applicable license agreements.\nBuilt on Wed Nov 30 13:05:52 PST 2022 by builder in /builds/c/2110B/R9/panos/main/sros\n</software-code-version>

"""
import re

CHUNK_MATCH_1_1 = re.compile(rb"(?P<size>\d+)\n(?P<content>.*?)^#", flags=re.M | re.S)
RAW = rb"""#303
                    <software-code-version>TiMOS-B-21.10.R9 both/hops64 Nokia 7750 SR Copyright(c) 2000-2022 Nokia.\nAll rights reserved. All use subject to applicable license agreements.\nBuilt on Wed Nov 30 13:05:52 PST 2022 by builder in /builds/c/2110B/R9/panos/main/sros\n</software-code-version>

#"""

def main():
    chunk_matches = re.finditer(pattern=CHUNK_MATCH_1_1, string=RAW)

    for chunk_match in chunk_matches:

        size = int(chunk_match.groupdict().get("size", 0))
        chunk = chunk_match.groupdict().get("content", "")

        actual_size = len(chunk)
        rstripped_size = len(chunk.rstrip())

        trailing_newline_count = actual_size - rstripped_size
        if trailing_newline_count > 1:
            extraneous_trailing_newline_count = trailing_newline_count - 1
        else:
            extraneous_trailing_newline_count = 1
        trimmed_newline_len = actual_size - extraneous_trailing_newline_count

        if rstripped_size == 0:
            actual_size = size

        if size == actual_size:
            print("matches actual")
        elif size == rstripped_size:
            print("matches rstripped")
        elif size == trimmed_newline_len:
            print("matches trimmed")
        else:
            print("no matches")

if __name__ == "__main__":
    main()

tl;dr you can read the comments in the response parsing bits there's a bit of a saga about all this, but I think it should all have been sorted out by now (and appears so in this case or at least I hope).

hroyd commented 6 months ago

Hi Carl

Sorry, I forgot to post the version

scrapli 2024.1.30 scrapli-netconf 2024.1.30

Here is a very simple script to compare ncclient with scrapli for this get operation (i narrowed down the get filter to the problematic part of the response which is some \n escaped string in the tag

from dotenv import load_dotenv
import os
from ncclient import manager
from lxml import etree

load_dotenv()

print("-" * 80)
print("\nNCCLIENT NETCONF EXAMPLE\n")
print("-" * 80)

device = {
    "host": "use2.sm1",
    "port": 22,
    "username": os.getenv('USERNAME'),
    "password": os.getenv('PASSWORD'),
    "hostkey_verify": False,
}

state_filter = '''
<state xmlns="urn:nokia.com:sros:ns:yang:sr:state">
    <card>
        <slot-number>1</slot-number>
            <hardware-data>
                <software-code-version>
                </software-code-version>
            </hardware-data>
    </card>
</state>
'''

dev = manager.connect(**device)
state_xml = dev.get(filter=('subtree', state_filter))   
dev.close_session()

print(state_xml)

print("-" * 80)
print("\nSCRAPLI NETCONF EXAMPLE\n")
print("-" * 80)

from scrapli_netconf.driver import NetconfDriver

device = {
    "host": "use2.sm1",
    "auth_username": os.getenv('USERNAME'),
    "auth_password": os.getenv('PASSWORD'),
    "auth_strict_key": False,
    "port": 22,
}

scrapli_rpc = f'''
<get>
    <filter type="subtree">
        {state_filter}
    </filter>
</get>
'''

conn = NetconfDriver(**device)
conn.open()
state_xml = conn.rpc(scrapli_rpc)
conn.close()

print(state_xml)

This is the result:

--------------------------------------------------------------------------------

NCCLIENT NETCONF EXAMPLE

--------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply message-id="urn:uuid:eda1c8df-e820-4395-add1-f1c364673200" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
    <data>
        <state xmlns="urn:nokia.com:sros:ns:yang:sr:state">
            <card>
                <slot-number>1</slot-number>
                <hardware-data>
                    <software-code-version>TiMOS-B-21.10.R11 both/hops64 Nokia 7750 SR Copyright (c) 2000-2023 Nokia.
All rights reserved. All use subject to applicable license agreements.
Built on Wed Mar 29 16:56:15 PDT 2023 by builder in /builds/c/2110B/R11/panos/main/sros
</software-code-version>
                </hardware-data>
            </card>
        </state>
    </data>
</rpc-reply>
--------------------------------------------------------------------------------

SCRAPLI NETCONF EXAMPLE

--------------------------------------------------------------------------------
Return element length invalid, expected 305 got 303 for element: b'                    <software-code-version>TiMOS-B-21.10.R11 both/hops64 Nokia 7750 SR Copyright (c) 2000-2023 Nokia.\nAll rights reserved. All use subject to applicable license agreements.\nBuilt on Wed Mar 29 16:56:15 PDT 2023 by builder in /builds/c/2110B/R11/panos/main/sros\n</software-code-version>\n\n'
NetconfResponse <Success: False>

ncclient does not have an issue with the response, so indicates to me that the router comms is ok, or at least ncclient is handling it (never had an issue with this until switching), but scrapli gives the error I was posting yesterday

hroyd commented 6 months ago
{'channel_input': '#353\n'
                  "<?xml version='1.0' encoding='utf-8'?>\n"
                  '<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" '
                  'message-id="101"><get><filter type="subtree"><state '
                  'xmlns="urn:nokia.com:sros:ns:yang:sr:state"><card><slot-number>1</slot-number><hardware-data><software-code-version>\n'
                  '                '
                  '</software-code-version></hardware-data></card></state></filter></get></rpc>\n'
                  '##',
 'elapsed_time': 0.007365,
 'error_messages': [],
 'failed': True,
 'failed_when_contains': [b'</rpc-error>',
                          b'</rpc-errors>',
                          b'<rpc-error>',
                          b'<rpc-errors>'],
 'finish_time': datetime.datetime(2024, 4, 18, 1, 33, 25, 67260),
 'genie_platform': '',
 'host': 'use2.sm1',
 'netconf_version': <NetconfVersion.VERSION_1_1: '1.1'>,
 'raw_result': b'\n#38\n<?xml version="1.0" encoding="UTF-8"?>\n#1\n\n\n#10'
               b'\n<rpc-reply\n#17\n message-id="101"\n#48\n xmlns="urn:ietf:p'
               b'arams:xml:ns:netconf:base:1.0"\n#1\n>\n#1\n\n\n#11\n    <da'
               b'ta>\n\n#60\n        <state xmlns="urn:nokia.com:sros:ns:yan'
               b'g:sr:state">\n\n#19\n            <card>\n\n#45\n              '
               b'  <slot-number>1</slot-number>\n\n#32\n                <har'
               b'dware-data>\n\n#305\n                    <software-code-ver'
               b'sion>TiMOS-B-21.10.R11 both/hops64 Nokia 7750 SR Copyright ('
               b'c) 2000-2023 Nokia.\nAll rights reserved. All use subject to '
               b'applicable license agreements.\nBuilt on Wed Mar 29 16:56:15 '
               b'PDT 2023 by builder in /builds/c/2110B/R11/panos/main/sros\n<'
               b'/software-code-version>\n\n#33\n                </hardware-'
               b'data>\n\n#20\n            </card>\n\n#17\n        </state>'
               b'\n\n#12\n    </data>\n\n#12\n</rpc-reply>\n##\n',
 'result': '<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" '
           'message-id="101">\n'
           '  <data>\n'
           '    <state xmlns="urn:nokia.com:sros:ns:yang:sr:state">\n'
           '      <card>\n'
           '        <slot-number>1</slot-number>\n'
           '        <hardware-data>\n'
           '          <software-code-version>TiMOS-B-21.10.R11 both/hops64 '
           'Nokia 7750 SR Copyright (c) 2000-2023 Nokia.\n'
           'All rights reserved. All use subject to applicable license '
           'agreements.\n'
           'Built on Wed Mar 29 16:56:15 PDT 2023 by builder in '
           '/builds/c/2110B/R11/panos/main/sros\n'
           '</software-code-version>\n'
           '        </hardware-data>\n'
           '      </card>\n'
           '    </state>\n'
           '  </data>\n'
           '</rpc-reply>\n',
 'start_time': datetime.datetime(2024, 4, 18, 1, 33, 25, 59895),
 'strip_namespaces': False,
 'textfsm_platform': '',
 'xml_input': <Element {urn:ietf:params:xml:ns:netconf:base:1.0}rpc at 0x7fe2b8d7d300>,
 'xml_result': <Element {urn:ietf:params:xml:ns:netconf:base:1.0}rpc-reply at 0x7fe2b81a9c80>}
carlmontanari commented 6 months ago

you will likely need to figure out what char(s)/parsing is the problem since I cant reproduce this (see the previous comment and the quick script there). drop in to debugger and see what's what. if the length of the chunk doesn't match what the router said then scrapli is going to set the response to failed. so you need to figure out what extra char(s) are in there (and how/where this happened) and/or where this is going wrong in the response parsing.

hroyd commented 6 months ago

Thanks. Will have to do some more testing when I get time, but ay have to park it for a week or two. I was testing on Nokia software version 21 and 22. In 22, there is no issue where the .text has changed a little bit with different escaping of the multiline string. ncclient can handle both though as I said

joshbenz commented 6 months ago

Hi, after some investigation, it appears that scrapli is stripping out carriage returns before comparing sizes and the router is including those characters in its chunk size.

b' <software-code-version>TiMOS-B-21.10.R11 both/hops64 Nokia 7750 SR Copyright (c) 2000-2023 Nokia.\r\nAll rights reserved. All use subject to applicable license agreements.\r\nBuilt on Wed Mar 29 16:56:15 PDT 2023 by builder in /builds/c/2110B/R11/panos/main/sros\r\n</software-code-version>\n

In the case of the version, this appears to account for the loss of the 3 characters.

Scrapli sees the following: #305\n <software-code-version>TiMOS-B-21.10.R11 both/hops64 Nokia 7750 SR Copyright (c) 2000-2023 Nokia.\nAll rights reserved. All use subject to applicable license agreements.\nBuilt on Wed Mar 29 16:56:15 PDT 2023 by builder in /builds/c/2110B/R11/panos/main/sros\n</software-code-version>\n\n#

which adds up to 303, which already doesn't match the 305 size that was sent by the router, so none of these https://github.com/scrapli/scrapli_netconf/blob/main/scrapli_netconf/response.py#L229-L234 would match.

If i manually put the carriage returns back into the string: b"#305\n <software-code-version>TiMOS-B-21.10.R11 both/hops64 Nokia 7750 SR Copyright (c) 2000-2023 Nokia.\r\nAll rights reserved. All use subject to applicable license agreements.\r\nBuilt on Wed Mar 29 16:56:15 PDT 2023 by builder in /builds/c/2110B/R11/panos/main/sros\r\n</software-code-version>\n\n#"

it will match trim_newline_len

carlmontanari commented 6 months ago

nice, thanks @joshbenz ! I think I may just tweak this to be like the recently updated chunk counting in scrapligo. will try to poke that this weekend and let ya'll know how it goes!

carlmontanari commented 5 months ago

👋 could ya'll give #143 a crack and let us know if that sorts it out. pretty much 1:1 copied from go -> py and tests are passing so should be cool I think/hope!

joshbenz commented 5 months ago

I think it is the same issue. The chunk size ends up not being accurate because the response has the \r stripped out. So it is slicing too far.

I get the following error:

DEBUG:scrapli.driver:Building payload for 'get' operation. filter_type: subtree, filter_: <state xmlns="urn:nokia.com:sros:ns:yang:sr:state"><card><slot-number>1</slot-number><hardware-data><software-code-version></software-code-version></hardware-data></card></state>
DEBUG:scrapli.driver:Building base element for message id 101
DEBUG:scrapli.driver:Built payload for 'get' operation. Payload: #313
<?xml version='1.0' encoding='utf-8'?>
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101"><get><filter type="subtree"><state xmlns="urn:nokia.com:sros:ns:yang:sr:state"><card><slot-number>1</slot-number><hardware-data><software-code-version/></hardware-data></card></state></filter></get></rpc>
##
INFO:scrapli.channel:sending channel input: #313
<?xml version='1.0' encoding='utf-8'?>
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101"><get><filter type="subtree"><state xmlns="urn:nokia.com:sros:ns:yang:sr:state"><card><slot-number>1</slot-number><hardware-data><software-code-version/></hardware-data></card></state></filter></get></rpc>
##; strip_prompt: False; eager: True
DEBUG:scrapli.channel:write: '#313\n<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101"><get><filter type="subtree"><state xmlns="urn:nokia.com:sros:ns:yang:sr:state"><card><slot-number>1</slot-number><hardware-data><software-code-version/></hardware-data></card></state></filter></get></rpc>\n##'
DEBUG:scrapli.channel:write: '\n'
DEBUG:scrapli.channel:read: b'\n#38\n<?xml version="1.0" encoding="UTF-8"?>\n#1\n\n'
DEBUG:scrapli.channel:read: b'\n#10\n<rpc-reply\n#17\n message-id="101"\n#48\n xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"\n#1\n>\n#1\n\n\n#11\n    <data>\n\n#60\n        <state xmlns="urn:nokia.com:sros:ns:yang:sr:state">\n\n#19\n            <card>\n\n#45\n                <slot-number>1</slot-number>\n\n#32\n                <hardware-data>\n\n#305\n                    <software-code-version>TiMOS-B-21.10.R11 both/hops64 Nokia 7750 SR Copyright (c) 2000-2023 Nokia.\nAll rights reserved. All use subject to applicable license agreements.\nBuilt on Wed Mar 29 16:56:15 PDT 2023 by builder in /builds/c/2110B/R11/panos/main/sros\n</software-code-version>\n\n#33\n                </hardware-data>\n\n#20\n            </card>\n\n#17\n        </state>\n\n#12\n    </data>\n\n#12\n</rpc-reply>\n##\n'
DEBUG:scrapli.channel:server echo is unset, determining if server echoes inputs now
DEBUG:scrapli.channel:server does *not* echo inputs, setting _server_echo to 'false'
DEBUG:scrapli.channel:write: '\n'
CRITICAL:response:unable to parse netconf response: chunk marker missing, got 51
Traceback (most recent call last):
  File "/home/jbenz/code/adf/scrapli/main.py", line 98, in <module>
    main()
  File "/home/jbenz/code/adf/scrapli/main.py", line 38, in main
    state_xml = conn.get(state_filter)
                ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jbenz/code/adf/scrapli/venv3/lib/python3.11/site-packages/scrapli_netconf/driver/sync_driver.py", line 147, in get
    response.record_response(raw_response)
  File "/home/jbenz/code/adf/scrapli/venv3/lib/python3.11/site-packages/scrapli_netconf/response.py", line 122, in record_response
    self._fetch_error_messages()
  File "/home/jbenz/code/adf/scrapli/venv3/lib/python3.11/site-packages/scrapli_netconf/response.py", line 275, in _fetch_error_messages
    err_messages = self.xml_result.xpath("//rpc-error/error-message")
                   ^^^^^^^^^^^^^^^
AttributeError: 'NetconfResponse' object has no attribute 'xml_result'. Did you mean: 'raw_result'?

I assume 51 is referring to the ascii value for 3. It is the 3 from #33 at the end of the same chunk that we were having issues with before.

This is the raw result as seen by scrapli-netconf: b'\n#38\n<?xml version="1.0" encoding="UTF-8"?>\n#1\n\n\n#10\n<rpc-reply\n#17\n message-id="101"\n#48\n xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"\n#1\n>\n#1\n\n\n#11\n <data>\n\n#60\n <state xmlns="urn:nokia.com:sros:ns:yang:sr:state">\n\n#19\n <card>\n\n#45\n <slot-number>1</slot-number>\n\n#32\n <hardware-data>\n\n#305\n <software-code-version>TiMOS-B-21.10.R11 both/hops64 Nokia 7750 SR Copyright (c) 2000-2023 Nokia.\nAll rights reserved. All use subject to applicable license agreements.\nBuilt on Wed Mar 29 16:56:15 PDT 2023 by builder in /builds/c/2110B/R11/panos/main/sros\n</software-code-version>\n\n#33\n </hardware-data>\n\n#20\n </card>\n\n#17\n </state>\n\n#12\n </data>\n\n#12\n</rpc-reply>\n##\n'

Once you call strip, this is the _raw_result: b'#38\n<?xml version="1.0" encoding="UTF-8"?>\n#1\n\n\n#10\n<rpc-reply\n#17\n message-id="101"\n#48\n xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"\n#1\n>\n#1\n\n\n#11\n <data>\n\n#60\n <state xmlns="urn:nokia.com:sros:ns:yang:sr:state">\n\n#19\n <card>\n\n#45\n <slot-number>1</slot-number>\n\n#32\n <hardware-data>\n\n#305\n <software-code-version>TiMOS-B-21.10.R11 both/hops64 Nokia 7750 SR Copyright (c) 2000-2023 Nokia.\nAll rights reserved. All use subject to applicable license agreements.\nBuilt on Wed Mar 29 16:56:15 PDT 2023 by builder in /builds/c/2110B/R11/panos/main/sros\n</software-code-version>\n\n#33\n </hardware-data>\n\n#20\n </card>\n\n#17\n </state>\n\n#12\n </data>\n\n#12\n</rpc-reply>\n##

These are the chunks it reads: 'chunks': [b'<?xml version="1.0" encoding="UTF-8"?>', b'\n', b'<rpc-reply', b' message-id="101"', b' xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"', b'>', b'\n', b' <data>\n', b' <state xmlns="urn:nokia.com:sros:ns:yang:sr:state">\n', b' <card>\n', b' <slot-number>1</slot-number>\n', b' <hardware-data>\n', b' <software-code-version>TiMOS-B-21.10.R11 both/hops64 Nokia 7750 SR Copyright (c) 2000-2023 Nokia.\nAll rights reserved. All use subject to applicable license agreements.\nBuilt on Wed Mar 29 16:56:15 PDT 2023 by builder in /builds/c/2110B/R11/panos/main/sros\n</software-code-version>\n\n#3']

At this point it crashes because it looks for the chunk size, but there is no chunk size because we wrote the chunk delimiter to the previous chunk. So it reads a 3, which is 51 and stops.

The chunk that it fails on is the only chunk with \r in the response. There are 3 of them. I am pretty sure this line in scrapli strips them out. b'\n#305\n <software-code-version>TiMOS-B-21.10.R11 both/hops64 Nokia 7750 SR Copyright (c) 2000-2023 Nokia.\r\nAll rights reserved. All use subject to applicable license agreements.\r\nBuilt on Wed Mar 29 16:56:15 PDT 2023 by builder in /builds/c/2110B/R11/panos/main/sros\r\n</software-code-version>\n

joshbenz commented 5 months ago

The same issue appears in the golang version "operation error from input '<?xml version=\"1.0\" encoding=\"UTF-8\"?><rpc xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"101\"><get><filter type=\"subtree\"><state xmlns=\"urn:nokia.com:sros:ns:yang:sr:state\"><card><slot-number>1</slot-number><hardware-data><software-code-version></software-code-version></hardware-data></card></state></filter></get></rpc>'. matched error sub-string 'unable to parse netconf 1.1 response: unable to parse netconf response: chunk marker missing, got '3''. full output: ''"

carlmontanari commented 5 months ago

I am pretty sure this line in scrapli

is never called in netconf. netconf channel overrides that w/ a noop function. but you pointing that one out made me look and there is this guy which has got to be our culprit.. but... removing that completely breaks everything for everything else :) just quickly checked iosxe since I have a box handy. it sends something like:

#167\r\n<?xml version=\'1.0\' encoding=\'utf-8\'?>\r\n<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101"><get-config><source><running/></source></get-config></rpc>\r\n##\r\n\r\n

which, after removing the carriage returns the 167 size is correct (and the escaped single quotes, thats just from the logger writing it out). obviously with the carriage returns... no dice, its way off. so... we are obviously in a pickle it seems!

this led me to wonder "why tf are there carriage returns anyway". which led me to this whiiiiich surely feels like its possibly the reason. so... if you could do me a favor and patch the read method of the sync channel (im assuming you re doing sync things) to look like:

        if self._read_buf:
            read_buf = self._read_buf
            self._read_buf = b""
            return read_buf

        buf = self.transport.read()

        self.logger.debug(f"read: {buf!r}")

        if self.channel_log:
            self.channel_log.write(buf)

        if b"\x1b" in buf.lower():
            buf = self._strip_ansi(buf=buf)

        return buf

then try with system transport and paramiko transport and see if things work. I think/hope that they will fail for the former, and succeed for the latter. if thats the case then I just go digging to find out about this termios stuff, fix that, then we are looking good :)

im going to merge that other branch as I think that is a better way to do the chunk parsing anyway and I was lazy and pushed some ci fix into that too. but we can keep chipping away on getting this sorted out too of course.

thanks for all the work on this!

carlmontanari commented 5 months ago

ok, this termios magic looks like it works. will follow up more this week or next weekend!

joshbenz commented 5 months ago

Ah ok, I just assumed it was using whatever scrapli was using hah. Thanks your work and for working with us on this. I use both sync and async depending on what I am doing. I have been testing all this with sync. I'll give it a try when I get a chance.

carlmontanari commented 5 months ago

fyi I think async (or paramiko) will be the same unless you patch that read in the channel -- but if/when you do that I think it should work!

joshbenz commented 5 months ago

I confirmed that the patch works without any issues for me. The chunk in question looks correct now.

b'\n#305\n <software-code-version>TiMOS-B-21.10.R11 both/hops64 Nokia 7750 SR Copyright (c) 2000-2023 Nokia.\r\nAll rights reserved. All use subject to applicable license agreements.\r\nBuilt on Wed Mar 29 16:56:15 PDT 2023 by builder in /builds/c/2110B/R11/panos/main/sros\r\n</software-code-version>\n'

Thanks for your help on this!

carlmontanari commented 5 months ago

bam! thanks a ton for confirming @joshbenz ! will mess about with the termios thing and/or this patch this weekend to see what I end up deciding. either way should be able to put this one to bed soon ish!

carlmontanari commented 5 months ago

okie dokie, so #144 and this should sort us out I think! if you've got some time to check it out and confirm its good that would be great!

joshbenz commented 5 months ago

Yeah, it looks good to me. I tried a few other RPCs and tried the other transports just for the heck of it. No issues!

carlmontanari commented 5 months ago

sweet, will close this and merge things. will do the next release on the normal schedule so will just have to pin stuff to commit for now!