Make module prefer interval (if set) over min/max

Fix linting issues for True vs true

Fix up unit test related errors
This commit is contained in:
John Westcott IV 2020-03-26 10:57:32 -04:00 committed by beeankha
parent b9b62e3771
commit 914ea54925
3 changed files with 26 additions and 11 deletions

View File

@ -31,8 +31,7 @@ options:
interval:
description:
- The interval in sections, to request an update from Tower.
- For backwards compatability this will assume the value of min or max interval.
- Or if both are set it will average the two of them.
- For backwards compatability if unset this will be set to the average of min and max intervals
required: False
default: 1
type: float
@ -138,7 +137,10 @@ def main():
interval = module.params.get('interval')
if min_interval is not None or max_interval is not None:
interval = abs((module.params.get('min_interval', 1) + module.params.get('max_interval', 30)) / 2)
# We can't tell if we got the default or if someone actually set this to 1.
# For now if we find 1 and had a min or max then we will do the average logic.
if interval == 1:
interval = abs((module.params.get('min_interval', 1) + module.params.get('max_interval', 30)) / 2)
module.deprecate(
msg="min and max interval have been depricated, please use interval instead, interval will be set to {0}".format(interval),
version="3.7"
@ -152,7 +154,7 @@ def main():
})
if job is None:
module.fail_json(msg='Unable to wait, on job {0} that ID does not exist in Tower.'.format(job_id))
module.fail_json(msg='Unable to wait on job {0}; that ID does not exist in Tower.'.format(job_id))
job_url = job['url']

View File

@ -18,7 +18,7 @@ def test_job_wait_successful(run_module, admin_user):
assert result.pop('started', '')[:10] == str(job.started)[:10]
assert result == {
"status": "successful",
"success": True,
"changed": False,
"elapsed": str(job.elapsed),
"id": job.id
}
@ -36,10 +36,10 @@ def test_job_wait_failed(run_module, admin_user):
assert result == {
"status": "failed",
"failed": True,
"success": False,
"changed": False,
"elapsed": str(job.elapsed),
"id": job.id,
"msg": "Job with id=1 failed, error: Job failed."
"msg": "Job with id 1 failed"
}
@ -50,7 +50,6 @@ def test_job_wait_not_found(run_module, admin_user):
), admin_user)
result.pop('invocation', None)
assert result == {
"changed": False,
"failed": True,
"msg": "Unable to wait, no job_id 42 found: The requested object could not be found."
"msg": "Unable to wait on job 42; that ID does not exist in Tower."
}

View File

@ -33,6 +33,20 @@
- "'deprecations' in result"
- "'min and max interval have been depricated, please use interval instead, interval will be set to 15' in result['deprecations'][0]['msg']"
- name: Validate that interval superceeds min/max
tower_job_wait:
min_interval: 10
max_interval: 20
interval: 12
job_id: "99999999"
register: result
ignore_errors: true
- assert:
that:
- "'deprecations' in result"
- "'min and max interval have been depricated, please use interval instead, interval will be set to 12' in result['deprecations'][0]['msg']"
- name: Check module fails with correct msg
tower_job_wait:
job_id: "99999999"
@ -78,7 +92,7 @@
tower_job_wait:
job_id: "{{ job.id }}"
timeout: 5
ignore_errors: True
ignore_errors: true
register: wait_results
# Make sure that we failed and that we have some data in our results
@ -98,7 +112,7 @@
tower_job_wait:
job_id: "{{ job.id }}"
register: wait_results
ignore_errors: True
ignore_errors: true
- assert:
that: