cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
293
Views
0
Helpful
1
Replies
Highlighted
Cisco Employee

ncclient getting bad-element error when dispatching rpc

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

 

 

 

1 REPLY 1
Cisco Employee

Re: ncclient getting bad-element error when dispatching rpc

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.