Repository navigation
fix: make service connection identity optional - #656
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!
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: |
Matches the podman CLI, which checks CONTAINER_CONNECTION before CONTAINER_HOST. An explicit CONTAINER_HOST URL no longer silently wins, so podman-py and the CLI always resolve to the same host. Also notes the dependency on PR containers#656 for identity-less connections. Signed-off-by: rjmcgee53192 <[email protected]>
|
@pratham8499 Any updates on this? Please rebase on upstream main. CI should be happy. |
faa9707 to
2d96dca
Compare
|
Hi — I'm the author of #679, which was just closed as a duplicate of this PR, so I read this diff closely. We landed on the same bug from opposite ends. The core approach matches what I found independently: return None from Two small things, in that spirit:
Otherwise this looks right to me: the client tests cover no-identity, explicit identity, override, and active_service. Glad to see this land — it also unblocks my #673, which depends on this fix. — Ryan |
Honny1
left a comment
There was a problem hiding this comment.
Nonblocking comment.Otherwise,e LGTM
| if "identity" in self.attrs: | ||
| val = self.attrs["identity"] | ||
| return Path(val) if val else None | ||
| if "Identity" in self.attrs: | ||
| val = self.attrs["Identity"] | ||
| return Path(val) if val else None | ||
| return None |
There was a problem hiding this comment.
| if "identity" in self.attrs: | |
| val = self.attrs["identity"] | |
| return Path(val) if val else None | |
| if "Identity" in self.attrs: | |
| val = self.attrs["Identity"] | |
| return Path(val) if val else None | |
| return None | |
| for key in ("identity", "Identity"): | |
| if key in self.attrs: | |
| val = self.attrs[key] | |
| return Path(val) if val else None | |
| return None |
|
LGTM |
2d96dca to
4af4364
Compare
|
Applied @Honny1's suggestion to loop over ('identity', 'Identity')\ to eliminate duplication and amended the commit. |
|
@pratham8499, can you please rebase on upstream main? Thanks! To make CI happy. |
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 <[email protected]>
4af4364 to
7af28b2
Compare
|
@Honny1 Rebased on upstream main and resolved the conflict. Ready for CI! |
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 [email protected]
#654 (from_env ignoring CONTAINER_CONNECTION) is a separate fix and depends on this one; happy to follow up.