Repository navigation
fix: make service connection identity optional - #656
pratham8499 wants to merge 1 commit into
Conversation
| identity = kwargs.get("identity") or connection.identity | ||
| if identity: | ||
| api_kwargs["identity"] = str(identity) | ||
| elif "identity" in api_kwargs: | ||
| del api_kwargs["identity"] |
There was a problem hiding this comment.
Well, I see this part as uplicate with rows 81-85. Maybe put that into a separate function?
| @@ -54,10 +54,12 @@ def url(self): | |||
|
|
|||
| @cached_property | |||
| def identity(self): | |||
There was a problem hiding this comment.
| def identity(self): | |
| def identity(self) -> Optional[Path]: |
Honny1
left a comment
There was a problem hiding this comment.
Also linter complains:
F841 Local variable `client` is assigned to but never used
--> podman/tests/unit/test_podmanclient.py:101:60
|
99 | def test_connect_no_identity(self, mock_api_init, mock_api_close):
100 | with mock.patch.multiple(Path, open=self.mocked_open, exists=MagicMock(return_value=True)):
101 | with PodmanClient(connection="no_identity") as client:
| ^^^^^^
102 | mock_api_init.assert_called_once()
103 | kwargs = mock_api_init.call_args[1]
|
help: Remove assignment to unused variable `client`
F841 Local variable `client` is assigned to but never used
--> podman/tests/unit/test_podmanclient.py:111:84
|
109 | def test_connect_explicit_identity(self, mock_api_init, mock_api_close):
110 | with mock.patch.multiple(Path, open=self.mocked_open, exists=MagicMock(return_value=True)):
111 | with PodmanClient(connection="no_identity", identity="/custom/key") as client:
| ^^^^^^
112 | mock_api_init.assert_called_once()
113 | kwargs = mock_api_init.call_args[1]
|
help: Remove assignment to unused variable `client`
F841 Local variable `client` is assigned to but never used
--> podman/tests/unit/test_podmanclient.py:120:81
|
118 | def test_connect_explicit_identity_override(self, mock_api_init, mock_api_close):
119 | with mock.patch.multiple(Path, open=self.mocked_open, exists=MagicMock(return_value=True)):
120 | with PodmanClient(connection="testing", identity="/custom/key2") as client:
| ^^^^^^
121 | mock_api_init.assert_called_once()
122 | kwargs = mock_api_init.call_args[1]
|
help: Remove assignment to unused variable `client`
F841 Local variable `client` is assigned to but never used
--> podman/tests/unit/test_podmanclient.py:136:36
|
135 | with mock.patch('podman.client.PodmanConfig', return_value=mock_config):
136 | with PodmanClient() as client:
| ^^^^^^
137 | mock_api_init.assert_called_once()
138 | kwargs = mock_api_init.call_args[1]
|
help: Remove assignment to unused variable `client`
E501 Line too long (147 > 100)
--> podman/tests/unit/test_podmanclient.py:154:101
|
152 | … / "podman.sock")
153 | …
154 | …l(), expected.replace('%5C', '\\') if '\\' in client.api.base_url.geturl() else expected)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
155 | …
156 | …or a user
|
Found 5 errors.
No fixes available (4 hidden fixes can be enabled with the `--unsafe-fixes` option).
ruff format..............................................................Failed
2ef5d3a to
3bdeb20
Compare
Honny1
left a comment
There was a problem hiding this comment.
Can you please sqoush commits and move unrealted changes to separate commit. Thanks!
| unittest: | ||
| coverage run -m unittest discover -s podman/tests/unit | ||
| coverage report -m --skip-covered --fail-under=80 --omit=./podman/tests/* --omit=.tox/* --omit=/usr/lib/* | ||
| coverage report -m --skip-covered --fail-under=85 --omit=./podman/tests/* --omit=.tox/* --omit=/usr/lib/* |
There was a problem hiding this comment.
I think those changes are unrelated to what is fixed. Please put them into a separate commit.
|
I have enabled CI. Please check if it will pass. |
3bdeb20 to
ddc39bf
Compare
Honny1
left a comment
There was a problem hiding this comment.
I didnt read last chnges fully but. Linter is complaining:
+++ b/podman/tests/unit/test_podmanclient.py
@@ -101,7 +101,9 @@ class PodmanClientTestCase(unittest.TestCase):
with PodmanClient(connection="no_identity"):
mock_api_init.assert_called_once()
kwargs = mock_api_init.call_args[1]
- self.assertEqual(kwargs["base_url"], "ssh://root@localhost:22/run/podman/podman.sock")
+ self.assertEqual(
+ kwargs["base_url"], "ssh://root@localhost:22/run/podman/podman.sock"
+ )
self.assertNotIn("identity", kwargs)
@mock.patch('podman.client.APIClient.close')
@@ -136,7 +138,9 @@ class PodmanClientTestCase(unittest.TestCase):
with PodmanClient():
mock_api_init.assert_called_once()
kwargs = mock_api_init.call_args[1]
- self.assertEqual(kwargs["base_url"], "http+ssh://root@localhost:22/run/podman/podman.sock")
+ self.assertEqual(
+ kwargs["base_url"], "http+ssh://root@localhost:22/run/podman/podman.sock"
+ )
self.assertNotIn("identity", kwargs)
def test_connect_404(self):
Error: Process completed with exit code 1.
c09b9fd to
5ab97c1
Compare
Honny1
left a comment
There was a problem hiding this comment.
Please link fixed issues in the commit msg with Fixes: #NUMBER_OF_ISSUE. Thanks!
Before the fix: a) PodmanConfig().services['local'].identity -> failed: TypeError expected str, bytes or os.PathLike object, not NoneType b) PodmanClient(connection='local') -> failed: TypeError expected str, bytes or os.PathLike object, not NoneType c) PodmanClient(connection='local', identity='<dummy>') -> failed: TypeError expected str, bytes or os.PathLike object, not NoneType d) PodmanClient(connection='production') -> success After the fix: a) PodmanConfig().services['local'].identity -> success: None b) PodmanClient(connection='local') -> success c) PodmanClient(connection='local', identity='<dummy>') -> success d) PodmanClient(connection='production') -> success The explicit `identity=` argument was ignored because the default fallback `str(connection.identity)` was evaluated eagerly, raising a TypeError before the fallback was even used. This fix lazily computes the fallback. Fixes: containers#652 Fixes: containers#653 Signed-off-by: Pratham <patidarpratham40@gmail.com> containers#654 (from_env ignoring CONTAINER_CONNECTION) is a separate fix and depends on this one; happy to follow up.
5ab97c1 to
faa9707
Compare
|
@Honny1 I have addressed all the feedback and force-pushed the changes: Fixed the unused variable and line-length linter errors. |
|
I think this line from commit msg: |
Before the fix:
a) PodmanConfig().services['local'].identity
-> failed: TypeError expected str, bytes or os.PathLike object, not NoneType
b) PodmanClient(connection='local')
-> failed: TypeError expected str, bytes or os.PathLike object, not NoneType
c) PodmanClient(connection='local', identity='')
-> failed: TypeError expected str, bytes or os.PathLike object, not NoneType
d) PodmanClient(connection='production')
-> success
After the fix:
a) PodmanConfig().services['local'].identity
-> success: None
b) PodmanClient(connection='local')
-> success
c) PodmanClient(connection='local', identity='')
-> success
d) PodmanClient(connection='production')
-> success
The explicit
identity=argument was ignored because the default fallbackstr(connection.identity)was evaluated eagerly, raising a TypeError before the fallback was even used. This fix lazily computes the fallback.Fixes: #652
Fixes: #653
Signed-off-by: Pratham patidarpratham40@gmail.com
#654 (from_env ignoring CONTAINER_CONNECTION) is a separate fix and depends on this one; happy to follow up.