Skip to content

Commit

Permalink
Merge pull request #181 from openwisp/molecule
Browse files Browse the repository at this point in the history
[qa] Switch to molecule
  • Loading branch information
hispanico authored May 7, 2020
2 parents 98dcd3b + bd40432 commit 71a9878
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 399 deletions.
3 changes: 1 addition & 2 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
rulesdir:
- /home/travis/galaxy/rules
skip_list:
- '204'
- '301'
- '303'
- '306'
- '403'
exclude_paths:
- /home/travis/.ansible/roles/Stouts.postfix/
173 changes: 0 additions & 173 deletions .gitlab-ci.yml

This file was deleted.

63 changes: 22 additions & 41 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,52 +1,33 @@
---

os: linux
dist: bionic
language: python
services: docker
cache: pip
python: "3.7"

if: (type = pull_request) OR (branch = master)

env:
matrix:
- distro: 'ubuntu:18.04'
playbook: test.yml
- distro: debian:10
playbook: test.yml
- distro: 'ubuntu:18.04'
playbook: test_networktopology.yml
# we don't have the resources now to maintain these distros
# - distro: debian:9
# playbook: test.yml
# - distro: fedora:27
# playbook: test.yml
# - distro: fedora:28
# playbook: test.yml
# - distro: centos:7
# playbook: test.yml
# matrix:
# include:
# - dist: trusty
# python: "3.5"
# env:
# - distro: 'ubuntu:16.04'
# playbook: test.yml
global:
- ROLE_NAME: openwisp2
jobs:
- MOLECULE_DISTRO: ubuntu1804
- MOLECULE_DISTRO: debian10

jobs:
fast_finish: true

install:
# Install test dependencies.
- pip install molecule yamllint ansible-lint docker

before_script:
# Use actual Ansible Galaxy role name for the project directory.
- cd ../
- mv ansible-$ROLE_NAME openwisp.$ROLE_NAME
- cd openwisp.$ROLE_NAME

script:
# Configure test script so we can run extra tests after playbook is run.
- export container_id=$(date +%s)
- export cleanup=false
# run ansible-lint
- pip install ansible
- ansible-galaxy install -r tests/requirements.yml
- pip install ansible-lint
- ln -s $TRAVIS_BUILD_DIR ~/.ansible/roles/role_under_test
- git clone https://github.com/ansible/galaxy-lint-rules.git
- mv galaxy-lint-rules ~/galaxy
- ansible-lint tests/test.yml
- ansible-lint tests/test_networktopology.yml
# run ci tests
- ${PWD}/tests/runtests.sh
# Run tests.
- molecule test
- pip install "openwisp-utils[qa]>=0.4.0"
- openwisp-utils-qa-checks --skip-isort --skip-flake8 --skip-checkmigrations

Expand Down
7 changes: 7 additions & 0 deletions .yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---

extends: default
rules:
line-length:
max: 160
level: warning
21 changes: 21 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---

- name: Converge
hosts: all
become: true

vars:
openwisp2_network_topology: true

pre_tasks:
- name: Update apt cache.
apt: update_cache=true cache_valid_time=600
when: ansible_os_family == 'Debian'

- name: Remove the .dockerenv file
file:
path: /.dockerenv
state: absent

roles:
- role: openwisp.openwisp2
28 changes: 28 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---

dependency:
name: galaxy
driver:
name: docker
lint: |
set -e
# yamllint .
ansible-lint
platforms:
- name: "${ROLE_NAME:-instance}-${MOLECULE_DISTRO}"
image: "geerlingguy/docker-${MOLECULE_DISTRO}-ansible:${tag:-latest}"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
privileged: true
pre_build_image: true
provisioner:
name: ansible
playbooks:
converge: ${MOLECULE_PLAYBOOK:-converge.yml}
config_options:
defaults:
stdout_callback: yaml
bin_ansible_callbacks: yes
verifier:
name: ansible
File renamed without changes.
65 changes: 65 additions & 0 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---

- name: Verify
hosts: all
become: yes
gather_facts: no

tasks:
- name: Run a specific subset of tests
command: >
/opt/openwisp2/env/bin/python /opt/openwisp2/manage.py test --keepdb \
openwisp_controller.pki \
openwisp_controller.config.tests.test_config \
openwisp_controller.config.tests.test_controller \
openwisp_controller.config.tests.test_device \
openwisp_controller.config.tests.test_tag \
openwisp_controller.config.tests.test_template \
openwisp_controller.config.tests.test_views \
openwisp_controller.config.tests.test_vpn \
openwisp_controller.config.tests.test_admin.TestAdmin.test_preview_device \
openwisp_controller.config.tests.test_admin.TestAdmin.test_device_preview_button \
openwisp_controller.config.tests.test_admin.TestAdmin.test_template_preview_button \
openwisp_controller.config.tests.test_admin.TestAdmin.test_vpn_preview_button \
openwisp_controller.config.tests.test_admin.TestAdmin.test_device_queryset \
openwisp_controller.config.tests.test_admin.TestAdmin.test_device_organization_fk_queryset \
openwisp_controller.config.tests.test_admin.TestAdmin.test_device_organization_fk_queryset \
openwisp_controller.config.tests.test_admin.TestAdmin.test_device_templates_m2m_queryset \
openwisp_controller.config.tests.test_admin.TestAdmin.test_template_queryset \
openwisp_controller.config.tests.test_admin.TestAdmin.test_template_organization_fk_queryset \
openwisp_controller.config.tests.test_admin.TestAdmin.test_template_vpn_fk_queryset \
openwisp_controller.config.tests.test_admin.TestAdmin.test_vpn_queryset \
openwisp_controller.config.tests.test_admin.TestAdmin.test_vpn_organization_fk_queryset \
openwisp_controller.config.tests.test_admin.TestAdmin.test_vpn_ca_fk_queryset \
openwisp_controller.config.tests.test_admin.TestAdmin.test_vpn_cert_fk_queryset \
openwisp_controller.config.tests.test_admin.TestAdmin.test_changelist_recover_deleted_button \
openwisp_controller.config.tests.test_admin.TestAdmin.test_recoverlist_operator_403 \
openwisp_controller.config.tests.test_admin.TestAdmin.test_device_template_filter \
openwisp_controller.config.tests.test_admin.TestAdmin.test_device_contains_default_templates_js \
openwisp_controller.config.tests.test_admin.TestAdmin.test_template_not_contains_default_templates_js \
openwisp_controller.config.tests.test_admin.TestAdmin.test_vpn_not_contains_default_templates_js \
openwisp_controller.geo.tests.test_api
changed_when: false

- name: Check if redis-server is running
command: systemctl status redis-server
changed_when: false

- name: Chcke if redis is running
command: systemctl status redis
changed_when: false

- name: Ceck Openwisp
block:
- name: Check if OpenWISP is running
uri:
url: "https://{{ inventory_hostname }}/admin/login/?next=/admin/"
validate_certs: false
rescue:
- name: Get OpenWisp log
command: "tail -n 500 {{ openwisp2_path }}/log/*.log"
register: openwisp_log

- name: Show OpenWisp log
debug:
var: openwisp_log
2 changes: 2 additions & 0 deletions tasks/complete.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
when: '"created" in load_initial_data_result.stdout'
debug:
msg: "Change your admin password at https://{{ inventory_hostname }}/admin/password_change/"
tags:
- molecule-idempotence-notest
2 changes: 2 additions & 0 deletions tasks/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
group: "{{ www_group }}"
mode: 0775
recurse: yes
tags:
- molecule-idempotence-notest

- name: manage.py
notify: reload supervisor
Expand Down
Loading

0 comments on commit 71a9878

Please sign in to comment.