Skip to content

Commit

Permalink
testinfra (#44): mananged components now create simple file at /opt/a…
Browse files Browse the repository at this point in the history
…lb/info/ to allow tests know what to check
  • Loading branch information
fititnt committed Dec 27, 2019
1 parent a5f60ce commit 496b264
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 52 deletions.
59 changes: 59 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,62 @@

- name: restart ufw
service: name=ufw state=restarted

## About /opt/alb/info/ files
# This folder may contain some very basic information about enabled components
# on each ALB node. The existence means a service was installed and (eventually)
# it's contents (INI format) could be used to describe more about the service.
#
# One main initial reason is allow testinfra (and later other scripts) know
# what state the node was expected to be. At this moment it just create empty
# file.

- name: "info alb component openresty"
file:
path: "/opt/alb/info/openresty"
state: touch
modification_time: preserve
access_time: preserve
owner: "{{ alb_internal_root_user }}"
group: "{{ alb_internal_root_group }}"
mode: "0640"

- name: "info alb component haproxy"
file:
path: "/opt/alb/info/haproxy"
state: touch
modification_time: preserve
access_time: preserve
owner: "{{ alb_internal_root_user }}"
group: "{{ alb_internal_root_group }}"
mode: "0640"

- name: "info alb component ufw"
file:
path: "/opt/alb/info/ufw"
state: touch
modification_time: preserve
access_time: preserve
owner: "{{ alb_internal_root_user }}"
group: "{{ alb_internal_root_group }}"
mode: "0640"

- name: "info alb component apps"
file:
path: "/opt/alb/info/apps"
state: touch
modification_time: preserve
access_time: preserve
owner: "{{ alb_internal_root_user }}"
group: "{{ alb_internal_root_group }}"
mode: "0640"

- name: "info alb component sysapps"
file:
path: "/opt/alb/info/sysapps"
state: touch
modification_time: preserve
access_time: preserve
owner: "{{ alb_internal_root_user }}"
group: "{{ alb_internal_root_group }}"
mode: "0640"
55 changes: 28 additions & 27 deletions molecule/default/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,46 @@
).get_hosts('all')


def test_hosts_file(host):
f = host.file('/etc/hosts')
def test_required_haproxy_is_installed(host):
assert (not host.file("/opt/alb/info/haproxy").exists) \
or host.package("haproxy").is_installed

assert f.exists
assert f.user == 'root'
assert f.group == 'root' or f.group == 'wheel'

def test_required_haproxy_is_enabled(host):
assert (not host.file("/opt/alb/info/haproxy").exists) \
or host.service("haproxy").is_enabled

def test_haproxy_is_installed(host):
assert host.package("haproxy").is_installed

def test_required_haproxy_is_running(host):
assert (not host.file("/opt/alb/info/haproxy").exists) \
or host.service("haproxy").is_running

def test_haproxy_is_enabled(host):
assert host.service("haproxy").is_enabled

def test_required_openresty_is_installed(host):
assert (not host.file("/opt/alb/info/openresty").exists) \
or host.package("openresty").is_installed

def test_haproxy_is_running(host):
assert host.service("haproxy").is_running

def test_required_openresty_is_enabled(host):
assert (not host.file("/opt/alb/info/openresty").exists) \
or host.service("openresty").is_enabled

def test_openresty_is_installed(host):
assert host.package("openresty").is_installed

def test_required_openresty_is_running(host):
assert (not host.file("/opt/alb/info/openresty").exists) \
or host.service("openresty").is_running

def test_openresty_is_enabled(host):
assert host.service("openresty").is_enabled

def test_required_ufw_is_installed(host):
assert (not host.file("/opt/alb/info/ufw").exists) \
or host.package("ufw").is_installed

def test_openresty_is_running(host):
assert host.service("openresty").is_running

def test_required_ufw_is_enabled(host):
assert (not host.file("/opt/alb/info/ufw").exists) \
or host.service("ufw").is_enabled

#def test_ufw_is_installed(host):
# assert host.package("ufw").is_installed
#
#
#def test_ufw_is_enabled(host):
# assert host.service("ufw").is_enabled
#
#
#def test_ufw_is_running(host):
# assert host.service("ufw").is_running

def test_required_ufw_is_running(host):
assert (not host.file("/opt/alb/info/ufw").exists) \
or host.service("ufw").is_running
5 changes: 4 additions & 1 deletion tasks/apps/alb/openresty-conf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@
- "(alb_run_only_app_uid is not defined) or (alb_run_only_app_uid == item.app_uid)"
- "(alb_apps_facts_deployed is changed) or (alb_forceredeploy|bool)"
register: result_apps_rules
notify: reload openresty
notify:
- "reload openresty"
- "info alb component apps"

5 changes: 3 additions & 2 deletions tasks/haproxy/management/bsd-init.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
mode: '0644'
backup: yes
notify:
- reload haproxy
- "reload haproxy"
- "info alb component haproxy"

# Enabled/Started must be AFTER moving new /etc/haproxy/haproxy.cfg
# configurations or Ansible will not be able to update one new valid
# configuration if old one was already with error. By moving this step
# after we avoid user being forced to solve manually on the server
# after we avoid user being forced to solve manually on the server
- name: "haproxy | management | bsd-init.yml: enable haproxy.service"
service:
name: haproxy
Expand Down
1 change: 1 addition & 0 deletions tasks/haproxy/management/systemd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
backup: yes
notify:
- reload haproxy
- info alb component haproxy

# Enabled/Started must be AFTER moving new /etc/haproxy/haproxy.cfg
# configurations or Ansible will not be able to update one new valid
Expand Down
3 changes: 2 additions & 1 deletion tasks/openresty/install/default-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
mode: '0644'
backup: yes
notify:
- reload openresty
- "reload openresty"
- "info alb component openresty"
3 changes: 2 additions & 1 deletion tasks/openresty/management/nginx-conf-global.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
mode: '0644'
backup: yes
notify:
- reload openresty
- "reload openresty"
- "info alb component openresty"
4 changes: 3 additions & 1 deletion tasks/sysapps/sysapps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@
when:
- alb_internal_sysapps is defined and alb_internal_sysapps[0] is defined
- "(alb_sysapps_facts_deployed is changed) or (alb_forceredeploy|bool)"
notify: reload openresty
notify:
- "reload openresty"
- "info alb component sysapps"

- name: "sysapps | mkdir /var/log/sysapp/[app_uid]"
file:
Expand Down
2 changes: 2 additions & 0 deletions tasks/ufw/install-ufw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
state: present
when:
- "alb_manange_ufw_install is defined and alb_manange_ufw_install|bool"
notify:
- "info alb component ufw"
4 changes: 3 additions & 1 deletion tasks/ufw/rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,7 @@
loop: "{{ ufw_rules }}"
loop_control:
extended: yes
notify: reload ufw
notify:
- "reload ufw"
- "info alb component ufw"
when: "ufw_rules is defined"
45 changes: 27 additions & 18 deletions tests/test_alb-standard-node.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,45 @@
# FILE: /opt/alb/bin/tests/test_alb-standard-node.py

def test_haproxy_is_installed(host):
assert host.package("haproxy").is_installed
def test_required_haproxy_is_installed(host):
assert (not host.file("/opt/alb/info/haproxy").exists) \
or host.package("haproxy").is_installed


def test_haproxy_is_enabled(host):
assert host.service("haproxy").is_enabled
def test_required_haproxy_is_enabled(host):
assert (not host.file("/opt/alb/info/haproxy").exists) \
or host.service("haproxy").is_enabled


def test_haproxy_is_running(host):
assert host.service("haproxy").is_running
def test_required_haproxy_is_running(host):
assert (not host.file("/opt/alb/info/haproxy").exists) \
or host.service("haproxy").is_running


def test_openresty_is_installed(host):
assert host.package("openresty").is_installed
def test_required_openresty_is_installed(host):
assert (not host.file("/opt/alb/info/openresty").exists) \
or host.package("openresty").is_installed


def test_openresty_is_enabled(host):
assert host.service("openresty").is_enabled
def test_required_openresty_is_enabled(host):
assert (not host.file("/opt/alb/info/openresty").exists) \
or host.service("openresty").is_enabled


def test_openresty_is_running(host):
assert host.service("openresty").is_running
def test_required_openresty_is_running(host):
assert (not host.file("/opt/alb/info/openresty").exists) \
or host.service("openresty").is_running


def test_ufw_is_installed(host):
assert host.package("ufw").is_installed
def test_required_ufw_is_installed(host):
assert (not host.file("/opt/alb/info/ufw").exists) \
or host.package("ufw").is_installed


def test_ufw_is_enabled(host):
assert host.service("ufw").is_enabled
def test_required_ufw_is_enabled(host):
assert (not host.file("/opt/alb/info/ufw").exists) \
or host.service("ufw").is_enabled


def test_ufw_is_running(host):
assert host.service("ufw").is_running
def test_required_ufw_is_running(host):
assert (not host.file("/opt/alb/info/ufw").exists) \
or host.service("ufw").is_running

0 comments on commit 496b264

Please sign in to comment.