Windows: A module for creating Toast notifications on Modern Windows versions. (#26675)

* replace duff commit version of win_toast

* change expire_mins to expire_secs and add example showing use of async

* fix metadata version to keep sanity --test validate-modules happy

* code review fixes and change expire_secs to expire_seconds

* add first pass integration tests for win_toast

* win_toast no longer fails if there are no logged in users to notify (it sets a toast_sent false if this happens)

* yaml lint clean up of setup.yml in win_toast integration tests

* improve exception and stack trace if the notifier cannot be created, following feedback from dag

* removed unwanted 'echo' input parameters from return vals; added to CHANGELOG.md, removed _seconds units from module params; updated tests to match
This commit is contained in:
jhawkesworth 2017-08-30 00:19:18 +01:00 committed by Jordan Borean
commit 8f9b885113
7 changed files with 332 additions and 0 deletions

View file

@ -0,0 +1 @@
windows/ci/group2

View file

@ -0,0 +1,13 @@
- name: Set up tests
include_tasks: setup.yml
- name: Test in normal mode
include_tasks: tests.yml
vars:
in_check_mode: no
- name: Test in check mode
include_tasks: tests.yml
vars:
in_check_mode: yes
check_mode: yes

View file

@ -0,0 +1,27 @@
- name: Get OS version
win_shell: '[Environment]::OSVersion.Version.Major'
register: os_version
- name: Get logged in user count (using explorer exe as a proxy)
win_shell: (get-process -name explorer -EA silentlyContinue).Count
register: user_count
- name: debug os_version
debug:
var: os_version
verbosity: 2
- name: debug user_count
debug:
var: user_count
verbosity: 2
- name: Set fact if toast cannot be made
set_fact:
can_toast: False
when: os_version.stdout|int < 10
- name: Set fact if toast can be made
set_fact:
can_toast: True
when: os_version.stdout|int >= 10

View file

@ -0,0 +1,106 @@
- name: Warn user
win_toast:
expire_seconds: 10
msg: Keep calm and carry on.
register: msg_result
ignore_errors: True
- name: Test msg_result when can_toast is true (normal mode, users)
assert:
that:
- not msg_result|failed
- msg_result.time_taken > 10
when:
- can_toast == True
- in_check_mode == False
- user_count.stdout|int > 0
- name: Test msg_result when can_toast is true (normal mode, no users)
assert:
that:
- not msg_result|failed
- msg_result.time_taken > 0.1
- msg_result.toast_sent == False
when:
- can_toast == True
- in_check_mode == False
- user_count.stdout|int == 0
- name: Test msg_result when can_toast is true (check mode, users)
assert:
that:
- not msg_result|failed
- msg_result.time_taken > 0.1
when:
- can_toast == True
- in_check_mode == True
- name: Test msg_result when can_toast is true (check mode, no users)
assert:
that:
- not msg_result|failed
- msg_result.time_taken > 0.1
- msg_result.toast_sent == False
when:
- can_toast == True
- in_check_mode == True
- user_count.stdout|int == 0
- name: Test msg_result when can_toast is false
assert:
that:
- msg_result|failed
when: can_toast == False
- name: Warn user again
win_toast:
expire_seconds: 10
msg: Keep calm and carry on.
register: msg_result2
ignore_errors: True
- name: Test msg_result2 when can_toast is true (normal mode, users)
assert:
that:
- not msg_result2|failed
- msg_result2.time_taken > 10
when:
- can_toast == True
- in_check_mode == False
- user_count.stdout|int > 0
- name: Test msg_result2 when can_toast is true (normal mode, no users)
assert:
that:
- not msg_result2|failed
- msg_result2.time_taken > 0.1
when:
- can_toast == True
- in_check_mode == False
- user_count.stdout|int == 0
- name: Test msg_result2 when can_toast is true (check mode, users)
assert:
that:
- not msg_result2|failed
- msg_result2.time_taken > 0.1
when:
- can_toast == True
- in_check_mode == False
- user_count.stdout|int > 0
- name: Test msg_result2 when can_toast is true (check mode, no users)
assert:
that:
- not msg_result2|failed
- msg_result2.time_taken > 0.1
when:
- can_toast == True
- in_check_mode == False
- user_count.stdout|int == 0
- name: Test msg_result2 when can_toast is false
assert:
that:
- msg_result2|failed
when: can_toast == False