-
Notifications
You must be signed in to change notification settings - Fork 142
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
pylint: Fix R1732 consider-using-with #937
Conversation
b786915
to
0be94fd
Compare
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 do not see why the e2e are failing on this PR. Can you rebase on the latest master?
keylime/keylime_agent.py
Outdated
f = open(secdir + "/" + self.server.enc_keyname, 'w', encoding="utf-8") | ||
f.write(base64.b64encode(self.server.K).decode()) | ||
f.close() | ||
with open(secdir + "/" + self.server.enc_keyname, 'w', encoding="utf-8") as f: |
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.
Can you fix the string formatting to os.path.join
?.
I know that this is not directly related to this issue, but I try to convert them if I change the line anyway.
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.
Fixed locally.
keylime/secure_mount.py
Outdated
@@ -20,7 +20,7 @@ | |||
def check_mounted(secdir): | |||
"""Inspect mountinfo to detect if a directory is mounted.""" | |||
secdir_escaped = secdir.replace(" ", r"\040") | |||
for line in open("/proc/self/mountinfo", "r", encoding="utf-8"): | |||
for line in open("/proc/self/mountinfo", "r", encoding="utf-8"): #pylint: disable=consider-using-with |
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.
Can we not open the file with with
and then iterate over readline()
?
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.
This seems to work fine for me with python 3.10 just running this here:
>>> with open("/proc/self/mountinfo", "r", encoding="utf-8") as f:
... for line in f:
... print(line)
On the CI/CD system we now get this here:
Error in test.test_secure_mount.TestSecureMount.test_check_mounted_found
File "/usr/lib64/python3.9/unittest/case.py", line 59, in testPartExecutor
yield
File "/usr/lib64/python3.9/unittest/case.py", line 592, in run
self._callTestMethod(testMethod)
File "/usr/lib64/python3.9/unittest/case.py", line 550, in _callTestMethod
method()
File "/usr/lib64/python3.9/unittest/mock.py", line 1336, in patched
return func(*newargs, **newkeywargs)
File "/__w/keylime/keylime/test/test_secure_mount.py", line 31, in test_check_mounted_found
self.assertTrue(secure_mount.check_mounted("/secdir"))
File "/__w/keylime/keylime/keylime/secure_mount.py", line 23, in check_mounted
with open("/proc/self/mountinfo", "r", encoding="utf-8") as f:
AttributeError: __enter__
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.
This is beacuse the open call is mocked, but the __enter__
and __exit__
functions are not: https://github.com/keylime/keylime/blob/master/test/test_secure_mount.py
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.
What's the solution?
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.
So odd...
>>> subprocess.Popen.__enter__
<function Popen.__enter__ at 0x6fffffdf2d30>
>>> open.__enter__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'builtin_function_or_method' object has no attribute '__enter__'
>>> os.open.__enter__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'builtin_function_or_method' object has no attribute '__enter__'
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.
open(..)
and os.open(..)
are two different functions.
Also the __enter__
function seems to be only there when the function is called:
>>> open.__enter__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'builtin_function_or_method' object has no attribute '__enter__'. Did you mean: '__ne__'?
>>> open("tesfile", "wb").__enter__
<built-in method __enter__ of _io.BufferedWriter object at 0x7f8266d521f0>
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.
There seems to be a mocking object in the library for that: https://docs.python.org/3.7/library/unittest.mock.html#mock-open
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.
Fixed in additional patch. What a struggle!
The warning is called |
0be94fd
to
447ef9f
Compare
When testing 447ef9f there is one test-failure in testing-farm:fedora-35-x86_64:
All other tests are passing. I prefer to ignore this test failure but something is flaky... |
4201c74
to
cfa277e
Compare
/packit test |
2f92115
to
5004ea2
Compare
I wonder what that is when Fedora 34 fails and all other ones pass...
|
@kkaarreell seems this like a timing issue? @stefanberger just use |
/packit test |
I can increase the timeout... so far 10 seconds for revocation action initiation was enough. What should be the reasonable timeout? |
10 seconds seem actually reasonable, but if it flaky again in the future we need to take a closer look what is causing this. |
Maybe some networking glitch on the actual virtual system... That would explain the above failure in the keylime tenant. |
Hopefully this would help next time |
5ea7dd4
to
b7903be
Compare
Fix the following issue detected by pylint 2.13.0: keylime/cmd/ima_emulator_adapter.py:73:12: E4702: Iterated dict 'position' is being modified inside for loop body, iterate through a copy of it instead. (modified-iterating-dict) Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Fix the following issue detected by pylint 2.13.0: keylime/tenant.py:1146:19: E0601: Using variable 'response' before assignment (used-before-assignment) Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
b7903be
to
98dc470
Compare
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
98dc470
to
5adcbc9
Compare
Signed-off-by: Stefan Berger stefanb@linux.ibm.com