Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #107 from jaredledvina/feature/fixup-module-tests
Browse files Browse the repository at this point in the history
Tests: Use filetree to include all module tests
  • Loading branch information
jaredledvina authored Jun 15, 2019
2 parents 7dbb761 + 2519433 commit 678b074
Show file tree
Hide file tree
Showing 17 changed files with 200 additions and 246 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ group: xenial
language: python
python: "2.7"
env:
global:
- ANSIBLE_MODULE_UTILS=$TRAVIS_BUILD_DIR/module_utils
matrix:
- SCENARIO=debian
- SCENARIO=ubuntu
- SCENARIO=centos
Expand Down
68 changes: 6 additions & 62 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
---
- name: restart sensu-backend
- name: Restart sensu-backend
service:
name: sensu-backend
state: restarted
notify: wait for sensu-backend to accept connections
notify: Wait for sensu-backend to accept connections
when: sensu_go_final_services.backend.state != 'stopped'

- name: wait for sensu-backend to accept connections
- name: Wait for sensu-backend to accept connections
wait_for:
port: 8081
connect_timeout: 1

- name: restart sensu-agent
- name: Restart sensu-agent
service:
name: sensu-agent
state: restarted
when: sensu_go_final_services.agent.state != 'stopped'

- name: update apt cache
- name: Update apt cache
apt:
update_cache: true

- name: yum-clean-metadata
- name: Clean yum metadata
command: yum clean metadata
args:
warn: no
8 changes: 3 additions & 5 deletions library/sensu_go_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
password:
aliases:
- url_password
default: P@ssword!
default: P@ssw0rd!
description:
- "Password to use when initially authenticating to the Sensu Go API."
- "Can be overriden with the environmental variable C(ANSIBLE_SENSU_GO_PASSWORD)"
Expand Down Expand Up @@ -284,18 +284,16 @@ def run_module():
low_flap_threshold=dict(type='int', default=0),
metadata=dict(
type='dict',
elements='dict',
options=dict(
annotations=dict(type='dict', elements='dict'),
labels=dict(type='dict', elements='dict')
annotations=dict(type='dict'),
labels=dict(type='dict')
)
),
output_metric_format=dict(type='str', default='', choices=['', 'nagios_perfdata', 'graphite_plaintext', 'influxdb_line', 'opentsdb_line']),
output_metric_handlers=dict(type='list', elements='str'),
proxy_entity_name=dict(type='str', default=''),
proxy_requests=dict(
type='dict',
elements='dict',
options=dict(
entity_attributes=dict(type='list', elements='tr'),
splay=dict(type='bool', default=False),
Expand Down
2 changes: 1 addition & 1 deletion module_utils/sensu_go.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, argument_spec, attributes, resource, **kwargs):
),
url_password=dict(
type='str',
default='P@ssword!',
default='P@ssw0rd!',
no_log=True,
aliases=['password'],
fallback=(env_fallback, ['ANSIBLE_SENSU_GO_PASSWORD'])
Expand Down
2 changes: 2 additions & 0 deletions molecule/debian/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ verifier:
directory: ../shared/
lint:
name: rubocop
env:
ANSIBLE_LIBRARY: ../../library/
65 changes: 65 additions & 0 deletions molecule/shared/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
- name: Install system dependencies for Inspec
package:
name: "{{ item }}"
state: present
with_items: "{{ inspec_package_deps }}"

- name: Download Inspec
get_url:
url: "{{ inspec_downloads[inspec_version]['url'] }}"
dest: "{{ inspec_download_source_dir }}"
sha256sum: "{{ inspec_downloads[inspec_version]['sha256'] }}"
mode: 0755
register: inspec_download

- name: Install Inspec
yum:
name: "{{ inspec_download.dest }}"
state: latest
when: ansible_pkg_mgr == 'yum'

- name: Install Inspec
dnf:
name: "{{ inspec_download.dest }}"
state: latest
when: ansible_pkg_mgr == 'dnf'

- name: Install Inspec
apt:
deb: "{{ inspec_download.dest }}"
state: present
when: ansible_pkg_mgr == 'apt'

- name: Create Molecule directory for test files
file:
path: "{{ inspec_test_directory }}"
state: directory

- name: Copy Inspec tests to remote
copy:
src: "{{ item }}"
dest: "{{ inspec_test_directory }}/{{ item | basename }}"
with_fileglob:
- "{{ playbook_dir }}/tests/test_*.rb"

- name: Register test files
shell: "ls {{ inspec_test_directory }}/test_*.rb"
register: test_files

- name: Execute Inspec tests
command: "{{ inspec_bin }} exec --chef-license accept {{ item }} --no-color --reporter progress"
register: test_results
with_items: "{{ test_files.stdout_lines }}"
ignore_errors: true

- name: Display details about the Inspec results
debug:
msg: "{{ item.stdout_lines }}"
with_items: "{{ test_results.results }}"

- name: Fail when tests fail
fail:
msg: "Inspec failed to validate"
when: item.rc != 0
with_items: "{{ test_results.results }}"
101 changes: 101 additions & 0 deletions molecule/shared/modules/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
- name: Ensure https on http fails
sensu_go_check:
name: check_test
host: localhost
state: present
command: /bin/true
interval: 120
protocol: https
register: https_on_http
failed_when: https_on_http is not failed
- name: Ensure agent port fails
sensu_go_check:
name: check_test
host: localhost
state: present
command: /bin/true
interval: 120
port: 8081
validate_certs: False
register: agent_port
failed_when: agent_port is not failed
- name: Ensure unknown host fails
sensu_go_check:
name: check_test
state: present
command: /bin/true
interval: 120
host: what.is.this
register: unknown_host
failed_when: unknown_host is not failed
- name: Ensure bad password fails
sensu_go_check:
name: check_test
host: localhost
state: present
command: /bin/true
interval: 120
password: thisisnottherightpassword
register: bad_password
failed_when: bad_password is not failed
- name: Ensure nonexistant namespace fails
sensu_go_check:
name: check_test
host: localhost
state: present
command: /bin/true
interval: 120
namespace: thisdoesnotexist
register: bad_namespace
failed_when: bad_namespace is not failed
- name: Ensure interval and cron fails
sensu_go_check:
name: check_test
host: localhost
state: present
command: /bin/true
interval: 120
cron: "* * * * * *"
register: interval_and_cron
failed_when: interval_and_cron is not failed
- name: Ensure check_example is configured
sensu_go_check:
name: check_example
host: localhost
command: /bin/true
interval: 300
subscriptions: all
- name: Ensure check_example is already configured
sensu_go_check:
name: check_example
host: localhost
command: /bin/true
interval: 300
subscriptions: all
register: check_example_already_configured
failed_when: check_example_already_configured is changed
- name: Ensure check_example is changed
sensu_go_check:
name: check_example
host: localhost
command: /bin/true
interval: 120
timeout: 120
metadata:
annotations:
ansible_managed: "true"
ttl: 300
subscriptions: all
- name: Ensure check_example is absent
sensu_go_check:
name: check_example
host: localhost
state: absent
- name: Ensure check_example is already absent
sensu_go_check:
name: check_example
host: localhost
state: absent
register: check_example_is_already_absent
failed_when: check_example_is_already_absent is changed
Loading

0 comments on commit 678b074

Please sign in to comment.