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

How to pass multiple credentials to JobTemplate.launch? #64

Open
howardjones opened this issue Nov 3, 2020 · 13 comments
Open

How to pass multiple credentials to JobTemplate.launch? #64

howardjones opened this issue Nov 3, 2020 · 13 comments

Comments

@howardjones
Copy link
Contributor

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.

@howardjones
Copy link
Contributor Author

howardjones commented Nov 4, 2020

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.

@howardjones
Copy link
Contributor Author

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])

@howardjones
Copy link
Contributor Author

howardjones commented Nov 5, 2020

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! :-) )

@costastf
Copy link
Collaborator

costastf commented Nov 6, 2020

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.

@costastf
Copy link
Collaborator

costastf commented Nov 6, 2020

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 :)

@howardjones
Copy link
Contributor Author

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.

@costastf
Copy link
Collaborator

costastf commented Nov 6, 2020 via email

@costastf
Copy link
Collaborator

costastf commented Nov 6, 2020

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!

@costastf
Copy link
Collaborator

costastf commented Nov 6, 2020

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

@howardjones
Copy link
Contributor Author

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.

@costastf
Copy link
Collaborator

costastf commented Nov 6, 2020

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 :)

@costastf
Copy link
Collaborator

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.

@howardjones
Copy link
Contributor Author

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.

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

No branches or pull requests

2 participants