CiscoTestAutomation / genielibs

genie.libs contains libraries for configuring, retrieving and testing topologies
Apache License 2.0
108 stars 55 forks source link

Common Criteria Policy optional arguments missing null checks #179

Open adivardh-cisco opened 1 week ago

adivardh-cisco commented 1 week ago

The API end point for configuring aaa common criteria policy i.e : configure_common_criteria_policy has optional arguments defined, operations on these optional args throws runtime errors when we don't provide these parameters because the defaults are None.

File: genielibs/pkgs/sdk-pkg/src/genie/libs/sdk/apis/iosxe/aaa/configure.py

Eg:

if int(lower_case) > 0:
        configs.append("lower-case {low}".format(low=lower_case))
if int(upper_case) > 0:
        configs.append("upper-case {up}".format(up=upper_case))
adivardh-cisco commented 1 week ago
2024-09-27T13:39:30: %AETEST-ERROR: Caught an exception while executing section configure_policy:
2024-09-27T13:39:30: %AETEST-ERROR: Traceback (most recent call last):
2024-09-27T13:39:30: %AETEST-ERROR:   File "/nobackup/adivardh/teacat_practice/user_missing.py", line 59, in configure_policy
2024-09-27T13:39:30: %AETEST-ERROR:     uut.api.configure_common_criteria_policy(policy)
2024-09-27T13:39:30: %AETEST-ERROR:   File "/nobackup/adivardh/pyats/lib/python3.8/site-packages/genie/conf/base/api.py", line 206, in wrapper_match
2024-09-27T13:39:30: %AETEST-ERROR:     func_result = func(*args, **kwargs)
2024-09-27T13:39:30: %AETEST-ERROR:   File "/nobackup/adivardh/pyats/lib/python3.8/site-packages/genie/libs/sdk/apis/iosxe/aaa/configure.py", line 924, in configure_common_criteria_policy
2024-09-27T13:39:30: %AETEST-ERROR:     if int(lower_case) > 0:
2024-09-27T13:39:30: %AETEST-ERROR: TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
SohanTirpude commented 1 week ago

Hello @adivardh-cisco,

Thank you for providing the fix for this issue. It seems you will have to add unittest for this. So, kindly follow this documentation: https://pubhub.devnetcloud.com/media/pyats-development-guide/docs/writeapi/writeapi.html#unit-testing. Also, if needed, refer to this PR: https://github.com/CiscoTestAutomation/genielibs/pull/171

Thank you.

adivardh-cisco commented 1 week ago

Hi @SohanTirpude

I have added a test and attached the logs, do let me know if anything else is needed.