From b758f66964763dd2bbcf42ad03292bd1e044ac5b Mon Sep 17 00:00:00 2001 From: "felix.niederwanger@suse.com" Date: Thu, 25 Mar 2021 14:25:37 +0100 Subject: [PATCH] Add GitHub Actions, including grafana and influxdb tests --- .github/workflows/CI.yml | 42 ++++++++++++++++++++++++++ molecule/default/converge.yml | 7 +++++ molecule/default/molecule.yml | 31 +++++++++++++++++++ molecule/default/tests/test_default.py | 34 +++++++++++++++++++++ tasks/grafana.yml | 2 +- 5 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/CI.yml create mode 100644 molecule/default/converge.yml create mode 100644 molecule/default/molecule.yml create mode 100755 molecule/default/tests/test_default.py diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..96238fc --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,42 @@ +--- +name: Test deployment +'on': + pull_request: + push: + schedule: + # Run every Wednesday at 01:42 + - cron: "42 1 * * 3" + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Check out codebase + uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + - name: Install dependencies + run: pip3 install yamllint + - name: Lint repository + run: yamllint . + + molecule: + name: Molecule + runs-on: ubuntu-latest + steps: + - name: Check out the codebase + uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + - name: Install dependencies + run: pip3 install ansible molecule[docker] docker pytest testinfra influxdb + - name: Run Molecule + run: molecule test + env: + PY_COLORS: '1' + ANSIBLE_FORCE_COLOR: '1' diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml new file mode 100644 index 0000000..8e3d0b9 --- /dev/null +++ b/molecule/default/converge.yml @@ -0,0 +1,7 @@ +--- +- name: Converge + hosts: all + tasks: + - name: "Include geekoops-grafana" + include_role: + name: "geekoops-grafana" diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml new file mode 100644 index 0000000..3471be8 --- /dev/null +++ b/molecule/default/molecule.yml @@ -0,0 +1,31 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: leap15_2 + image: grisu48/leap-ansible + pre_build_image: true + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + capabilities: + - SYS_ADMIN + privileged: true + tmpfs: + - /run + - /tmp +provisioner: + name: ansible + inventory: + host_vars: + leap15_2: + ansible_python_interpreter: /usr/bin/python3 + influxdb: true +verifier: + name: testinfra + lint: + name: flake8 +lint: | + set -e + yamllint . diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py new file mode 100755 index 0000000..74b507b --- /dev/null +++ b/molecule/default/tests/test_default.py @@ -0,0 +1,34 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + + +import testinfra.utils.ansible_runner +import os + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + +def test_grafana_http(host): + cmd = host.run("curl -v http://127.0.0.1:3000") + assert cmd.succeeded + assert "/login" in cmd.stdout + assert "Found" in cmd.stdout + +def test_influxdb(host) : + def run(command) : + cmd = host.run(command) + assert cmd.succeeded + run("influx -version") + run("influx -execute 'CREATE DATABASE apollo13'") + run("influx -database apollo13 -execute 'INSERT thermo,location=space temperature=22 5'") + run("influx -database apollo13 -execute 'INSERT thermo,location=space temperature=23 6'") + cmd = host.run("influx -database apollo13 -execute 'SELECT * FROM thermo;'") + assert cmd.succeeded + lines = cmd.stdout.split("\n") + print(lines) + def assert_line(loc, time, temperature) : + loc, time, temperature = str(loc), str(time), str(temperature) + for line in lines : + if loc in line and time in line and temperature in line : return + assert False + assert_line('space', 5, 22) + assert_line('space', 6, 23) diff --git a/tasks/grafana.yml b/tasks/grafana.yml index 1de188c..405846b 100644 --- a/tasks/grafana.yml +++ b/tasks/grafana.yml @@ -6,7 +6,7 @@ state: present tags: ['grafana'] -- name: Ensure grafana is started +- name: Ensure grafana is started and enabled systemd: name: grafana-server state: started