-
Notifications
You must be signed in to change notification settings - Fork 45
[Role][1625]simple_role_to_get_job_status #2386
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
Open
AndreMarcel99
wants to merge
22
commits into
dev
Choose a base branch
from
role/1625/simple_role_to_get_job_status
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
46b90f4
Add folder of structure
49bce00
First iteration of the role
77ace04
Add test case
bcd89c4
Fix bad imports
32fc411
Add fragment
ae86699
Add documentation of the role
6f51284
Updated role doc generation
fernandofloresg e10515d
Updated makefile to remove residuals
fernandofloresg 324b94a
Updated docs
fernandofloresg d91c9c1
Updated ansible content
fernandofloresg fdccabc
Align documentation
3f28ba8
Merge branch 'dev' into role/1625/simple_role_to_get_job_status
AndreMarcel99 fcf7657
Update README.md
AndreMarcel99 5bc28f8
Merge branch 'dev' into role/1625/simple_role_to_get_job_status
AndreMarcel99 1a7c770
To try to validate dependency finder
fa44b94
Fix dependencyfinder
1f613d1
Handle errors and add to job status
4007e58
Avoid make None all
6230991
Update roles/job_status/README.md
AndreMarcel99 2422078
Update roles/job_status/README.md
AndreMarcel99 37ec7ae
Fix sanity
920b8cf
Fix sanity
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| trivial: | ||
| - zos_job_query - Enhanced to return proper status of a job_id. | ||
| (https://github.com/ansible-collections/ibm_zos_core/pull/2386). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # ibm.ibm_zos_core.job_status | ||
|
|
||
| This role gathers job status and if the jos is active about a giving a job_id. | ||
AndreMarcel99 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Role Variables | ||
|
|
||
| Tue only variable required is: | ||
richp405 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - `job_id`: ID of the job to query status and if is active or not. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| --- | ||
| - name: "Query job {{ job_id }}" | ||
| ibm.ibm_zos_core.zos_job_query: | ||
| job_name: "*" | ||
| owner: "*" | ||
| job_id: "{{ job_id }}" | ||
| register: jobs_status | ||
|
|
||
| - name: Normalize return values | ||
| ansible.builtin.set_fact: | ||
| jobs_list: "{{ jobs_status.jobs }}" | ||
| when: jobs_status is defined and jobs_status.jobs is defined and (jobs_status.jobs | length > 0) | ||
|
|
||
| - name: Extract ret_code.msg from {{ job_id }} | ||
| set_fact: | ||
| job_status: >- | ||
| {% set rc = jobs_list[0].ret_code | default({}) %} | ||
| {% if rc is mapping %} | ||
| {% if rc.msg is defined and rc.msg is not none and rc.msg|string != '' %} | ||
| {{ rc.msg | string | trim }} | ||
| {% elif rc.msg_txt is defined and rc.msg_txt is not none and rc.msg_txt|string != '' %} | ||
| {{ rc.msg_txt | string | trim }} | ||
| {% elif rc.message is defined and rc.message is not none and rc.message|string != '' %} | ||
| {{ rc.message | string | trim }} | ||
| {% else %} | ||
| UNKNOWN | ||
| {% endif %} | ||
| {% else %} | ||
| {{ rc | string | trim }} | ||
| {% endif %} | ||
| job_active_from_msg: "{{ 'AC' in (jobs_list[0].ret_code.msg | default('')) }}" | ||
|
|
||
| - name: Clean job_status value | ||
| set_fact: | ||
| job_status: "{{ job_status | trim }}" | ||
|
|
||
| - name: Verify if {{ job_id }} is found | ||
| when: jobs_list is not defined or jobs_list | length == 0 | ||
| set_fact: | ||
| job_status: "JOB_NOT_FOUND" | ||
| job_active_from_msg: "JOB_NOT_FOUND" | ||
|
|
||
| - name: See job_status and job_active from {{ job_id }} | ||
| ansible.builtin.debug: | ||
| msg: | ||
| job_status: "{{ job_status }}" | ||
| job_active: "{{ job_active_from_msg }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| # Copyright (c) IBM Corporation 2025 | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from __future__ import absolute_import, division, print_function | ||
|
|
||
| import pytest | ||
| __metaclass__ = type | ||
|
|
||
| def test_my_role_with_vars(ansible_zos_module): | ||
| hosts = ansible_zos_module | ||
|
|
||
| jobs = hosts.all.zos_job_query(job_id="*", owner="*") | ||
| for job in jobs.contacted.values(): | ||
| job_id = job.get("jobs")[0].get("job_id") | ||
|
|
||
| hosts.all.set_fact(job_id=job_id) | ||
| results = hosts.all.include_role(name="job_status") | ||
| for result in results.contacted.values(): | ||
| assert result.get("msg").get("job_active") is not None | ||
| assert result.get("msg").get("job_status") is not None |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is not set, will it still be returned as None or not returned at all ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would make sense to set them as none at the start of the function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It returns as None, but right better to be safe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we cover that case of been None