Add winrm integration tests for raw, script and ping modules.

This commit is contained in:
Chris Church 2014-06-17 23:04:17 -05:00 committed by Matt Martz
parent fa0943a9b3
commit 0c938562a7
11 changed files with 241 additions and 0 deletions

View file

@ -46,6 +46,9 @@ test_vault:
ansible-playbook test_vault.yml -i $(INVENTORY) $(CREDENTIALS_ARG) -v $(TEST_FLAGS) --vault-password-file $(VAULT_PASSWORD_FILE) --syntax-check
ansible-playbook test_vault.yml -i $(INVENTORY) $(CREDENTIALS_ARG) -v $(TEST_FLAGS) --vault-password-file $(VAULT_PASSWORD_FILE)
test_winrm:
ansible-playbook test_winrm.yml -i inventory.winrm -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)
cloud: amazon rackspace
cloud_cleanup: amazon_cleanup rackspace_cleanup

View file

@ -70,3 +70,23 @@ resources. Running these tests may result in additional fees associated with
your cloud account. Care is taken to ensure that created resources are
removed. However, it is advisable to inspect your AWS console to ensure no
unexpected resources are running.
Windows Tests
=============
These tests exercise the winrm connection plugin and Windows modules. You'll
need to define an inventory with a remote Windows 2008 or 2012 Server to use
for testing, and enable PowerShell Remoting to continue.
Running these tests may result in changes to your Windows host, so don't run
them against a production/critical Windows environment.
Enable PowerShell Remoting (run on the Windows host via Remote Desktop):
Enable-PSRemoting -Force
Define Windows inventory:
cp inventory.winrm.template inventory.winrm
${EDITOR:-vi} inventory.winrm
Run the tests:
make test_winrm

View file

@ -0,0 +1,7 @@
[windows]
server ansible_ssh_host=10.10.10.10 ansible_ssh_user=Administrator ansible_ssh_pass=ShhhDontTellAnyone
[windows:vars]
ansible_connection=winrm
# HTTPS uses 5986, HTTP uses 5985
ansible_ssh_port=5985

View file

@ -0,0 +1,66 @@
---
- name: test win_ping
action: win_ping
register: win_ping_result
- name: check win_ping result
assert:
that:
- "not win_ping_result|failed"
- "not win_ping_result|changed"
- "win_ping_result.ping == 'pong'"
- name: test win_ping with data
win_ping: data=blah
register: win_ping_with_data_result
- name: check win_ping result with data
assert:
that:
- "not win_ping_with_data_result|failed"
- "not win_ping_with_data_result|changed"
- "win_ping_with_data_result.ping == 'blah'"
- name: test ping.ps1 with data
ping.ps1: data=bleep
register: ping_ps1_result
- name: check ping.ps1 result
assert:
that:
- "not ping_ps1_result|failed"
- "not ping_ps1_result|changed"
- "ping_ps1_result.ping == 'bleep'"
#- name: test ping.ps1 with invalid args
# ping.ps1: arg=invalid
# register: ping_ps1_invalid_args_result
#- name: check that ping.ps1 with invalid args fails
# assert:
# that:
# - "ping_ps1_invalid_args_result|failed"
# - "ping_ps1_invalid_args_result.msg"
- name: test local ping (should use default ping)
local_action: ping
register: local_ping_result
- name: check local ping result
assert:
that:
- "not local_ping_result|failed"
- "not local_ping_result|changed"
- "local_ping_result.ping == 'pong'"
- name: test ping (should use ping.ps1)
action: ping
register: ping_result
- name: check ping result
assert:
that:
- "not ping_result|failed"
- "not ping_result|changed"
- "ping_result.ping == 'pong'"

View file

@ -0,0 +1,56 @@
---
- name: run getmac
raw: getmac
register: getmac_result
- name: assert that getmac ran
assert:
that:
- "getmac_result.rc == 0"
- "getmac_result.stdout"
- "not getmac_result.stderr"
- "not getmac_result|failed"
- "not getmac_result|changed"
- name: run ipconfig with /all argument
raw: ipconfig /all
register: ipconfig_result
- name: assert that ipconfig ran with /all argument
assert:
that:
- "ipconfig_result.rc == 0"
- "ipconfig_result.stdout"
- "'Physical Address' in ipconfig_result.stdout"
- "not ipconfig_result.stderr"
- "not ipconfig_result|failed"
- "not ipconfig_result|changed"
- name: run ipconfig with invalid argument
raw: ipconfig /badswitch
register: ipconfig_invalid_result
ignore_errors: true
- name: assert that ipconfig with invalid argument failed
assert:
that:
- "ipconfig_invalid_result.rc != 0"
- "ipconfig_invalid_result.stdout" # ipconfig displays errors on stdout.
- "not ipconfig_invalid_result.stderr"
- "ipconfig_invalid_result|failed"
- "not ipconfig_invalid_result|changed"
- name: run an unknown command
raw: uname -a
register: unknown_result
ignore_errors: true
- name: assert that an unknown command failed
assert:
that:
- "unknown_result.rc != 0"
- "not unknown_result.stdout"
- "unknown_result.stderr" # An unknown command displays error on stderr.
- "unknown_result|failed"
- "not unknown_result|changed"

View file

@ -0,0 +1,2 @@
@ECHO OFF
ECHO We can even run a batch file!

View file

@ -0,0 +1,2 @@
# Test script to make sure the Ansible script module works.
Write-Host "Woohoo! We can run a PowerShell script via Ansible!"

View file

@ -0,0 +1,7 @@
# Test script to make sure the Ansible script module works when arguments are
# passed to the script.
foreach ($i in $args)
{
Write-Host $i;
}

View file

@ -0,0 +1,11 @@
# http://stackoverflow.com/questions/9948517/how-to-stop-a-powershell-script-on-the-first-error
#$ErrorActionPreference = "Stop";
# http://stackoverflow.com/questions/15777492/why-are-my-powershell-exit-codes-always-0
trap
{
Write-Error -ErrorRecord $_
exit 1;
}
throw "Oh noes I has an error"

View file

@ -0,0 +1,59 @@
---
- name: run simple test script
script: test_script.ps1
register: test_script_result
- name: check that script ran
assert:
that:
- "test_script_result.rc == 0"
- "test_script_result.stdout"
- "'Woohoo' in test_script_result.stdout"
- "not test_script_result.stderr"
- "not test_script_result|failed"
- "test_script_result|changed"
- name: run test script that takes arguments
script: test_script_with_args.ps1 /this /that /other
register: test_script_with_args_result
- name: check that script ran and received arguments
assert:
that:
- "test_script_with_args_result.rc == 0"
- "test_script_with_args_result.stdout"
- "test_script_with_args_result.stdout_lines[0] == '/this'"
- "test_script_with_args_result.stdout_lines[1] == '/that'"
- "test_script_with_args_result.stdout_lines[2] == '/other'"
- "not test_script_with_args_result.stderr"
- "not test_script_with_args_result|failed"
- "test_script_with_args_result|changed"
- name: run test script that has errors
script: test_script_with_errors.ps1
register: test_script_with_errors_result
ignore_errors: true
- name: check that script ran but failed with errors
assert:
that:
- "test_script_with_errors_result.rc != 0"
- "not test_script_with_errors_result.stdout"
- "test_script_with_errors_result.stderr"
- "test_script_with_errors_result|failed"
- "test_script_with_errors_result|changed"
- name: run simple batch file
script: test_script.bat
register: test_batch_result
- name: check that batch file ran
assert:
that:
- "test_batch_result.rc == 0"
- "test_batch_result.stdout"
- "'batch' in test_batch_result.stdout"
- "not test_batch_result.stderr"
- "not test_batch_result|failed"
- "test_batch_result|changed"

View file

@ -0,0 +1,8 @@
---
- hosts: windows
gather_facts: false
roles:
- { role: test_win_raw, tags: test_win_raw }
- { role: test_win_script, tags: test_win_script }
- { role: test_win_ping, tags: test_win_ping }