Skip to content
This repository was archived by the owner on Sep 16, 2020. It is now read-only.

Add --use-job-endpoint option for job launch.#184

Merged
jangsutsr merged 2 commits intoansible:masterfrom
jangsutsr:issue136
Aug 3, 2016
Merged

Add --use-job-endpoint option for job launch.#184
jangsutsr merged 2 commits intoansible:masterfrom
jangsutsr:issue136

Conversation

@jangsutsr
Copy link
Contributor

@jangsutsr jangsutsr commented Jul 29, 2016

Connect to #136.

Now user can use this flag to disable /job_templates/\d/launch/ endpoint during job launch.

(tower_cli_devel) sitan-OSX:tower-cli sitan$ tower-cli job launch --job-template 5 --use-job-endpoint -v
*** DETAILS: Getting the record. **********************************************
GET https://ec2-54-234-179-218.compute-1.amazonaws.com/api/v1/job_templates/5/
Params: {}

*** DETAILS: Creating the job. ************************************************
POST https://ec2-54-234-179-218.compute-1.amazonaws.com/api/v1/jobs/
Data: {u'type': u'job_template', u'url': u'/api/v1/job_templates/5/', u'related': {u'created_by': u'/api/v1/users/1/', u'labels': u'/api/v1/job_templates/5/labels/', u'inventory': u'/api/v1/inventories/1/', u'project': u'/api/v1/projects/4/', u'credential': u'/api/v1/credentials/1/', u'last_job': u'/api/v1/jobs/14/', u'notification_templates_error': u'/api/v1/job_templates/5/notification_templates_error/', u'notification_templates_success': u'/api/v1/job_templates/5/notification_templates_success/', u'jobs': u'/api/v1/job_templates/5/jobs/', u'object_roles': u'/api/v1/job_templates/5/object_roles/', u'notification_templates_any': u'/api/v1/job_templates/5/notification_templates_any/', u'access_list': u'/api/v1/job_templates/5/access_list/', u'launch': u'/api/v1/job_templates/5/launch/', u'schedules': u'/api/v1/job_templates/5/schedules/', u'activity_stream': u'/api/v1/job_templates/5/activity_stream/', u'survey_spec': u'/api/v1/job_templates/5/survey_spec/'}, u'summary_fields': {u'last_job': {u'id': 14, u'name': u'Demo Job Template [invoked via. Tower CLI]', u'description': u'', u'finished': u'2016-07-29T19:54:24.419Z', u'status': u'successful', u'failed': False}, u'last_update': {u'id': 14, u'name': u'Demo Job Template [invoked via. Tower CLI]', u'description': u'', u'status': u'successful', u'failed': False}, u'inventory': {u'id': 1, u'name': u'Demo Inventory', u'description': u'', u'has_active_failures': False, u'total_hosts': 1, u'hosts_with_active_failures': 0, u'total_groups': 0, u'groups_with_active_failures': 0, u'has_inventory_sources': False, u'total_inventory_sources': 0, u'inventory_sources_with_failures': 0}, u'credential': {u'id': 1, u'name': u'Demo Credential', u'description': u'', u'kind': u'ssh', u'cloud': False}, u'project': {u'id': 4, u'name': u'Demo Project', u'description': u'', u'status': u'successful'}, u'created_by': {u'id': 1, u'username': u'admin', u'first_name': u'', u'last_name': u''}, u'object_roles': {u'admin_role': {u'description': u'Can manage all aspects of the job template', u'id': 20, u'name': u'Admin'}, u'execute_role': {u'description': u'May run the job template', u'id': 22, u'name': u'Execute'}, u'read_role': {u'description': u'May view settings for the job template', u'id': 21, u'name': u'Read'}}, u'labels': {u'count': 9, u'results': [{u'id': 10, u'name': u'doushitui'}, {u'id': 6, u'name': u'fafa'}, {u'id': 7, u'name': u'guagua'}, {u'id': 3, u'name': u'haha'}, {u'id': 1, u'name': u'hey'}, {u'id': 4, u'name': u'hoho'}, {u'id': 8, u'name': u'kaka'}, {u'id': 9, u'name': u'touyixia'}, {u'id': 5, u'name': u'xiaxia'}]}, u'can_copy': True, u'can_edit': True, u'recent_jobs': [{u'status': u'successful', u'finished': u'2016-07-29T19:54:24.419Z', u'id': 14}, {u'status': u'successful', u'finished': u'2016-07-29T18:47:15.993Z', u'id': 12}, {u'status': u'successful', u'finished': u'2016-07-29T18:46:03.525Z', u'id': 10}, {u'status': u'successful', u'finished': u'2016-07-27T21:28:58.521Z', u'id': 8}, {u'status': u'successful', u'finished': u'2016-07-27T21:25:57.493Z', u'id': 6}, {u'status': u'successful', u'finished': u'2016-07-21T13:53:01.004Z', u'id': 2}]}, u'created': u'2016-07-21T13:49:56.384Z', u'modified': u'2016-07-29T19:52:06.800Z', u'name': u'Demo Job Template [invoked via. Tower CLI]', u'description': u'', u'job_type': u'run', u'inventory': 1, u'project': 4, u'playbook': u'hello_world.yml', u'credential': 1, u'cloud_credential': None, u'network_credential': None, u'forks': 0, u'limit': u'', u'verbosity': 0, u'job_tags': u'', u'force_handlers': False, u'skip_tags': u'', u'start_at_task': u'', u'last_job_run': u'2016-07-29T19:54:24.419178Z', u'last_job_failed': False, u'has_schedules': False, u'next_job_run': None, u'status': u'successful', u'host_config_key': u'', u'survey_enabled': False, u'become_enabled': False, u'allow_simultaneous': False, u'job_template': 5}

*** DETAILS: Asking for information necessary to start the job. ***************
GET https://ec2-54-234-179-218.compute-1.amazonaws.com/api/v1/jobs/16/start/
Params: {}

*** DETAILS: Launching the job. ***********************************************
POST https://ec2-54-234-179-218.compute-1.amazonaws.com/api/v1/jobs/16/start/
Data: {}

*** DETAILS: Asking for job status. *******************************************
GET https://ec2-54-234-179-218.compute-1.amazonaws.com/api/v1/jobs/16/
Params: {}

== ============ ======================== ======= ======= 
id job_template         created          status  elapsed 
== ============ ======================== ======= ======= 
16            5 2016-07-29T19:58:02.571Z pending
== ============ ======================== ======= =======

Note setting this flag will disable any prompt checkbox ---- jobs will be created with provided prompt-for fields regardless of whether their checkboxes on the server side is checked or not.

@coveralls
Copy link

coveralls commented Jul 29, 2016

Coverage Status

Coverage increased (+0.001%) to 98.829% when pulling c9cb98c on jangsutsr:issue136 into 056a01a on ansible:master.

# Get the job template from Ansible Tower.
# This is used as the baseline for starting the job.

tags = kwargs.get('tags', None)
Copy link
Member

Choose a reason for hiding this comment

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

I see what you're doing to maintain the same old use-pattern with tags here. But couldn't we remove all the special cases for tags if we did a single replacement at the start where we pop tags from kwargs and put re-insert it as job_tags? I don't see any reason this should be different from limit or skip_tags, aside from a quick substitution of the alias.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AlanCoding Great idea! But since this will be a pure restructure unrelated to any specific issue, shall we make an isolated PR for that after this one is merged?

Copy link
Member

Choose a reason for hiding this comment

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

sure, and for right here, the only reason this line about tags was added was because it was absorbed into kwargs. That's going in the right direction, so we'll leave it for now. I'm still gearing up to run some test cases with the feature in general right now.

@AlanCoding
Copy link
Member

I'm going to past some abbreviated output:

$ tower-cli job launch --job-template "Hello World" --limit "pi" --tags "tag1" --use-job-endpoint -v
*** DETAILS: Getting the record. **********************************************
GET http://alantowerhost.com/api/v1/job_templates/27/
Params: {}

*** DETAILS: Getting version of Tower. ****************************************
GET http://alantowerhost.com/api/v1/config/
Params: {}

*** DETAILS: Creating the job. ************************************************
POST http://alantowerhost.com/api/v1/jobs/
Data: {
...(data removed)
u'limit': u'', 
u'verbosity': 0, 
u'job_tags': u'tag1',
...(data removed)
}

*** DETAILS: Asking for information necessary to start the job. ***************
GET http://alantowerhost.com/api/v1/jobs/35/start/
Params: {}

*** DETAILS: Launching the job. ***********************************************
POST http://alantowerhost.com/api/v1/jobs/35/start/
Data: {u'tags': u'tag1', u'limit': u'pi'}

*** DETAILS: Asking for job status. *******************************************
GET http://192.168.100.128:8013/api/v1/jobs/35/
Params: {}

Resource changed.
== ============ ======================== ======= ======= 
id job_template         created          status  elapsed 
== ============ ======================== ======= ======= 
35           27 2016-08-02T20:50:20.423Z pending
== ============ ======================== ======= ======= 

I see that job_tags are getting correctly passed into the job creation here. However, limit is not for some reason. These shouldn't behave any differently, and I don't think it will be hard to get them both working correctly. The user should be able to overwrite any JT variables on launch with this method.

Also, passing the data to the job /start/ endpoint is ineffective. I believe that all the data that goes in that POST is ignored. So you can continue to provide it in that circumstance (no harm in it), but it can not be relied on to pass data into the job run (like with the JT launch endpoint). After I launched the job, I GET the job data, and see that limit is an empty string but job_tags gives tag1.

@jangsutsr
Copy link
Contributor Author

@AlanCoding Thx for pointing out, will look into it. As for the redundant data, I found it annoying too. But since it works anyway, and altering the original design would probably cause back compatibility issues, let us leave it be for now.

@coveralls
Copy link

coveralls commented Aug 3, 2016

Coverage Status

Coverage increased (+0.2%) to 98.989% when pulling d10515c on jangsutsr:issue136 into 056a01a on ansible:master.

@AlanCoding
Copy link
Member

👍 re-tested this and confirmed that --tags gets included as job_tags and limit gets passed into the creation of the job as well.

@jangsutsr jangsutsr merged commit c38ee78 into ansible:master Aug 3, 2016
@jangsutsr jangsutsr removed the review label Aug 3, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants