Skip to content

[202012][aclshow] fix aclshow when clear is called before counters ar…#2038

Merged
bingwang-ms merged 1 commit intosonic-net:202012from
stepanblyschak:202012-fix-aclshow
Jan 28, 2022
Merged

[202012][aclshow] fix aclshow when clear is called before counters ar…#2038
bingwang-ms merged 1 commit intosonic-net:202012from
stepanblyschak:202012-fix-aclshow

Conversation

@stepanblyschak
Copy link
Contributor

Signed-off-by: Stepan Blyschak stepanb@nvidia.com

Backport of : #2037

What I did

Fixed a bug that in case ACL counters are cleared before counters are populated in COUNTERS DB the next aclshow will fail:

admin@sonic:~$ aclshow -c -t DATAACL
admin@sonic:~$ aclshow -a -t DATAACL
'NoneType' object is not subscriptable  

How I did it

Keep self.acl_counters in sync with COUNTERS DB and don't put empty values when no counters are available, so when dumping counters and loading them back there are no empty values.

How to verify it

Without this change the added UT fails:

self = <aclshow.AclStat object at 0x7f0208277438>, key = ('DATAACL_NO_COUNTER', 'RULE_NO_COUNTER'), type = 'SAI_ACL_COUNTER_ATTR_PACKETS'
                                                                                     
    def get_counter_value(self, key, type):                                          
        """                                                                          
        return the counter value or the difference comparing with the saved value in string format
        """                                                                          
        if not self.acl_counters[key]:                                               
            return 'N/A'                                                             
                                                                                     
        if key in self.saved_acl_counters: 
>           new_value = int(self.acl_counters[key][type]) - int(self.saved_acl_counters[key][type])
E           TypeError: 'NoneType' object is not subscriptable  

Previous command output (if the output of a command-line utility has changed)

New command output (if the output of a command-line utility has changed)

…e populated

Signed-off-by: Stepan Blyschak <stepanb@nvidia.com>
@bingwang-ms bingwang-ms merged commit 40d1365 into sonic-net:202012 Jan 28, 2022
@bingwang-ms
Copy link
Contributor

Thanks for the fix

@qiluo-msft
Copy link
Contributor

@bingwang-ms The PR is for 202012. So there is no need to "Request for 202012 branch".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants