Skip to content

Conversation

@Aflynn50
Copy link
Contributor

The temporary file used to store the ca_cert was set to delete itself on close. This meant that when it was accessed multiple times it would no longer be present.

Set to not delete on close and to remove file when the proxy is deleted.

QA Steps

juju bootstrap microk8s
juju add-model default
juju deploy cos-lite

In python

from juju import model
m = model.Model()
await m.connect()
await m.create_offer("grafana:grafana-dashboard", "grafana-dashboards")
await m.disconnect()

Check all resource in /tmp have been cleaned up

Fixes #1040

The temporary file used to store the ca_cert was set to delete itself on
close. This meant that when it was accessed multiple times it would no
longer be present.
Copy link
Contributor

@cderici cderici left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with one small change needed 👍


def __del__(self):
self.close()
os.unlink(self.temp_ca_file.name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's handle the FileNotFoundError here ourselves and log a nice warning, instead of __del__ ignoring it and writes it onto the stderr verbatim. (exceptions raised within destructors are suppressed -- to avoid weird behaviors, like the exception handler trying to destroy the object -- thereby calling __del__ again -- see doc)

We really should stop using things like __del__ and turn this into a context by adding __enter__ and __exit__ to handle these things, but that's beyond the scope of this PR.

Copy link
Contributor Author

@Aflynn50 Aflynn50 Apr 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense I've got the connection logger and logged the error to that in __del__.

@Aflynn50 Aflynn50 force-pushed the fix-microk8s-proxy-issue branch from 0d4fbe8 to 7002122 Compare April 18, 2024 10:18
@Aflynn50
Copy link
Contributor Author

/merge

@jujubot jujubot merged commit 2c30901 into juju:master Apr 19, 2024
jujubot added a commit that referenced this pull request May 31, 2024
#1056

## What's Changed
* Make consume respect the controller name in the url by @Aflynn50 in #1038
* Fix multiline description in textarea in bug template GH workflow by @cderici in #1041
* Fix issue with microk8s proxy by @Aflynn50 in #1044
* add missing "revision" parameter to addModel step. by @Thanhphan1147 in #1043
* Add user api to pylibjuju documentation by @cderici in #1049

## New Contributors
* @Thanhphan1147 made their first contribution in #1043

**Full Changelog**: 3.4.0.0...3.5.0.0
jujubot added a commit that referenced this pull request May 23, 2025
…ng-to-existing-model

#1265

#### Description

#1044 fixed proxy object reuse some time ago
I accidentally undid that change in #1186 as I didn't realise that multiple connect/close calls were expected on a given instance.
This PR re-applies the change, and cleans up init.

(I've rearranged the initialisation order, because `__del__()` is run on a partially-initialised instance if `__init__()` fails half-way through. That's something that happens in unit tests, although unlikely to affect legitimate use.)

Fixes: #1264 creating offer fails when connecting to existing model

#### QA Steps

- No regression in unit or integration tests
- Eyeball the code change

All CI tests need to pass.

Fixes #1264
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Cannot create more than one offer

3 participants