Skip to content

Commit

Permalink
Merge pull request #85 from pieterlexis/os-repos-tests
Browse files Browse the repository at this point in the history
Fix #84 and add tests for os-repos
  • Loading branch information
pieterlexis authored Sep 29, 2020
2 parents 1624a45 + a4e4cd6 commit 2304d86
Show file tree
Hide file tree
Showing 20 changed files with 172 additions and 33 deletions.
23 changes: 13 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ before_install:
# Ansible versions
env:
jobs:
- ANSIBLE=2.7 AUTH_VERSION=42
- ANSIBLE=2.7 AUTH_VERSION=43
- ANSIBLE=2.7 AUTH_VERSION=master
- ANSIBLE=2.7 TEST_SCENARIO=pdns-42
- ANSIBLE=2.7 TEST_SCENARIO=pdns-43
- ANSIBLE=2.7 TEST_SCENARIO=pdns-master

- ANSIBLE=2.8 AUTH_VERSION=42
- ANSIBLE=2.8 AUTH_VERSION=43
- ANSIBLE=2.8 AUTH_VERSION=master
- ANSIBLE=2.8 TEST_SCENARIO=pdns-42
- ANSIBLE=2.8 TEST_SCENARIO=pdns-43
- ANSIBLE=2.8 TEST_SCENARIO=pdns-master

- ANSIBLE=2.9 AUTH_VERSION=42
- ANSIBLE=2.9 AUTH_VERSION=43
- ANSIBLE=2.9 AUTH_VERSION=master
- ANSIBLE=2.9 TEST_SCENARIO=pdns-42
- ANSIBLE=2.9 TEST_SCENARIO=pdns-43
- ANSIBLE=2.9 TEST_SCENARIO=pdns-master

- ANSIBLE=2.9 TEST_SCENARIO=pdns-os-repos
- ANSIBLE=2.9 TEST_SCENARIO=systemd-no-overrides

jobs:
allow_failures:
Expand All @@ -42,7 +45,7 @@ install:

# Test the current PowerDNS Authoritative Server stable release
script:
- tox -- molecule test -s pdns-${AUTH_VERSION}
- tox -- molecule test -s ${TEST_SCENARIO}

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
1 change: 1 addition & 0 deletions molecule/pdns-42/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,5 @@ verifier:
- ../repo-42/
- ../backend-sqlite/
- ../backend-mysql/
- ../systemd-override/
lint: flake8
1 change: 1 addition & 0 deletions molecule/pdns-43/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,5 @@ verifier:
- ../repo-43/
- ../backend-sqlite/
- ../backend-mysql/
- ../systemd-override/
lint: flake8
1 change: 1 addition & 0 deletions molecule/pdns-master/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,5 @@ verifier:
- ../repo-master/
- ../backend-sqlite/
- ../backend-mysql/
- ../systemd-override/
lint: flake8
6 changes: 6 additions & 0 deletions molecule/pdns-os-repos/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ platforms:
image: archlinux/base
dockerfile_tpl: archlinux-systemd

- name: ubuntu-2004
groups: ["pdns"]
image: ubuntu:20.04
dockerfile_tpl: debian-systemd

# In order to run the tests we need
# a MySQL container to be up & running
- name: mysql
Expand Down Expand Up @@ -63,6 +68,7 @@ verifier:
directory: ../resources/tests/all
additional_files_or_dirs:
# path relative to 'directory'
- ../systemd-override/
- ../backend-sqlite/
- ../backend-mysql/
lint: flake8
2 changes: 1 addition & 1 deletion molecule/resources/Dockerfile.debian-systemd.j2
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ VOLUME [ "/sys/fs/cgroup" ]

CMD ["/sbin/init"]

RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get upgrade -y && apt-get install -y python sudo bash net-tools ca-certificates && apt-get clean; fi
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get upgrade -y && apt-get install -y python python3 sudo bash net-tools ca-certificates && apt-get clean; fi
4 changes: 4 additions & 0 deletions molecule/resources/host_vars/debian-10.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---

ansible_python_interpreter: "/usr/bin/python3"

3 changes: 3 additions & 0 deletions molecule/resources/host_vars/ubuntu-2004.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---

ansible_python_interpreter: "/usr/bin/python3"
12 changes: 0 additions & 12 deletions molecule/resources/tests/all/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,3 @@ def test_service(host):
s = host.ansible('service', 'name=pdns state=started enabled=yes')

assert s["changed"] is False


def systemd_override(host):
smgr = host.ansible("setup")["ansible_facts"]["ansible_service_mgr"]
if smgr == 'systemd':
fname = '/etc/systemd/system/pdns.service.d/override.conf'
f = host.file(fname)

assert f.exists
assert f.user == 'root'
assert f.group == 'root'
assert f.contains('LimitCORE=infinity')
7 changes: 7 additions & 0 deletions molecule/resources/tests/systemd-no-override/test_override.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
def test_systemd_override(host):
smgr = host.ansible("setup")["ansible_facts"]["ansible_service_mgr"]
if smgr == 'systemd':
fname = '/etc/systemd/system/pdns.service.d/override.conf'
f = host.file(fname)

assert not f.exists
10 changes: 10 additions & 0 deletions molecule/resources/tests/systemd-override/test_override.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def test_systemd_override(host):
smgr = host.ansible("setup")["ansible_facts"]["ansible_service_mgr"]
if smgr == 'systemd':
fname = '/etc/systemd/system/pdns.service.d/override.conf'
f = host.file(fname)

assert f.exists
assert f.user == 'root'
assert f.group == 'root'
assert f.contains('LimitCORE=infinity')
23 changes: 23 additions & 0 deletions molecule/resources/vars/pdns-no-overrides.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---

##
# PowerDNS Configuration
##

pdns_config:

# Turns on master operations
master: true

# Listen Address
local-address: "127.0.0.1"
local-port: "53"

# API Configuration
api: yes
api-key: "powerdns"

# Embedded webserver
webserver: yes
webserver-address: "0.0.0.0"
webserver-port: "8001"
7 changes: 7 additions & 0 deletions molecule/systemd-no-overrides/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---

- hosts: pdns
vars_files:
- ../resources/vars/pdns-no-overrides.yml
roles:
- { role: pdns-ansible }
56 changes: 56 additions & 0 deletions molecule/systemd-no-overrides/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---

scenario:
name: systemd-no-overrides

driver:
name: docker

dependency:
name: galaxy

platforms:
- name: debian-10
groups: ["pdns"]
image: debian:10
dockerfile_tpl: debian-systemd

- name: ubuntu-2004
groups: ["pdns"]
image: ubuntu:20.04
dockerfile_tpl: debian-systemd

provisioner:
name: ansible
options:
diff: True
v: True
config_options:
defaults:
gathering: smart
fact_caching: jsonfile
fact_caching_connection: .ansible_cache
fact_caching_timeout: 7200
ssh_connection:
pipelining: true
inventory:
links:
host_vars: ../resources/host_vars/
playbooks:
create: ../resources/create.yml
destroy: ../resources/destroy.yml
prepare: ../resources/prepare.yml
lint: ansible-lint -x ANSIBLE0006 ANSIBLE0016 306

lint: yamllint defaults tasks meta vars

verifier:
name: testinfra
options:
hosts: "pdns"
vvv: True
directory: ../resources/tests/all
additional_files_or_dirs:
# path relative to 'directory'
- ../no-systemd-overrides
lint: flake8
1 change: 1 addition & 0 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
owner: root
group: root
register: _pdns_override_unit
when: pdns_service_overrides | length > 0

- name: Reload systemd
command: systemctl daemon-reload
Expand Down
8 changes: 0 additions & 8 deletions tasks/database-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
name: "{{ pdns_mysql_packages }}"
state: present

- name: Install the MySQL dependencies on Archlinux
package:
name:
- python-pymysql
- mariadb-clients
state: present
when: ansible_os_family == 'Archlinux'

- name: Create the PowerDNS MySQL databases
mysql_db:
login_user: "{{ item['value']['priv_user'] }}"
Expand Down
3 changes: 2 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
- name: Include OS-specific variables
include_vars: "{{ item }}"
with_first_found:
- "{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml"
- "{{ ansible_distribution }}-{{ ansible_distribution_major_version }}.yml"
- "{{ ansible_distribution }}.yml"
- "{{ ansible_os_family }}-{{ ansible_distribution_major_version }}.yml"
- "{{ ansible_os_family }}.yml"
tags:
- always
Expand Down
5 changes: 5 additions & 0 deletions vars/Archlinux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ default_pdns_backends_packages: {}
# The directory where the PowerDNS configuration is located
default_pdns_config_dir: '/etc/powerdns'

# Packages to install for MySQL support
pdns_mysql_packages:
- python-pymysql
- mariadb-clients

# Other defaults
pdns_user: powerdns
pdns_group: powerdns
30 changes: 30 additions & 0 deletions vars/Ubuntu-20.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---

# The name of the PowerDNS Authoritative Server package
default_pdns_package_name: "pdns-server"

# The name of the PowerDNS Authoritative Server debug package
default_pdns_debug_symbols_package_name: "pdns-server-dbg"

# Packages needed to install MySQL
pdns_mysql_packages:
- default-mysql-client
- python3-pymysql

# List of PowerDNS Authoritative Server Backends packages on Debian
default_pdns_backends_packages:
geo: pdns-backend-geo
geoip: pdns-backend-geoip
gmysql: pdns-backend-mysql
gpgsql: pdns-backend-pgsql
gsqlite3: pdns-backend-sqlite3
ldap: pdns-backend-ldap
lmdb: pdns-backend-lmdb
lua: pdns-backend-lua
mydns: pdns-backend-mydns
pipe: pdns-backend-pipe
remote: pdns-backend-remote
tinydns: pdns-backend-tinydns

# The directory where the PowerDNS Authoritative Server configuration is located
default_pdns_config_dir: "/etc/powerdns"
2 changes: 1 addition & 1 deletion vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ pdns_auth_powerdns_repo_43:
default_pdns_service_overrides: >-
{{ { 'User' : pdns_user
, 'Group' : pdns_group
} if _pdns_package_version is version('4.3', operator='ge')
} if _pdns_running_version is version('4.3', operator='ge')
else {}
}}

0 comments on commit 2304d86

Please sign in to comment.