cisco-en-programmability / dnacentersdk

Cisco DNA Center Python SDK
https://dnacentersdk.readthedocs.io/en/latest/
MIT License
70 stars 33 forks source link

Sda.adds_border_device boolean not accepted for connectedToInternet and borderWithExternalConnectivity #65

Closed nextnoob closed 2 years ago

nextnoob commented 2 years ago

Prerequisites

Yes →

Example Payload:

[
    {
        "deviceManagementIpAddress": "172.22.4.2",
        "siteNameHierarchy": "Global/SH-2",
        "deviceRole": [
            "Border_Node", 
            "Control_Plane_Node",
            "Edge_Node"
        ],
        "externalDomainRoutingProtocolName": "BGP",
        "externalConnectivityIpPoolName": "L3-Handoff",
        "internalAutonomouSystemNumber": "65101",
        "borderPriority": "10",
        "borderSessionType": "ANYWHERE",
        "connectedToInternet": "True",
        "borderWithExternalConnectivity": "False",
    }
]
pip show dnacentersdk
Name: dnacentersdk
Version: 2.5.2
Summary: Cisco DNA Center Platform SDK
Home-page: https://dnacentersdk.readthedocs.io/en/latest/
Author: Jose Bogarin Solano
Author-email: jbogarin@altus.cr
License: MIT
Location: c:\users\username\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages
Requires: fastjsonschema, future, requests, requests-toolbelt
Required-by: 

Describe the bug

Class: classSda Function: adds_border_device(headers=None, payload=None, active_validation=True, **request_parameters)

First issue: The scheme under Developer DNAC Docs wants booleans for the keys borderWithExternalConnectivity and connectedToInternet as values. Unfortunately, in reality only strings are accepted by the DNA Center here.

Payload:

[
    {
        "deviceManagementIpAddress": "172.22.4.2",
        "siteNameHierarchy": "Global/SH-2",
        "deviceRole": [
            "Border_Node", 
            "Control_Plane_Node",
            "Edge_Node"
        ],
        "externalDomainRoutingProtocolName": "BGP",
        "externalConnectivityIpPoolName": "L3-Handoff",
        "internalAutonomouSystemNumber": "65101",
        "borderPriority": "10",
        "borderSessionType": "ANYWHERE",
        "connectedToInternet": True,
        "borderWithExternalConnectivity": False,
    }
]

Error message:

PS E:\Users\username\ios-xe-nc-trial> python3 .\add_border_node.py
Traceback (most recent call last):
  File "E:\Users\username\ios-xe-nc-trial\add_border_node.py", line 70, in <module>
    dnac.sda.adds_border_device(payload = payload)
  File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\dnacentersdk\api\v2_3_3_0\sda.py", line 370, in adds_border_device
    json_data = self._session.post(endpoint_full_url, params=_params,
  File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\dnacentersdk\restsession.py", line 619, in post
    response = self.request('POST', url, erc, 0, params=params,
  File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\dnacentersdk\restsession.py", line 471, in request  
    check_response_code(response, erc)
  File "C:\Users\username\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\dnacentersdk\utils.py", line 209, in check_response_code
    raise ApiError(response)
dnacentersdk.exceptions.ApiError: [400] Bad Request - The request was invalid or cannot be otherwise served.

When I adjust the validator, the API call works.

"borderWithExternalConnectivity": {
"type": "string"
},
"connectedToInternet": {
"type": "string"
},

Also following values are accepted with adjusted validators:

"connectedToInternet": true,
"borderWithExternalConnectivity": false,

Expected behavior The API should accept Boolean according to the schema, but it does not.

Screenshots image image

Environment (please complete the following information):

Additional context

Thanks for maintaining the very good SDK :blush:

fmunozmiranda commented 2 years ago

Hey @nextnoob , there´s a new version of dnacentersdk (2.5.3) with solved problem, try it and let us know if it works for you.

nextnoob commented 2 years ago

Hey @fmunozmiranda ,

the implementation worked, thank you very much!

What about the DNAC API docs? Will this be adapted or can it be that in newer DNAC versions only Boolean will be accepted again?

fmunozmiranda commented 2 years ago

We are going to report it, however that does not fall on us, we only provide support to the sdk. If there´s anything else, please close issue.