-
Notifications
You must be signed in to change notification settings - Fork 666
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
Replace cmp in acl_loader with operator.eq #2328
Conversation
Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
Please update test case to cover the diff. |
acl_loader/main.py
Outdated
@@ -758,7 +759,7 @@ def incremental_update(self): | |||
namespace_configdb.mod_entry(self.ACL_RULE, key, None) | |||
|
|||
for key in existing_controlplane_rules: | |||
if cmp(self.rules_info[key], self.rules_db_info[key]) != 0: | |||
if operator.eq(self.rules_info[key], self.rules_db_info[key]) != 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
operator.eq
will return a bool?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qiluo-msft Yes. The return type of this method is bool, it returns True if x is equal to y, False, otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qiluo-msft Thank you for your question, for python2, cmp returns 0 if x is equal to y, if not equal, the result is not 0, it should be -1 or 1. So, operator.eq's return result is opposite with cmp's results. I will update code to make the logic right and write unit test case as well.
Syntax:
cmp(a, b)
Parameters:
a and b are the two numbers in which the comparison is being done.
Returns:
-1 if a<b
0 if a=b
1 if a>b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your new iteration. To make it better, use if not eq()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qiluo-msft Ye, agree, I updated it.
Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
@ZhaohuiS , we need this for 202012 as well, correct? Can you please raise a separate PR? |
cmp is deprecated in python3. Use operator.eq instead Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
cmp is deprecated in python3. Use operator.eq instead Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
cmp is deprecated in python3. Use operator.eq instead Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
Signed-off-by: Zhaohui Sun zhaohuisun@microsoft.com
What I did
When run try to add a new rule for existing rule table with this command
acl-loader update incremental
, it will throw a traceback like this:cmp is deprecated in python3.
How I did it
Use
operator.eq
instead.The return type of
operator.eq
is bool, it returns True if x is equal to y, False, otherwise.cmp
syntax:cmp(a, b)
Parameters:
a and b are the two numbers in which the comparison is being done.
Returns:
-1 if a<b
0 if a=b
1 if a>b
Add unit test
How to verify it
Load acl json file with existing rule table in the config file with this command:
acl-loader update incremental**.json
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)