Skip to content
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

Free pyblijuju from relying on juju client when connecting to a controller #984

Merged
merged 2 commits into from
Nov 15, 2023

Conversation

cderici
Copy link
Contributor

@cderici cderici commented Nov 1, 2023

Description

This moves the computation of the controller_name from the connector to the Controller class, to be lazily evaluated from jujudata (and cached). We can move it out of the connector safely because:

1 - controller_name is not used within the connector.
2 - the only location that the controller_name is returned to, ignores it.

This has the nice consequence of freeing pylibjuju from relying on things like the controllers.yaml file (in turn the juju client to be installed) to connect to a controller.

Fixes #983

QA Steps

Added a test for lazy computation of controller_name.

 $ tox -e integration -- tests/integration/test_controller.py::test_connection_lazy_jujudata

But the scenario from the #983 can be tried easily as follows:

# make a new controller and connect it in a normal way:
from juju import controller
c = controller.Controller()
await c.connect()

# get the connection
conn = c.connection()

Now go move the .local/share/juju/controllers.yaml file temporarily.

# make a new controller
c2 = controller.Controller()

# connect it using the information within the connection we got above
await c2.connect(endpoint=conn.endpoints[0][0], cacert=conn.cacert, username=conn.usertag, password=conn.password)

Should succeed without any errors.

Don't forget to move back your controllers.yaml back so nothing else on your machine freaks out.

All CI tests need to pass.

Notes & Discussion

juju-4891

Instead of computing it in the connector in connection.

1 - controller_name is not used within the connector
2 - the only location that the controller_name is returned to, ignores it

This also frees pylibjuju from relying on things like the
controllers.yaml file (in turn the juju client) to connect to a
controller.

Fixes juju#983
@cderici cderici added kind/bug indicates a bug in the project hint/3.x going on main branch labels Nov 1, 2023
Copy link
Member

@jack-w-shaw jack-w-shaw left a comment

Choose a reason for hiding this comment

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

LGTM

@cderici
Copy link
Contributor Author

cderici commented Nov 15, 2023

CI fails are unrelated, @jack-w-shaw if you wanna tackle a bitesize thing, only a charm change would fix this one.

@cderici
Copy link
Contributor Author

cderici commented Nov 15, 2023

/merge

@jujubot jujubot merged commit 6aa065e into juju:master Nov 15, 2023
4 of 6 checks passed
@cderici cderici mentioned this pull request Nov 30, 2023
jujubot added a commit that referenced this pull request Nov 30, 2023
#988

## What's Changed

The main contribution of this release is the user secrets that's released as a part of Juju 3.3.

* Free pyblijuju from relying on juju client when connecting to a controller by @cderici in #984
* Handle FileNotFoundError on current_controller() by @DanielArndt in #937
* Add support for adding user secrets by @cderici in #986
* Complete support for user secrets by @cderici in #987

#### Notes & Discussion

JUJU-5079
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hint/3.x going on main branch kind/bug indicates a bug in the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Juju connect fails because it can't find controllers.yaml
3 participants