Correctly load configuration when instantiating new client without kwargs#544
Correctly load configuration when instantiating new client without kwargs#544anishasthana wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: anishasthana The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
@anishasthana The |
| api_kwargs["base_url"] = connection.url.geturl() | ||
| # Override configured identity, if provided in arguments | ||
| api_kwargs["identity"] = kwargs.get("identity", str(connection.identity)) | ||
| elif "base_url" not in api_kwargs: |
There was a problem hiding this comment.
@jwhonce any reason why this is technically the default case (this will always be true if api_kwargs is empty) and not the contents we get from the podman config?
f8f753e to
da8458c
Compare
| elif "base_url" not in api_kwargs: | ||
| path = str(Path(get_runtime_dir()) / "podman" / "podman.sock") | ||
| api_kwargs["base_url"] = "http+unix://" + path | ||
| if not api_kwargs and "Connection" in config.attrs: |
There was a problem hiding this comment.
I think this PR is bringing in a lot of value.
I would take the chance to rework this logic, making use of a more linear if/else chain. Here's a POC of what I mean.
wdyt @jwhonce @umohnani8 @anishasthana ?
# Case 1: Use named connection from kwargs if specified
if "connection" in api_kwargs:
connection = config.services[api_kwargs.get("connection")]
api_kwargs["base_url"] = connection.url.geturl()
# Override configured identity, if provided in arguments
api_kwargs["identity"] = kwargs.get("identity", str(connection.identity))
# Case 2: No kwargs provided - try to load from system configuration
elif not api_kwargs:
default_connection_name = config.attrs["Connection"]["Default"]
connection = config.attrs["Connection"]["Connections"][default_connection_name]
api_kwargs["base_url"] = connection["URI"]
api_kwargs["identity"] = connection["Identity"]
# Case 3: Fallback - if no base_url is specified, use default socket path
if "base_url" not in api_kwargs:
path = str(Path(get_runtime_dir()) / "podman" / "podman.sock")
api_kwargs["base_url"] = "http+unix://" + pathI would also take the chance to add some logging, and, of course, a couple more tests are needed to ensure that the config priority is maintained.
There was a problem hiding this comment.
I was worried about breaking existing behaviour, but I'm happy to move to a more linear chain!
There was a problem hiding this comment.
my suggestion is to enforce the behaviour with integration tests. you can proceed this way if you like:
- write tests for the current behaviour (I didn't check the test status right now), make a pr, and we merge it.
- write the new code (in this PR) and use any approach. then we'll have tests to help understand if the behaviour is breaking
we need to ensure this is tested anyway. it's quite critical for this feature :)
There was a problem hiding this comment.
@anishasthana thanks for moving it forward
we need to ensure this is tested anyway. it's quite critical for this feature :)
I'd like to have tests for all the if/else cases in this PR. do you need help with them?
There was a problem hiding this comment.
Hey @inknos, I'm in the middle of some travel so it'll be slow going on my end (as and when I have time). I'll reach out if I find myself stuck/confused!
da8458c to
df2e7e0
Compare
…args The init function of PodmanClient was never loading the system configuration when no kwargs were specified. This change makes it so that we load the core data (base_url and identity) from the config file. Signed-off-by: Anish Asthana <anishasthana1@gmail.com>
df2e7e0 to
4c537ee
Compare
The init function of PodmanClient was never loading the system configuration when no kwargs were specified. This change makes it so that we load the core data (base_url and identity) from the config file.