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

feature tests #15

Merged
merged 24 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
ANSIBLE_VIRTUALENV ?= .venv
ANSIBLE_PYTHON := $(ANSIBLE_VIRTUALENV)/bin/python3
ANSIBLE_PIP := $(ANSIBLE_PYTHON) -m pip
MAKEFILE_DIR := $(realpath $(dir $(firstword $(MAKEFILE_LIST))))
VIRTUALENV_VENV ?= $(MAKEFILE_DIR)/.venv
VIRTUALENV_PYTHON := $(VIRTUALENV_VENV)/bin/python3
VIRTUALENV_PIP := $(VIRTUALENV_PYTHON) -m pip
VIRTUALENV_MOLECULE := $(VIRTUALENV_VENV)/bin/molecule

.PHONY: help
help: ## Show this help
@egrep -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

$(ANSIBLE_VIRTUALENV):
python3 -m venv $(ANSIBLE_VIRTUALENV)
$(ANSIBLE_PYTHON) -m pip install -U pip setuptools wheel
$(ANSIBLE_PIP) install -U \
$(VIRTUALENV_VENV):
python3 -m venv $(VIRTUALENV_VENV)
$(VIRTUALENV_PIP) install \
'ansible-lint==6.16.1' \
'pycodestyle==2.10.0'

.PHONY: virtualenv
virtualenv: $(ANSIBLE_VIRTUALENV) ## Create local environment
virtualenv: $(VIRTUALENV_VENV) ## Create local environment

.PHONY: lint
lint: virtualenv ## Lint
$(ANSIBLE_VIRTUALENV)/bin/ansible-lint -v molecule_qemu
$(ANSIBLE_VIRTUALENV)/bin/pycodestyle molecule_qemu
$(VIRTUALENV_VENV)/bin/ansible-lint -v molecule_qemu
$(VIRTUALENV_VENV)/bin/pycodestyle molecule_qemu

.PHONY: test
test: virtualenv ## Test
$(VIRTUALENV_PIP) install -e .
cd tests && $(VIRTUALENV_MOLECULE) test -s default

.PHONY: test-all
test-all: virtualenv ## Test
$(VIRTUALENV_PIP) install -e .
cd tests && \
$(VIRTUALENV_MOLECULE) destroy || true && \
$(VIRTUALENV_MOLECULE) reset && \
$(VIRTUALENV_MOLECULE) test -s default && \
$(VIRTUALENV_MOLECULE) test -s user && \
$(VIRTUALENV_MOLECULE) test -s vmnet-shared

.PHONY: clean
clean: ## Remove cache
rm -rf $(ANSIBLE_VIRTUALENV) build dist *.egg-info
rm -rf $(VIRTUALENV_VENV) build dist *.egg-info
32 changes: 13 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,42 +56,36 @@ dependency:
driver:
name: molecule-qemu
platforms:
- name: debian-bullseye-arm64
image: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2
image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS
image_arch: aarch64
ssh_port: 10000
- name: debian-bullseye-amd64
image: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2
image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS
image_arch: x86_64
ssh_port: 10001
- name: ubuntu-focal-arm64
image: https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-arm64.img
image_checksum: sha256:https://cloud-images.ubuntu.com/focal/current/SHA256SUMS
image_arch: aarch64
ssh_port: 10000
ssh_user: ubuntu
ssh_port: 10002
- name: ubuntu-focal-amd64
image: https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img
image_checksum: sha256:https://cloud-images.ubuntu.com/focal/current/SHA256SUMS
image_arch: x86_64
ssh_port: 10001
ssh_user: ubuntu
ssh_port: 10003
- name: ubuntu-jammy-arm64
image: https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-arm64.img
image_checksum: sha256:https://cloud-images.ubuntu.com/jammy/current/SHA256SUMS
image_arch: aarch64
ssh_port: 10002
ssh_user: ubuntu
ssh_port: 10004
- name: ubuntu-jammy-amd64
image: https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img
image_checksum: sha256:https://cloud-images.ubuntu.com/jammy/current/SHA256SUMS
image_arch: x86_64
ssh_port: 10003
ssh_user: ubuntu
- name: debian-bullseye-arm64
image: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2
image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS
image_arch: aarch64
ssh_port: 10004
ssh_user: debian
- name: debian-bullseye-amd64
image: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2
image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS
image_arch: x86_64
ssh_port: 10005
ssh_user: debian
provisioner:
name: ansible
verifier:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
- name: Prepare
hosts: all
become: true
gather_facts: false

{% raw -%}
environment:
http_proxy: "{{ lookup('ansible.builtin.env', 'http_proxy') | default(omit) }}"
https_proxy: "{{ lookup('ansible.builtin.env', 'https_proxy') | default(omit) }}"
{%- endraw %}

tasks: []
tasks:
- name: Wait for SSH to become available
ansible.builtin.wait_for_connection:
delay: 5
timeout: 300
33 changes: 33 additions & 0 deletions tests/.yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
# Based on ansible-lint config
extends: default

rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
colons:
max-spaces-after: -1
level: error
commas:
max-spaces-after: -1
level: error
comments: disable
comments-indentation: disable
document-start: disable
empty-lines:
max: 3
level: error
hyphens:
level: error
indentation: disable
key-duplicates: enable
line-length: disable
new-line-at-end-of-file: disable
new-lines:
type: unix
trailing-spaces: disable
truthy: disable
9 changes: 9 additions & 0 deletions tests/molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: Converge
hosts: all

environment:
http_proxy: "{{ lookup('ansible.builtin.env', 'http_proxy') | default(omit) }}"
https_proxy: "{{ lookup('ansible.builtin.env', 'https_proxy') | default(omit) }}"

tasks: []
15 changes: 15 additions & 0 deletions tests/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
dependency:
name: galaxy
driver:
name: molecule-qemu
platforms:
- name: debian-bullseye-arm64
image: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2
image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS
image_arch: aarch64
ssh_port: 10000
provisioner:
name: ansible
verifier:
name: ansible
15 changes: 15 additions & 0 deletions tests/molecule/default/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- name: Prepare
hosts: all
become: true
gather_facts: false

environment:
http_proxy: "{{ lookup('ansible.builtin.env', 'http_proxy') | default(omit) }}"
https_proxy: "{{ lookup('ansible.builtin.env', 'https_proxy') | default(omit) }}"

tasks:
- name: Wait for SSH to become available
ansible.builtin.wait_for_connection:
delay: 5
timeout: 300
10 changes: 10 additions & 0 deletions tests/molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
# This is an example playbook to execute Ansible tests.

- name: Verify
hosts: all
gather_facts: false
tasks: []
# - name: Example assertion
# ansible.builtin.assert:
# that: true
12 changes: 12 additions & 0 deletions tests/molecule/user/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: Converge
hosts: all

environment:
http_proxy: "{{ lookup('ansible.builtin.env', 'http_proxy') | default(omit) }}"
https_proxy: "{{ lookup('ansible.builtin.env', 'https_proxy') | default(omit) }}"

tasks:
- name: "Include tests"
ansible.builtin.include_role:
name: "tests"
20 changes: 20 additions & 0 deletions tests/molecule/user/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
dependency:
name: galaxy
driver:
name: molecule-qemu
platforms:
- name: debian-bullseye-arm64
image: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2
image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS
image_arch: aarch64
ssh_port: 10000
- name: debian-bullseye-amd64
image: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2
image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS
image_arch: x86_64
ssh_port: 10001
provisioner:
name: ansible
verifier:
name: ansible
15 changes: 15 additions & 0 deletions tests/molecule/user/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- name: Prepare
hosts: all
become: true
gather_facts: false

environment:
http_proxy: "{{ lookup('ansible.builtin.env', 'http_proxy') | default(omit) }}"
https_proxy: "{{ lookup('ansible.builtin.env', 'https_proxy') | default(omit) }}"

tasks:
- name: Wait for SSH to become available
ansible.builtin.wait_for_connection:
delay: 5
timeout: 300
10 changes: 10 additions & 0 deletions tests/molecule/user/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
# This is an example playbook to execute Ansible tests.

- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Example assertion
ansible.builtin.assert:
that: true
12 changes: 12 additions & 0 deletions tests/molecule/vmnet-shared/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
- name: Converge
hosts: all

environment:
http_proxy: "{{ lookup('ansible.builtin.env', 'http_proxy') | default(omit) }}"
https_proxy: "{{ lookup('ansible.builtin.env', 'https_proxy') | default(omit) }}"

tasks:
- name: "Include tests"
ansible.builtin.include_role:
name: "tests"
20 changes: 20 additions & 0 deletions tests/molecule/vmnet-shared/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
dependency:
name: galaxy
driver:
name: molecule-qemu
platforms:
- name: debian-bullseye-arm64
image: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-arm64.qcow2
image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS
image_arch: aarch64
vm_network: vmnet-shared
- name: debian-bullseye-amd64
image: https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2
image_checksum: sha512:https://cloud.debian.org/images/cloud/bullseye/latest/SHA512SUMS
image_arch: x86_64
vm_network: vmnet-shared
provisioner:
name: ansible
verifier:
name: ansible
15 changes: 15 additions & 0 deletions tests/molecule/vmnet-shared/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- name: Prepare
hosts: all
become: true
gather_facts: false

environment:
http_proxy: "{{ lookup('ansible.builtin.env', 'http_proxy') | default(omit) }}"
https_proxy: "{{ lookup('ansible.builtin.env', 'https_proxy') | default(omit) }}"

tasks:
- name: Wait for SSH to become available
ansible.builtin.wait_for_connection:
delay: 5
timeout: 300
10 changes: 10 additions & 0 deletions tests/molecule/vmnet-shared/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
# This is an example playbook to execute Ansible tests.

- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Example assertion
ansible.builtin.assert:
that: true