-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from shantanoo-desai/develop
tests: add Integrity Tests for Generated Files / Directories
- Loading branch information
Showing
12 changed files
with
223 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ on: | |
- pull_request | ||
|
||
jobs: | ||
build: | ||
lint: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
name: Integrity Tests with Ansible | ||
|
||
on: | ||
push: | ||
branches: | ||
- "main" | ||
pull_request: | ||
branches: | ||
- "main" | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: true | ||
matrix: | ||
python-version: | ||
- "3.10" | ||
- "3.9" | ||
- "3.8" | ||
|
||
steps: | ||
- name: Checkout Codebase | ||
uses: actions/checkout@v3 | ||
|
||
- name: Pull eclipse-mosquitto image | ||
run: docker pull eclipse-mosquitto:2.0.15 | ||
|
||
- name: Set up python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install ansible | ||
run: python -m pip install ansible docker passlib | ||
|
||
- name: Generate the Default Komponist Stack | ||
run: ansible-playbook -vv generate_stack.yml | ||
|
||
- name: Test Integrity of Generated Directories | ||
run: ansible-playbook tests/test_generated_directories.yml | ||
|
||
- name: Test Integrity of Generated Files | ||
run: ansible-playbook tests/test_generated_files.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
[defaults] | ||
ansible_managed = This file is generated by Komponist.%n | ||
Generated On: %Y-%m-%d %H:%M:%S %n | ||
Generated On: %Y-%m-%d %H:%M:%S %n | ||
stdout_callback = yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
- name: Get stats for Grafana Files in dedicated directory under deploy_dir | ||
ansible.builtin.stat: | ||
path: "{{ playbook_dir }}/../{{ komponist.deploy_dir }}/grafana/provisioning/datasources/datasources.yml" | ||
register: test_grafana_datasources_stat | ||
|
||
- name: Test if the Grafana Datasources File in dedicated directory exists under deploy_dir | ||
ansible.builtin.assert: | ||
that: test_grafana_datasources_stat.stat.exists and test_grafana_datasources_stat.stat.mode == '0755' | ||
fail_msg: "FAIL: Datasources File DOES NOT exist in {{ komponist.deploy_dir }}/grafana/provisioning/datasources directory." | ||
success_msg: "PASS: Datasources File exists in {{ komponist.deploy_dir }}/grafana/provisioning/datasources directory." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
- name: Get stats for InfluxDBv1/v2 environment file in dedicated directory under deploy_dir | ||
ansible.builtin.stat: | ||
path: "{{ playbook_dir }}/../{{ komponist.deploy_dir }}/{{ item }}/{{ item }}.env" | ||
register: test_service_envfile_stat | ||
|
||
- name: Test if the InfluxDBv1/v2 environment file in dedicated directory exists under deploy_dir | ||
ansible.builtin.assert: | ||
that: test_service_envfile_stat.stat.exists and test_service_envfile_stat.stat.mode == '0755' | ||
fail_msg: "FAIL: {{ item }}.env DOES NOT exist in {{ komponist.deploy_dir }}/{{ item }} directory." | ||
success_msg: "PASS: {{ item }}.env File exists in {{ komponist.deploy_dir }}/{{ item }} directory." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
- name: Get stats for Mosquitto related configuration files | ||
ansible.builtin.stat: | ||
path: "{{ playbook_dir }}/../{{ komponist.deploy_dir }}/mosquitto/{{ item }}" | ||
register: test_mosquitto_files_stat | ||
loop: | ||
- acl | ||
- mosquitto.conf | ||
- users | ||
|
||
- name: Test if Mosquitto related configuration files exist in deploy_dir | ||
ansible.builtin.assert: | ||
that: item.stat.exists and item.stat.mode == '0755' | ||
fail_msg: "FAIL: {{ item.item }} DOES NOT exist in {{ komponist.deploy_dir }}/mosquitto directory" | ||
success_msg: "PASS: {{ item.item }} exists in {{ komponist.deploy_dir }}/mosquitto directory" | ||
loop: "{{ test_mosquitto_files_stat.results | map('ansible.utils.keep_keys', ['item', 'exists', 'mode']) }}" | ||
loop_control: | ||
label: "{{ item.item }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
- name: Get stats for Node-RED settings file | ||
ansible.builtin.stat: | ||
path: "{{ playbook_dir }}/../{{ komponist.deploy_dir }}/nodered/settings.js" | ||
register: test_nodered_settings_file_stat | ||
|
||
- name: Test if settings.js Exists under deploy_dir directory | ||
ansible.builtin.assert: | ||
that: test_nodered_settings_file_stat.stat.exists and test_nodered_settings_file_stat.stat.mode == '0755' | ||
fail_msg: "FAIL: settings.js DOES NOT exist under {{ komponist.deploy_dir }}/nodered directory" | ||
success_msg: "PASS: settings.js exists under {{ komponist.deploy_dir }}/nodered directory" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
- name: Get stats for Traefik related configuration files | ||
ansible.builtin.stat: | ||
path: "{{ playbook_dir }}/../{{ komponist.deploy_dir }}/traefik/{{ item }}" | ||
register: test_traefik_files_stat | ||
loop: | ||
- traefik.yml | ||
- configurations/dynamic.yml | ||
|
||
- name: Test if Traefik related configuration files in deploy_dir | ||
ansible.builtin.assert: | ||
that: item.stat.exists and item.stat.mode == '0755' | ||
fail_msg: "FAIL: {{ item.item }} DOES NOT exist under {{ komponist.deploy_dir }}/traefik directory" | ||
success_msg: "PASS: {{ item.item }} exists under {{ komponist.deploy_dir }}/traefik directory" | ||
loop: "{{ test_traefik_files_stat.results | map('ansible.utils.keep_keys', ['item', 'exists', 'mode']) }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
- name: Directory Structure Creation Tests | ||
vars_files: | ||
- "{{ playbook_dir }}/../vars/config.yml" | ||
hosts: localhost | ||
gather_facts: false | ||
|
||
pre_tasks: | ||
- name: Collect Stat Information for deploy_dir | ||
ansible.builtin.stat: | ||
path: "{{ playbook_dir }}/../{{ komponist.deploy_dir }}" | ||
register: test_deploy_dir_state | ||
|
||
- name: Collect Stat Information for Services under deploy_dir | ||
ansible.builtin.stat: | ||
path: "{{ playbook_dir }}/../{{ komponist.deploy_dir }}/{{ item }}" | ||
register: test_deploy_dir_service_state | ||
loop: "{{ komponist.configuration.keys() }}" | ||
|
||
tasks: | ||
- name: Test if deploy_dir directory is created | ||
ansible.builtin.assert: | ||
that: | ||
- test_deploy_dir_state.stat.exists and test_deploy_dir_state.stat.isdir | ||
fail_msg: "Cannot Find the {{ komponist.deploy_dir }} in the root of the repository." | ||
success_msg: "{{ komponist.deploy_dir }} exists in the root of the repository." | ||
|
||
- name: Test if the subdirectories for each Service exists under deploy_dir | ||
ansible.builtin.assert: | ||
that: item.stat.exists and item.stat.isdir and item.stat.mode == '0755' | ||
fail_msg: "FAIL: {{ item.item }} does not exist under {{ komponist.deploy_dir }} directory" | ||
success_msg: "PASS: {{ item.item }} exist under {{ komponist.deploy_dir }} directory" | ||
quiet: false | ||
loop: "{{ test_deploy_dir_service_state.results | map('ansible.utils.keep_keys', ['item', 'exists', 'isdir', 'mode']) }}" | ||
loop_control: | ||
label: "{{ item.item }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
- name: File Generation Tests | ||
vars_files: | ||
- "{{ playbook_dir }}/../vars/config.yml" | ||
hosts: localhost | ||
gather_facts: false | ||
tasks: | ||
- name: Check for .env File in deploy_dir | ||
block: | ||
- name: Get stats for .env in deploy_dir | ||
ansible.builtin.stat: | ||
path: "{{ playbook_dir }}/../{{ komponist.deploy_dir }}/.env" | ||
register: test_compose_env_file_stat | ||
|
||
- name: Check if .env file is generated | ||
ansible.builtin.assert: | ||
that: test_compose_env_file_stat.stat.exists and test_compose_env_file_stat.stat.mode == "0755" | ||
fail_msg: "FAIL: .env File DOES NOT exist in {{ komponist.deploy_dir }} directory." | ||
success_msg: "PASS: .env File exists in {{ komponist.deploy_dir }} directory." | ||
|
||
- name: Check for Generated Docker Compose Services Files | ||
block: | ||
- name: Get stats for configured Docker Compose services | ||
ansible.builtin.stat: | ||
path: "{{ playbook_dir }}/../{{ komponist.deploy_dir }}/docker-compose.{{ item }}.yml" | ||
loop: "{{ komponist.configuration.keys() }}" | ||
register: test_compose_services_files_stat | ||
|
||
- name: Check if respective Docker Compose Service Files exist | ||
ansible.builtin.assert: | ||
that: item.stat.exists and item.stat.mode | ||
fail_msg: "FAIL: docker-compose.{{ item.item }}.yml DOES NOT exist in {{ komponist.deploy_dir }} directory." | ||
success_msg: "PASS: docker-compose.{{ item.item }}.yml File exists in {{ komponist.deploy_dir }} directory." | ||
loop: "{{ test_compose_services_files_stat.results | map('ansible.utils.keep_keys', ['item', 'exists', 'mode']) }}" | ||
loop_control: | ||
label: "{{ item.item }}" | ||
|
||
- name: Check for Deployment-Ready docker-compose.yml File | ||
block: | ||
- name: Get stats for Deployment-Ready docker-compose.yml file | ||
ansible.builtin.stat: | ||
path: "{{ playbook_dir }}/../{{ komponist.deploy_dir }}/docker-compose.yml" | ||
register: test_compose_deployment_file_stat | ||
|
||
- name: Check if docker-compose.yml File exist | ||
ansible.builtin.assert: | ||
that: test_compose_deployment_file_stat.stat.exists and test_compose_deployment_file_stat.stat.mode == '0644' | ||
fail_msg: "FAIL: docker-compose.yml DOES NOT exist in {{ komponist.deploy_dir }} directory." | ||
success_msg: "PASS: docker-compose.yml File exists in {{ komponist.deploy_dir }} directory." | ||
|
||
- name: Check InfluxDB V1/V2 Generated Files in deploy_dir | ||
ansible.builtin.include_tasks: "{{ playbook_dir }}/services/test_config_influxdb.yml" | ||
with_items: "{{ komponist.configuration.keys() | select('match', 'influxdbv[1-2]') | list }}" | ||
|
||
- name: Check Mosquitto MQTT Generated Files in deploy_dir | ||
ansible.builtin.include_tasks: "{{ playbook_dir }}/services/test_config_mosquitto.yml" | ||
when: "'mosquitto' in komponist.configuration.keys()" | ||
|
||
- name: Check Grafana Generated Files in deploy_dir | ||
ansible.builtin.include_tasks: "{{ playbook_dir }}/services/test_config_grafana.yml" | ||
when: "'grafana' in komponist.configuration.keys() and ('influxdbv1' in komponist.configuration.keys() or 'influxdbv2' in komponist.configuration.keys())" | ||
|
||
- name: Check Node-RED Generated Files in deploy_dir | ||
ansible.builtin.include_tasks: "{{ playbook_dir }}/services/test_config_nodered.yml" | ||
when: "'nodered' in komponist.configuration.keys()" | ||
|
||
- name: Check Traefik Generated Files in deploy_dir | ||
ansible.builtin.include_tasks: "{{ playbook_dir }}/services/test_config_traefik.yml" | ||
when: "'traefik' in komponist.configuration.keys()" |