towerlib
towerlib copied to clipboard
How to pass multiple credentials to JobTemplate.launch?
awx 15.0.0 towerlib 3.4.1 python 3.8
I have a job template that needs multiple credentials. I can fetch the credentials with tower.get_credentials_by_name() and find the job template with tower.get_job_template_by_name().
JobTemplate.launch() takes a credential parameter. I have tried passing a list of the found credentials, and also their IDs (the docs don't say which is required), but neither succeeds.
job_template = tower.get_job_template_by_name(template_name)
extra_vars = {}
creds = [12,8] # (IDs fetched from get_credentials_by_name()
job = job_template.launch(extra_vars=extra_vars, credential=creds)
{"written_at": "2020-11-03T16:20:49.335Z", "written_ts": 1604420449335948000, "msg": "Unknown entity type None", "type": "log", "logger": "jobs", "thread": "Dummy-3", "level": "ERROR", "module": "job", "line_no": 75}
The error appears to be related to something internal to towerlib checking a type variable that I don't set.
Looked a bit further. I added credentials=None as a new parameter to launch()
The Unknown entity type None message seems to be because the Job constructor expects the response from awx to contain a type field, and it doesn't.
The launch() function creates what looks like a valid payload, but gets back the job template definition, not the job status JSON that I see if I run the same job from the awx cli.
Adding the credentials parameter, plus adding the first credential to credentials= seems to fix it.
job = job_template.launch(extra_vars=extra_vars, credentials=creds, credential=creds[0])
It would be cool if the docs described how to get a dev environment that works. e.g. so far:
- bootstrap script dies if your system python is 2.7, or even 3.6 (dataclasses), also if you don't have python 3.7 installed
- dev dependencies missing (betamax_serializers)
- tests are expecting awx on port 80, docker-compose fixtures (not mentioned at all in docs) run on 8052, postgres doesn't start.
As it is I can't get the existing tests to run before making a 2 line change, so I'll maintain my own fork for now. (the build script does work! :-) )
Hi @howardjones , thanks for the feedback. This library was build because awx is used internally and it covers the features we use but not everything as it is not an official redhat library. So apologies for not having everything working, but please feel free to submit an MR with anything that you think can improve the situation, whether that is code or documentation. I will gladly help if you need some clarifications but checking out features we do not use is not really doable with the load we are currently facing, so apologies for that.
You indeed need python3.7 and i dropped the serializers by accident :( The tests were very quickly put in place and were not given the love they deserve that is why they are not documented. If you care to help there it would be greatly appreciated :)
Are the tests normally run on something other than x64? The database that's baked into the fixtures doesn't load (the postgres container sits in a loop saying it can see data, but can't load it) which I think is part of the problem with that. As I mentioned, it's actually a 3 line change to add in the functionality that I need for our internal use, but I'd like to see that I haven't actively broken anything else. Followup: is there actually any data in that postgres database or do the tests and/or awx recreate it anyway?
For now, I built my own wheel and put it in the relevant repo.
There should be some default data in for some basic checks. Most tests create and delete to validate the lifecycle of the methods.
On Fri, Nov 6, 2020 at 9:46 AM Howard Jones [email protected] wrote:
Are the tests normally run on something other than x64? The database that's baked into the fixtures doesn't load (the postgres container sits in a loop saying it can see data, but can't load it) which I think is part of the problem with that. As I mentioned, it's actually a 3 line change to add in the functionality that I need for our internal use, but I'd like to see that I haven't actively broken anything else. Followup: is there actually any data in that postgres database or do the tests and/or awx recreate it anyway?
For now, I built my own wheel and put it in the relevant repo.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/schubergphilis/towerlib/issues/64#issuecomment-722955704, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABDMK22HB5HRXILANBN376DSOOZUTANCNFSM4TI6VZ3Q .
It would be cool if the docs described how to get a dev environment that works. e.g. so far:
* bootstrap script dies if your system python is 2.7, or even 3.6 (dataclasses), also if you don't have python 3.7 installed * dev dependencies missing (betamax_serializers) * tests are expecting awx on port 80, docker-compose fixtures (not mentioned at all in docs) run on 8052, postgres doesn't start.As it is I can't get the existing tests to run before making a 2 line change, so I'll maintain my own fork for now. (the build script does work! :-) )
I uploaded a patch version with the missing dependencies for now. Thanks for reporting!
Are the tests normally run on something other than x64? The database that's baked into the fixtures doesn't load (the postgres container sits in a loop saying it can see data, but can't load it) which I think is part of the problem with that. As I mentioned, it's actually a 3 line change to add in the functionality that I need for our internal use, but I'd like to see that I haven't actively broken anything else. Followup: is there actually any data in that postgres database or do the tests and/or awx recreate it anyway?
For now, I built my own wheel and put it in the relevant repo.
Just quickly checked the testing, it was supposed to be just a docker-compose up but it is indeed broken on my current Mac. Sadly, i do not have any time to look into it but I will try to schedule something next week to try to troubleshoot, fix and update documentation. Of course if someone (wink, wink) can save me the trouble I will be for ever in debt :) @howardjones
Hehe. The python side of things I understand, but not so much postgres. I'll poke at it some more in the next few days.
The postgres part is not really postgres specific, it is just postgres in docker as a backend for awx with a mount of the data on the local file system. It worked like this a year back, i swear :)
Hi @howardjones I am trying to get some colleagues involved with maintaining this and fixing the testing would be the first thing on the agenda.
That would be cool! I have another small patch waiting, actually (skip_tags on launch()). It'd be nice to be able to run tests - I might make larger additions with that confirmation.