Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added module win_pester and relatives integration tests #37343

Merged
merged 18 commits into from Apr 6, 2018
Merged

Added module win_pester and relatives integration tests #37343

merged 18 commits into from Apr 6, 2018

Conversation

equelin
Copy link
Contributor

@equelin equelin commented Mar 13, 2018

SUMMARY

Run Pester tests with Ansible on Windows hosts.

You may integrate this module in your Ansible workflow to check if the configuration of your Windows host is correct after running your playbook.

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

win_pester

ANSIBLE VERSION
2.5
ADDITIONAL INFORMATION

Options

parameter required default choices comments
src true (string) Specifies the source path of the test files on the remote host. Could be files or folder. If a folder, the module will try to run Pester tests with all ps1 files available in it.
version false (string) Specifies the minimum version of the Pester module that has to be available on the remote host.

Examples

- name: Run Pester test(s) in the file C:\Pester\test01.test.ps1
  win_pester:
    src: C:\Pester\test01.test.ps1

- name: Run Pester test(s) located in the 'C:\Pester' folder and defining the minimum version of the pester module
  win_pester:
    src: C:\Pester
    version: '3.4.0'

Return Values

name description returned type sample
pester_result Data returned by the Pester module success
pester_version Version of the Pester module find on the remote host string '4.1.0'

Playbook

This playbook will copy the Pester tests files on the remote hosts, run the tests and verified if a test failed. The tests files are deleted at the end.

- name: Test out win_pester module
  hosts: windows
  vars:
    local_test_files:
      - "files/test01.test.ps1"
      - "files/test02.test.ps1"
    remote_test_folder: C:\Pester\

  tasks:
    - name : Copy test file(s)
      win_copy:
        src: "{{ item }}"
        dest: "{{ remote_test_folder }}"
      with_items: "{{local_test_files}}"

    - name: Run Pester test(s) located in a folder and defining the minimum version of the pester module
      win_pester:
        src: "{{ remote_test_folder }}"
        version: '3.4.0'
      register: result

    - name: Check if one of the Pester tests failed
      assert:
        that: result.pester_result.FailedCount == 0

    - name: Delete test folder
      win_file:
        path: "{{ remote_test_folder }}"
        state: absent

@ansibot
Copy link
Contributor

ansibot commented Mar 13, 2018

@ansibot ansibot added module This issue/PR relates to a module. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. needs_triage Needs a first human triage before being processed. new_module This PR includes a new module. new_plugin This PR includes a new plugin. support:community This issue/PR relates to code supported by the Ansible community. test This PR relates to tests. windows Windows community labels Mar 13, 2018
@ryansb ryansb removed the needs_triage Needs a first human triage before being processed. label Mar 13, 2018
@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. community_review In order to be merged, this PR must follow the community review workflow. labels Mar 13, 2018
If (Get-Module -Name $Module -ListAvailable -ErrorAction SilentlyContinue) {
Import-Module $Module
} else {
Fail-Json -obj $result -message "Cannot find module: $Module"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a little thing, but it would be nice to prompt the user to check if pester is installed and suggest they install it via win_psmodule or win_chocolatey as appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the best way to prompt informations to users ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I could have been clearer. I just mean it would be nice to add more information to the -message string to suggest to the user how they could fix the problem where the pester module cannot be loaded by Get-Module. Something like
Fail-Json -obj $result -message "Cannot find module: $Module. Check if pester is installed, and if it is not, install using win_psmodule or win_chocolatey."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jhawkesworth I've modified the code with your recommendations .

- name: Get facts
setup:

- name: Add Pester module
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider adding these steps to the examples so users can know how to ensure they have pre-requisites for running the module.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing !

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done !

@jhawkesworth
Copy link
Contributor

I think this would be a nice module to have.

I see that the module documentation isn't passing the sanity checks currently.

A quick way to check that the module documentation at least parses is to run 'ansible-doc win_pester'. You can of course run the same sanity tests like this from root of ansible source code.

test/runner/ansible-test sanity --test validate-modules win_pester

Hope this helps and that we can eventually get this module included into Ansible

By the way, do you have any links you would recommend for getting started with pester - its not something I have made any use of?

@equelin equelin changed the title Added module win_pester and relatives integration tests [WIP] Added module win_pester and relatives integration tests Mar 15, 2018
@ansibot ansibot added the WIP This issue/PR is a work in progress. Nevertheless it was shared for getting input from peers. label Mar 15, 2018
@equelin
Copy link
Contributor Author

equelin commented Mar 15, 2018

Hello @jhawkesworth,

Thanks for the feedback ! I'll try to implement your comments as soon as possible.

You'll find a lot of documentations about Pester directly on the Pester GitHub wiki. I'm quiet sure you'll find something useful ;-)

@ansibot ansibot added the ci_verified Changes made in this PR are causing tests to fail. label Mar 15, 2018
@ansibot ansibot removed the ci_verified Changes made in this PR are causing tests to fail. label Mar 15, 2018
@dagwieers
Copy link
Contributor

I think we can remove the [WIP] in the title ;-)

}

# Run Pester tests
If (Test-Path -Path $path -PathType Leaf) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I would be expecting -LiteralPath everywhere unless this is not needed.

@jborean93 You have a good perspective on this.

@equelin equelin changed the title [WIP] Added module win_pester and relatives integration tests Added module win_pester and relatives integration tests Mar 16, 2018
@equelin
Copy link
Contributor Author

equelin commented Mar 16, 2018

Thanks for your help @dagwieers. I'm learning a lot ;-)

@ansibot ansibot removed the WIP This issue/PR is a work in progress. Nevertheless it was shared for getting input from peers. label Mar 16, 2018
- Run Pester tests on Windows hosts.
- Test files have to be available on the remote host.
requirements:
- The Pester module should be present on the remote host.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You only need to list the component name (and optionally minimum version). The documentation will generate the supporting text.

@ansibot
Copy link
Contributor

ansibot commented Mar 17, 2018

@LiranNis @SamLiu79 @timothyvandenbrande @andrewsaraceni @ar7z1 @blakfeld @brianlloyd @chrishoffman @daBONDi @elventear @henrikwallstrom @if-meaton @joshludwig @marqelme @nwchandler @nwsparks @petemounce @ptemplier @rndmh3ro @schwartzmx @smadam813 @themiwi @tksarah

As a maintainer of a module in the same namespace this new module has been submitted to, your vote counts for shipits. Please review this module and add shipit if you would like to see it merged.

click here for bot help

@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Mar 17, 2018
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Mar 25, 2018
@jhawkesworth
Copy link
Contributor

Looks good to me

shipit

@jhawkesworth
Copy link
Contributor

bot_status

@ansibot
Copy link
Contributor

ansibot commented Apr 6, 2018

Components

lib/ansible/modules/windows/win_pester.ps1
support: community
maintainers: dagwieers jborean93 jhawkesworth nitzmahone

lib/ansible/modules/windows/win_pester.py
support: community
maintainers: dagwieers jborean93 jhawkesworth nitzmahone

test/integration/targets/win_pester/aliases
support: community
maintainers:

test/integration/targets/win_pester/defaults/main.yml
support: community
maintainers:

test/integration/targets/win_pester/files/test01.test.ps1
support: community
maintainers:

test/integration/targets/win_pester/files/test02.test.ps1
support: community
maintainers:

test/integration/targets/win_pester/tasks/main.yml
support: community
maintainers:

Metadata

waiting_on: maintainer
changes_requested_by: null
needs_info: False
needs_revision: False
needs_rebase: False
merge_commits: []
mergeable_state: clean
shippable_status: success
maintainer_shipits (module maintainers): 0
community_shipits (namespace maintainers): 0
ansible_shipits (core team members): 1
shipit_actors (maintainers or core team members): jhawkesworth
shipit_actors_other: []
automerge: automerge shipit test failed

click here for bot help

@jhawkesworth
Copy link
Contributor

bot doesn't automerge new modules apparently.
since this has been discussed at Windows Working Group and there were no objections, and the code looks good to me, I'm merging this.

@ansibot ansibot removed the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Apr 6, 2018
@jhawkesworth jhawkesworth merged commit 49aac5f into ansible:devel Apr 6, 2018
ilicmilan pushed a commit to ilicmilan/ansible that referenced this pull request Nov 7, 2018
* Added module win_pester and relatives integration tests

* Corrected issues as stated by ansible-test

* Added defaults variable in integration tests

* Added task to install Pester if needed in the integration test

* Corrected error in win_psmodule task

* Added Pester installation with Chocolatey when Powershell version < 5

* Get facts...

* Disabled invoke-pester output

* Added pester_result type

* Added jhawkesworth changes proposal

* Corrected documentation linting

* Corrected linting

* Added dagwieers recommendations

* Added dagwieers recommendations

* Corrected linting errors and task error in integration test

* Corrected error in integration test

* Added dagwieers recommendations

* Corrected requirements in the DOCUMENTATION block
@ansible ansible locked and limited conversation to collaborators Apr 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. new_module This PR includes a new module. new_plugin This PR includes a new plugin. support:community This issue/PR relates to code supported by the Ansible community. test This PR relates to tests. windows Windows community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants