Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 28, 2022

Conversation

stepanblyschak
Copy link
Contributor

Signed-off-by: Stepan Blyschak [email protected]

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)

@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