Browse code

Create a dedicated windows-minimal test target. (#67987)

* Create a dedicated windows-minimal test target.

The windows-minimal target is a copy of the win_ping test, taking the place of that test as the windows minimal test run on multiple python versions.

It includes a private copy of the win_ping module so it will work after migration.

This will keep tests passing during the migration prep process.

* Update sanity ignores.

Matt Clay authored on 2020/03/04 11:36:37
Showing 11 changed files
... ...
@@ -1,3 +1,2 @@
1 1
 shippable/windows/group1
2
-shippable/windows/minimal
3 2
 shippable/windows/smoketest
4 3
new file mode 100644
... ...
@@ -0,0 +1,4 @@
0
+shippable/windows/group1
1
+shippable/windows/minimal
2
+shippable/windows/smoketest
3
+windows
0 4
new file mode 100644
... ...
@@ -0,0 +1,21 @@
0
+#!powershell
1
+
2
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
3
+
4
+#AnsibleRequires -CSharpUtil Ansible.Basic
5
+
6
+$spec = @{
7
+    options = @{
8
+        data = @{ type = "str"; default = "pong" }
9
+    }
10
+    supports_check_mode = $true
11
+}
12
+$module = [Ansible.Basic.AnsibleModule]::Create($args, $spec)
13
+$data = $module.Params.data
14
+
15
+if ($data -eq "crash") {
16
+    throw "boom"
17
+}
18
+
19
+$module.Result.ping = $data
20
+$module.ExitJson()
0 21
new file mode 100644
... ...
@@ -0,0 +1,55 @@
0
+#!/usr/bin/python
1
+# -*- coding: utf-8 -*-
2
+
3
+# Copyright: (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>, and others
4
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
+
6
+# this is a windows documentation stub.  actual code lives in the .ps1
7
+# file of the same name
8
+
9
+ANSIBLE_METADATA = {'metadata_version': '1.1',
10
+                    'status': ['stableinterface'],
11
+                    'supported_by': 'core'}
12
+
13
+DOCUMENTATION = r'''
14
+---
15
+module: win_ping
16
+version_added: "1.7"
17
+short_description: A windows version of the classic ping module
18
+description:
19
+  - Checks management connectivity of a windows host.
20
+  - This is NOT ICMP ping, this is just a trivial test module.
21
+  - For non-Windows targets, use the M(ping) module instead.
22
+  - For Network targets, use the M(net_ping) module instead.
23
+options:
24
+  data:
25
+    description:
26
+      - Alternate data to return instead of 'pong'.
27
+      - If this parameter is set to C(crash), the module will cause an exception.
28
+    type: str
29
+    default: pong
30
+seealso:
31
+- module: ping
32
+author:
33
+- Chris Church (@cchurch)
34
+'''
35
+
36
+EXAMPLES = r'''
37
+# Test connectivity to a windows host
38
+# ansible winserver -m win_ping
39
+
40
+- name: Example from an Ansible Playbook
41
+  win_ping:
42
+
43
+- name: Induce an exception to see what happens
44
+  win_ping:
45
+    data: crash
46
+'''
47
+
48
+RETURN = r'''
49
+ping:
50
+    description: Value provided with the data parameter.
51
+    returned: success
52
+    type: str
53
+    sample: pong
54
+'''
0 55
new file mode 100644
... ...
@@ -0,0 +1,31 @@
0
+#!powershell
1
+# This file is part of Ansible
2
+#
3
+# Ansible is free software: you can redistribute it and/or modify
4
+# it under the terms of the GNU General Public License as published by
5
+# the Free Software Foundation, either version 3 of the License, or
6
+# (at your option) any later version.
7
+#
8
+# Ansible is distributed in the hope that it will be useful,
9
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
+# GNU General Public License for more details.
12
+#
13
+# You should have received a copy of the GNU General Public License
14
+# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
15
+
16
+# POWERSHELL_COMMON
17
+
18
+$params = Parse-Args $args $true;
19
+
20
+$data = Get-Attr $params "data" "pong";
21
+
22
+$result = @{
23
+    changed = $false
24
+    ping = "pong"
25
+};
26
+
27
+# Test that Set-Attr will replace an existing attribute.
28
+Set-Attr $result "ping" $data
29
+
30
+Exit-Json $result;
0 31
new file mode 100644
... ...
@@ -0,0 +1,30 @@
0
+#!powershell
1
+# This file is part of Ansible
2
+#
3
+# Ansible is free software: you can redistribute it and/or modify
4
+# it under the terms of the GNU General Public License as published by
5
+# the Free Software Foundation, either version 3 of the License, or
6
+# (at your option) any later version.
7
+#
8
+# Ansible is distributed in the hope that it will be useful,
9
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
+# GNU General Public License for more details.
12
+#
13
+# You should have received a copy of the GNU General Public License
14
+# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
15
+
16
+# POWERSHELL_COMMON
17
+
18
+$params = Parse-Args $args $true;
19
+
20
+$params.thisPropertyDoesNotExist
21
+
22
+$data = Get-Attr $params "data" "pong";
23
+
24
+$result = @{
25
+    changed = $false
26
+    ping = $data
27
+};
28
+
29
+Exit-Json $result;
0 30
new file mode 100644
... ...
@@ -0,0 +1,30 @@
0
+#!powershell
1
+# This file is part of Ansible
2
+#
3
+# Ansible is free software: you can redistribute it and/or modify
4
+# it under the terms of the GNU General Public License as published by
5
+# the Free Software Foundation, either version 3 of the License, or
6
+# (at your option) any later version.
7
+#
8
+# Ansible is distributed in the hope that it will be useful,
9
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
+# GNU General Public License for more details.
12
+#
13
+# You should have received a copy of the GNU General Public License
14
+# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
15
+
16
+# POWERSHELL_COMMON
17
+
18
+$blah = 'I can't quote my strings correctly.'
19
+
20
+$params = Parse-Args $args $true;
21
+
22
+$data = Get-Attr $params "data" "pong";
23
+
24
+$result = @{
25
+    changed = $false
26
+    ping = $data
27
+};
28
+
29
+Exit-Json $result;
0 30
new file mode 100644
... ...
@@ -0,0 +1,30 @@
0
+#!powershell
1
+# This file is part of Ansible
2
+#
3
+# Ansible is free software: you can redistribute it and/or modify
4
+# it under the terms of the GNU General Public License as published by
5
+# the Free Software Foundation, either version 3 of the License, or
6
+# (at your option) any later version.
7
+#
8
+# Ansible is distributed in the hope that it will be useful,
9
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
+# GNU General Public License for more details.
12
+#
13
+# You should have received a copy of the GNU General Public License
14
+# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
15
+
16
+# POWERSHELL_COMMON
17
+
18
+throw
19
+
20
+$params = Parse-Args $args $true;
21
+
22
+$data = Get-Attr $params "data" "pong";
23
+
24
+$result = @{
25
+    changed = $false
26
+    ping = $data
27
+};
28
+
29
+Exit-Json $result;
0 30
new file mode 100644
... ...
@@ -0,0 +1,30 @@
0
+#!powershell
1
+# This file is part of Ansible
2
+#
3
+# Ansible is free software: you can redistribute it and/or modify
4
+# it under the terms of the GNU General Public License as published by
5
+# the Free Software Foundation, either version 3 of the License, or
6
+# (at your option) any later version.
7
+#
8
+# Ansible is distributed in the hope that it will be useful,
9
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
+# GNU General Public License for more details.
12
+#
13
+# You should have received a copy of the GNU General Public License
14
+# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
15
+
16
+# POWERSHELL_COMMON
17
+
18
+throw "no ping for you"
19
+
20
+$params = Parse-Args $args $true;
21
+
22
+$data = Get-Attr $params "data" "pong";
23
+
24
+$result = @{
25
+    changed = $false
26
+    ping = $data
27
+};
28
+
29
+Exit-Json $result;
0 30
new file mode 100644
... ...
@@ -0,0 +1,67 @@
0
+# test code for the win_ping module
1
+# (c) 2014, Chris Church <chris@ninemoreminutes.com>
2
+
3
+# This file is part of Ansible
4
+#
5
+# Ansible is free software: you can redistribute it and/or modify
6
+# it under the terms of the GNU General Public License as published by
7
+# the Free Software Foundation, either version 3 of the License, or
8
+# (at your option) any later version.
9
+#
10
+# Ansible is distributed in the hope that it will be useful,
11
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
+# GNU General Public License for more details.
14
+#
15
+# You should have received a copy of the GNU General Public License
16
+# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
17
+
18
+- name: test win_ping
19
+  action: win_ping
20
+  register: win_ping_result
21
+
22
+- name: check win_ping result
23
+  assert:
24
+    that:
25
+      - win_ping_result is not failed
26
+      - win_ping_result is not changed
27
+      - win_ping_result.ping == 'pong'
28
+
29
+- name: test win_ping with data
30
+  win_ping:
31
+    data: ☠
32
+  register: win_ping_with_data_result
33
+
34
+- name: check win_ping result with data
35
+  assert:
36
+    that:
37
+      - win_ping_with_data_result is not failed
38
+      - win_ping_with_data_result is not changed
39
+      - win_ping_with_data_result.ping == '☠'
40
+
41
+- name: test win_ping.ps1 with data as complex args
42
+  # win_ping.ps1: # TODO: do we want to actually support this? no other tests that I can see...
43
+  win_ping:
44
+    data: bleep
45
+  register: win_ping_ps1_result
46
+
47
+- name: check win_ping.ps1 result with data
48
+  assert:
49
+    that:
50
+      - win_ping_ps1_result is not failed
51
+      - win_ping_ps1_result is not changed
52
+      - win_ping_ps1_result.ping == 'bleep'
53
+
54
+- name: test win_ping using data=crash so that it throws an exception
55
+  win_ping:
56
+    data: crash
57
+  register: win_ping_crash_result
58
+  ignore_errors: yes
59
+
60
+- name: check win_ping_crash result
61
+  assert:
62
+    that:
63
+      - win_ping_crash_result is failed
64
+      - win_ping_crash_result is not changed
65
+      - 'win_ping_crash_result.msg == "Unhandled exception while executing module: boom"'
66
+      - '"throw \"boom\"" in win_ping_crash_result.exception'
... ...
@@ -8198,6 +8198,7 @@ test/integration/targets/win_script/files/test_script_with_splatting.ps1 pslint:
8198 8198
 test/integration/targets/win_stat/library/test_symlink_file.ps1 pslint:PSCustomUseLiteralPath
8199 8199
 test/integration/targets/win_template/files/foo.dos.txt line-endings
8200 8200
 test/integration/targets/win_user_right/library/test_get_right.ps1 pslint:PSCustomUseLiteralPath
8201
+test/integration/targets/windows-minimal/library/win_ping_syntax_error.ps1 pslint!skip
8201 8202
 test/lib/ansible_test/_data/requirements/constraints.txt test-constraints
8202 8203
 test/lib/ansible_test/_data/requirements/integration.cloud.azure.txt test-constraints
8203 8204
 test/lib/ansible_test/_data/sanity/pylint/plugins/string_format.py use-compat-six