From 30da7a363c8ca4f95ae1de90387c38661c1ef8a9 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Fri, 18 Jan 2019 22:41:29 -0500 Subject: [PATCH] allows loop pause for subseconds (#50461) * allows loop pause for subseconds * skip test on os x and bsd since date commands lacks nano fixes #49951 --- changelogs/fragments/pause_subsecs.yml | 2 ++ lib/ansible/playbook/loop_control.py | 2 +- test/integration/targets/loops/tasks/main.yml | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/pause_subsecs.yml diff --git a/changelogs/fragments/pause_subsecs.yml b/changelogs/fragments/pause_subsecs.yml new file mode 100644 index 00000000000..8819f4a7e05 --- /dev/null +++ b/changelogs/fragments/pause_subsecs.yml @@ -0,0 +1,2 @@ +minor_changes: + - loop_control's pause now allows for fractions of a second diff --git a/lib/ansible/playbook/loop_control.py b/lib/ansible/playbook/loop_control.py index 9e3cbb76a8f..d840644fc81 100644 --- a/lib/ansible/playbook/loop_control.py +++ b/lib/ansible/playbook/loop_control.py @@ -28,7 +28,7 @@ class LoopControl(FieldAttributeBase): _loop_var = FieldAttribute(isa='str', default='item') _index_var = FieldAttribute(isa='str') _label = FieldAttribute(isa='str') - _pause = FieldAttribute(isa='int', default=0) + _pause = FieldAttribute(isa='float', default=0) _extended = FieldAttribute(isa='bool') def __init__(self): diff --git a/test/integration/targets/loops/tasks/main.yml b/test/integration/targets/loops/tasks/main.yml index c46c165d99b..c0a4f14da08 100644 --- a/test/integration/targets/loops/tasks/main.yml +++ b/test/integration/targets/loops/tasks/main.yml @@ -23,6 +23,25 @@ that: - '(after.stdout |int) - (before.stdout|int) >= 4' +- name: test subsecond pause + block: + - name: Measure time before loop with .5s pause + set_fact: + times: "{{times|default([]) + [ lookup('pipe','date +%s.%3N') ]}}" + with_sequence: count=3 + loop_control: + pause: 0.6 + + - name: ensure lag, since there is 3 rounds, and 0.5 seconds between, it should last 1.2 seconds, but allowing leeway due to CI lag + assert: + that: + - tdiff|float >= 1.2 + - tdiff|int < 3 + vars: + tdiff: '{{ times[2]|float - times[0]|float }}' + when: + - ansible_facts['distribution'] not in ("MacOSX", "FreeBSD") + # # Tests of loop syntax with args #