Skip to content

Commit

Permalink
Adds tests for ufw support
Browse files Browse the repository at this point in the history
  • Loading branch information
asm0dey committed Aug 9, 2018
1 parent 2c28c05 commit 0ab0369
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 0 deletions.
17 changes: 17 additions & 0 deletions molecule/ufw/INSTALL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*******
Vagrant driver installation guide
*******

Requirements
============

* Vagrant
* Virtualbox, Parallels, VMware Fusion, VMware Workstation or VMware Desktop
* python-vagrant

Install
=======

.. code-block:: bash
$ sudo pip install python-vagrant
28 changes: 28 additions & 0 deletions molecule/ufw/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
dependency:
name: galaxy
driver:
name: vagrant
provider:
name: virtualbox
lint:
name: yamllint
platforms:
- name: xenial
box: ubuntu/xenial64
provider_raw_config_args:
- "customize ['modifyvm', :id, '--uartmode1', 'disconnected']"
- name: bionic
box: ubuntu/bionic64
provider_raw_config_args:
- "customize ['modifyvm', :id, '--uartmode1', 'disconnected']"
provisioner:
name: ansible
lint:
name: ansible-lint
scenario:
name: ufw
verifier:
name: goss
lint:
name: yamllint
6 changes: 6 additions & 0 deletions molecule/ufw/playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Converge
become: true
hosts: all
roles:
- role: 3proxy
9 changes: 9 additions & 0 deletions molecule/ufw/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: Prepare
hosts: all
gather_facts: false
tasks:
- name: Install python for Ansible
raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal)
become: true
changed_when: false
21 changes: 21 additions & 0 deletions molecule/ufw/tests/test_service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
package:
ufw:
installed: true
port:
tcp:1080:
listening: true
tcp:3128:
listening: true
service:
ufw:
enabled: true
running: true
command:
'grep ''### tuple ###'' /etc/ufw/*.rules':
exit-status: 0
stdout:
- allow tcp 1080
- allow tcp 3128
stderr: []
timeout: 10000
51 changes: 51 additions & 0 deletions molecule/ufw/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
# This is an example playbook to execute goss tests.
# Tests need distributed to the appropriate ansible host/groups
# prior to execution by `goss validate`.

- name: Verify
hosts: all
become: true
vars:
goss_version: v0.3.6
goss_arch: amd64
goss_dst: /usr/local/bin/goss
goss_url: "https://github.com/aelsabbahy/goss/releases/download/{{ goss_version }}/goss-linux-{{ goss_arch }}"
goss_test_directory: /tmp
goss_format: json_oneline
tasks:
- name: Download and install Goss
get_url:
url: "{{ goss_url }}"
dest: "{{ goss_dst }}"
mode: 0755
register: download_goss
until: download_goss is succeeded
retries: 3

- name: Copy Goss tests to remote
copy:
src: "{{ item }}"
dest: "{{ goss_test_directory }}/{{ item | basename }}"
with_fileglob:
- "{{ lookup('env', 'MOLECULE_VERIFIER_TEST_DIRECTORY') }}/test_*.yml"

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

- name: Execute Goss tests
command: "{{ goss_dst }} -g {{ item }} validate --format {{ goss_format }}"
register: test_results
with_items: "{{ test_files.stdout_lines }}"

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

- name: Fail when tests fail
fail:
msg: "Goss failed to validate"
when: item.rc != 0
with_items: "{{ test_results.results }}"

0 comments on commit 0ab0369

Please sign in to comment.