cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
5070
Views
15
Helpful
3
Replies

ncclient getting bad-element error when dispatching rpc

nikhchau
Cisco Employee
Cisco Employee

Hi,

 

When using dispatch method of ncclient(0.6.6) to execute an RPC with nso(5.3) getting unknown element error.

 

The same code used to work with previous nso version 4.7.2.1.

 

 

[Console output]

Sending: 2020-01-13T09:54:06: %NCCLIENT-INFO: 2020-01-13T09:54:06: %NCCLIENT-INFO: #673 2020-01-13T09:54:06: %NCCLIENT-INFO: <?xml version="1.0" encoding="UTF-8"?><nc:rpc xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:44e94a3b-f614-4660-9deb-2e30809d0b88"><edit-config> 2020-01-13T09:54:06: %NCCLIENT-INFO: <target> 2020-01-13T09:54:06: %NCCLIENT-INFO: <running/> 2020-01-13T09:54:06: %NCCLIENT-INFO: </target> 2020-01-13T09:54:06: %NCCLIENT-INFO: <config> 2020-01-13T09:54:06: %NCCLIENT-INFO: <org-openroadm-device xmlns="http://org/openroadm/device"> 2020-01-13T09:54:06: %NCCLIENT-INFO: <shelves nc:operation="create"> 2020-01-13T09:54:06: %NCCLIENT-INFO: <shelf-name>0</shelf-name> 2020-01-13T09:54:06: %NCCLIENT-INFO: <shelf-type>xyz Chassis</shelf-type> 2020-01-13T09:54:06: %NCCLIENT-INFO: </shelves> 2020-01-13T09:54:06: %NCCLIENT-INFO: </org-openroadm-device> 2020-01-13T09:54:06: %NCCLIENT-INFO: </config> 2020-01-13T09:54:06: %NCCLIENT-INFO: </edit-config></nc:rpc> 2020-01-13T09:54:06: %NCCLIENT-INFO: ## 2020-01-13T09:54:06: %NCCLIENT-INFO: [host 10.225.100.220 session-id 56] Received: 2020-01-13T09:54:06: %NCCLIENT-INFO: <?xml version="1.0" encoding="UTF-8"?> 2020-01-13T09:54:06: %NCCLIENT-INFO: <rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:44e94a3b-f614-4660-9deb-2e30809d0b88" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><rpc-error> 2020-01-13T09:54:06: %NCCLIENT-INFO: <error-type>protocol</error-type> 2020-01-13T09:54:06: %NCCLIENT-INFO: <error-tag>unknown-element</error-tag> 2020-01-13T09:54:06: %NCCLIENT-INFO: <error-severity>error</error-severity> 2020-01-13T09:54:06: %NCCLIENT-INFO: <error-path> 2020-01-13T09:54:06: %NCCLIENT-INFO: /rpc 2020-01-13T09:54:06: %NCCLIENT-INFO: </error-path><error-info><bad-element>edit-config</bad-element> 2020-01-13T09:54:06: %NCCLIENT-INFO: </error-info> 2020-01-13T09:54:06: %NCCLIENT-INFO: </rpc-error> 2020-01-13T09:54:06: %NCCLIENT-INFO: </rpc-reply>

 

Code that executes with pyats test suite

 

with manager.connect(host=self.host,
                                 port=self.port,
                                 username=self.username,
                                 password=self.password,
                                 timeout=90,
                                 hostkey_verify=self.hostkey_verify,
                                 device_params={'name': 'csr'}) as m:
                try:
                    response = m.dispatch(et.fromstring(payload))
                    print(response)
                    data = response.data_ele
                    print(data)
                except Exception as e:
                    log.error(e)
                    return False
[Payload in code]
'''
<edit-config> <target> <running/> </target> <config> <org-openroadm-device xmlns="http://org/openroadm/device"> <shelves xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="{nc_operation}"> {shelf_name_leaf} {shelf_type_leaf} </shelves> </org-openroadm-device> </config> </edit-config>
'''

The dispatch method forms the final rpc out of the payload.

 

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

 

python version: 3.4.1

ncclient: 0.6.6

nso: 5.3

 

 

 

3 Replies 3

mvolf
Cisco Employee
Cisco Employee

The edit-config element is indeed incorrect in that it does not belong to the correct namespace. The element does not have a namespace prefix and the default namespace is not declared in its scope; it needs to belong to the base netconf namespace, like

<edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">...</edit-config>

Maybe you should preferably use manager.edit_config instead of the general manager.dispatch.

ciscoramanan
Level 1
Level 1
This example is showing add one device to the NSO , You need to define the namespace in the config tag.
 
xmldata = '''
<config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
 <devices xmlns="http://tail-f.com/ns/ncs">
  <device>
   <name>R4</name>
    <address>192.168.200.104</address>
    <ssh>
      <host-key-verification>none</host-key-verification>
    </ssh>
    <authgroup>l3cisco</authgroup>
    <device-type>
     <cli>
        <protocol>telnet</protocol>
     </cli>
    </device-type>
    <state>
      <admin-state>unlocked</admin-state>
    </state>
  </device>       
 </devices>
 </config>
'''


with manager.connect(**conn_para) as conn:
    response = conn.edit_config(target="running",config=xmldata)
    print (response)
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:aa2de885-b1a0-470c-a71a-e740895fa550" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"><ok/></rpc-reply>

is there any way to sync-from this device using ncclient?