-
Notifications
You must be signed in to change notification settings - Fork 95
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
unit.run
output doesn't contain "results" field in v3.0.0, which breaks run_on_unit
function in zaza
#707
Comments
Hi @agileshaw, thanks for your detailed input! Yeah this is a result of an upstream change in the coming juju 3.0 api, things got confused a little bit because we wanted pylibjuju to support both 2.9 and 3.0 at the same time. I believe #706 should fix this. We'll keep working on it if it doesn't 👍 |
Hello @cderici . Thank you for the fast response. I would like to let you know that, unfortunately, v3.0.1 didn't solve the above-mentioned issue. It seems that the problem sits in the |
Ah yes I thought I saw So this is actually a change in the juju api before the juju 3.0. The tldr is, instead of getting the data like So, looks like you're using slightly older Juju from These sorts of breaking changes (that we had to do to support the Juju 3.0) are actually why we had a major version bump in python-libjuju. However, we're still trying to support What I'm doing right now is that I'm cleaning up the |
Thanks for the detailed explanation. In that case, I think zaza test would need to be updated to facilitate this API change once they unpin libjuju<3.0.0. I'm looking forward to the new PR and seeing the usage of the |
I was also wondering if it is possible to have the |
👀 i'm SUPER interested in this answer |
OK, so more info i'm getting different here's the setup
On Vsphere (addyess-vsphere k8s-vsphere/Boston 2.9.31)
on Azure (addyess-azure azure/centralus 2.9.33)
|
here's some fun antics i'm taking to "work-around" async def juju_run(unit: Unit, cmd):
action = await unit.run(cmd)
result = await action.wait()
code = str(result.results.get("Code") or result.results.get("return-code"))
stdout = result.results.get("Stdout") or result.results.get("stdout")
stderr = result.results.get("Stderr") or result.results.get("stderr")
assert code == "0", f"{cmd} failed ({code}): {stderr or stdout}"
return stdout |
... regardless of the version of the client and/or facade being used Fixes juju#707
To see why the internals of the received objects are different, I'd need to look at Juju's side of things @addyess. It is possible that |
I talked about your request in the PR a little bit, @agileshaw . I think it's valid (and also a very easy/cheap way for me to keep the backwards compatibility), however, I think it would only make sense if we were releasing for the |
juju#707 I agree there's inconsistency from the juju api response there. Since `action.wait()` ultimately just fills out the `results` dict more, what we we add some decode logic to the `Action` object to handle the various facades? Action could have an attribute that returned an object like `subprocess.CompletedProcess`[https://docs.python.org/3/library/subprocess.html#subprocess.CompletedProcess] users of the unit.run class could do this: ```python response = await unit.run(cmd) response.completed.check_returncode() # raises a known exception for non-zero return codes stdout = response.completed.stdout ```
I think it makes sense to do this, but from the other way around.
If we see that we are connecting to the 2.9 facade, massage the fields to
be consistent with the return values from the 3.0 request.
The end user still needs to update their code to be compatible with the 3.0
API, but they don't have to carry the burden of 2.9 compatibility in their
code tree as well.
…On Thu, Aug 11, 2022 at 7:57 PM Caner Derici ***@***.***> wrote:
I was also wondering if it is possible to have the action = await
action.wait() build into the run function when
self.connection.is_using_old_client is evaluated to be true. This way the
return object from this function would be consistent for both types of
connections.
I talked about your request in the PR a little bit, @agileshaw
<https://github.com/agileshaw> . I think it's valid (and also a very
easy/cheap way for me to keep the backwards compatibility), however, I
think it would only make sense if we were releasing for the 2.9 track. I
don't think it's a good idea to do that in the 3.0. You can see my
explanation in #710 <#710>.
Hope this helps, and hope #710
<#710> solves your issue 👍
—
Reply to this email directly, view it on GitHub
<#707 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABRQ7JQMSMOEAS7YPG3N6TVYWHOHANCNFSM56GLLYBA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
@cderici Thanks for the explanation and PR #710. I tend to agree with the approach suggested by @jameinel . Since the |
@agileshaw Now with the #710 landing the results should be consistent across the board. Also, see dcadb7a adds a little convenience flag to be used with the older versions, or for whoever wants to block until a result is there, hope it makes it easier for you to use 👍 |
#710 #### Description This is PR complements #706, and tries to address the issues being discussed in #707, by updating the `old_client`s with `2.9.34` schema and fixing the `unit.run()` function to be asynchronous, as it's (breakingly) changed to be in the `Juju 3.0`. This also brings `unit.run` and `unit.run_action` functions very close, the only difference is that the former is using `Action.Run` while the latter is using `Action.Enqueue` functions. It's plausible that one of these ways of doing the similar thing will disappear in the future since the newer versions of `Action.Run` is asynchronous anyway. Should fix the #707. #### QA Steps I updated the integration tests for `run()`, so basically all the tests in the following suite (that includes `test_run` and `test_run_action`) should pass: ```python tox -e integration -- tests/integration/test_unit.py ``` Additionally I added the example that I have been using myself to test this into the examples folder, so it should be running fine: ``` $ python examples/run_action.py ``` Both the integration tests (`test_run` & `test_run_action`) and the example module are tested in the following controllers: ``` Controller Model User Access Cloud/Region Models Nodes HA Version caner-k8s test admin superuser microk8s/localhost 2 - - 2.9.33 caner-k8s-2929 testhede admin superuser microk8s/localhost 2 - - 2.9.29 caner-k8s-2931 testhaylaz admin superuser microk8s/localhost 2 - - 2.9.31 caner-k8s-2934* haylazlar admin superuser microk8s/localhost 2 - - 2.9.34 caner-lxd-2.9 default admin superuser localhost/localhost 3 2 none 2.9.34.1 caner-lxd-2929 default admin superuser localhost/localhost 2 1 none 2.9.29 caner-lxd-2931 default admin superuser localhost/localhost 2 1 none 2.9.31 caner-lxd-2932 default admin superuser localhost/localhost 2 1 none 2.9.32 caner-lxd-3.0 canhiras admin superuser localhost/localhost 1 1 none 3.0-rc1.1 k8s-30 test4 admin superuser microk8s/localhost 2 - - 3.0-rc1 ``` Note that, all the clients that I used `<2.9.34` are using the `ActionFacade v6`, and the ones `>=2.9.34` are using the `ActionFacade v7` (regardless of `2.9` vs` 3.0`). #### Notes & Discussion One of the requests was to keep the `unit.run()` function synchronous for any client using `<ActionFacade v6`. While this is a valid request from the user perspective, it also means that we would have the same function returning different types (either a dictionary or an action object) depending on the facade being used, which would make it way harder to maintain. That's why I kept the change for all the versions.
With python-libjuju 3.0.0,
unit.run
returns less information than before, notably the absent of theresults
field. I think the commit causes this change is a1c4f20 (whenself.connection.is_using_old_client
is true).With 3.0.0
With 2.9.11
This causes the zaza functional tests failure when executing
run_on_unit
function.Additional information
The text was updated successfully, but these errors were encountered: