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

Update CI Testing #99

Merged
merged 18 commits into from
Sep 18, 2023
4 changes: 2 additions & 2 deletions .github/workflows/full-integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
- name: Install ansible-base (${{ matrix.ansible }})
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check

- name: Run integration test
run: ansible-test integration -v --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --docker --coverage
- name: Test Modules
run: ansible-test integration -v alert_contact_point alert_notification_policy cloud_api_key cloud_plugin cloud_stack dashboard datasource folder --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --coverage --docker

Check warning on line 65 in .github/workflows/full-integration-test.yml

View workflow job for this annotation

GitHub Actions / Perform Linting

65:151 [line-length] line too long (255 > 150 characters)
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}

- name: Cooling Period
Expand Down
89 changes: 89 additions & 0 deletions .github/workflows/modules-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
name: Modules Test

# yamllint disable-line rule:truthy
on:
push:
branches:
- "main"
pull_request:
schedule:
- cron: '0 6 * * *'
env:
NAMESPACE: grafana
COLLECTION_NAME: grafana

jobs:

sanity:
name: Sanity (Ⓐ${{ matrix.ansible }})
strategy:
matrix:
ansible:
- stable-2.12
- stable-2.13
- stable-2.14
- devel
runs-on: ubuntu-20.04
steps:

- name: Check out code
uses: actions/checkout@v3
with:
path: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.10'

- name: Install ansible-base (${{ matrix.ansible }})
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check

- name: Run sanity tests
run: ansible-test sanity -v --docker --color --coverage
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}

integration:
runs-on: ubuntu-20.04
name: Integration (Ⓐ${{ matrix.ansible }}-py${{ matrix.python }})
strategy:
fail-fast: true
max-parallel: 1
matrix:
ansible:
- stable-2.13
python:
- '3.10'

steps:
- name: Check out code
uses: actions/checkout@v2
with:
path: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}

- name: create integration_config
working-directory: ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}/tests/integration
run: |
cat <<EOF > integration_config.yml
org_name: ${{ secrets.ANSIBLE_TEST_ORG_NAME }}
grafana_cloud_api_key: ${{ secrets.ANSIBLE_TEST_CLOUD_API_KEY }}
grafana_api_key: ${{ secrets.ANSIBLE_TEST_GRAFANA_API_KEY }}
grafana_url: ${{ secrets.ANSIBLE_GRAFANA_URL }}
test_stack_name: ${{ secrets.ANSIBLE_TEST_CI_STACK }}
EOF

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}

- name: Install ansible-base (${{ matrix.ansible }})
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check

- name: Install Requests
run: pip install requests

- name: Test Modules
run: ansible-test integration -v alert_contact_point alert_notification_policy cloud_api_key cloud_plugin cloud_stack dashboard datasource folder --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --coverage --docker

Check warning on line 88 in .github/workflows/modules-test.yml

View workflow job for this annotation

GitHub Actions / Perform Linting

88:151 [line-length] line too long (255 > 150 characters)
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
- name: Install ansible-base (${{ matrix.ansible }})
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check

- name: Run integration test
run: ansible-test integration -v --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --docker --coverage
- name: Test Modules
run: ansible-test integration -v alert_contact_point alert_notification_policy cloud_api_key cloud_plugin cloud_stack dashboard datasource folder --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --coverage --docker

Check warning on line 83 in .github/workflows/release.yml

View workflow job for this annotation

GitHub Actions / Perform Linting

83:151 [line-length] line too long (255 > 150 characters)
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}

release:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: CI Tests
name: Roles Test

# yamllint disable-line rule:truthy
on:
Expand Down Expand Up @@ -85,6 +85,6 @@
- name: Install Requests
run: pip install requests

- name: Run integration test
run: ansible-test integration -v --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --coverage --docker
- name: Test Roles
run: ansible-test integration -v molecule-grafana-alternative molecule-grafana-default --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --coverage --docker

Check warning on line 89 in .github/workflows/roles-test.yml

View workflow job for this annotation

GitHub Actions / Perform Linting

89:151 [line-length] line too long (196 > 150 characters)
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
[![GitHub Contributors](https://img.shields.io/github/contributors/grafana/grafana-ansible-collection)](https://github.com/grafana/grafana-ansible-collection/tags)

[![Lint](https://github.com/grafana/grafana-ansible-collection/actions/workflows/lint.yaml/badge.svg)](https://github.com/grafana/grafana-ansible-collection/actions/workflows/lint.yaml)
[![CI Tests](https://github.com/grafana/grafana-ansible-collection/actions/workflows/ci-test.yml/badge.svg?branch=main)](https://github.com/grafana/grafana-ansible-collection/actions/workflows/ci-test.yml)
[![Modules Test](https://github.com/grafana/grafana-ansible-collection/actions/workflows/modules-test.yml/badge.svg?branch=main)](https://github.com/grafana/grafana-ansible-collection/actions/workflows/modules-test.yml)
[![Roles Test](https://github.com/grafana/grafana-ansible-collection/actions/workflows/roles-test.yml/badge.svg?branch=main)](https://github.com/grafana/grafana-ansible-collection/actions/workflows/roles-test.yml)
[![Full Integration Test](https://github.com/grafana/grafana-ansible-collection/actions/workflows/full-integration-test.yml/badge.svg?branch=main)](https://github.com/grafana/grafana-ansible-collection/actions/workflows/full-integration-test.yml)

This collection (`grafana.grafana`) contains modules and plugins to assist in automating managing of resources in **Grafana** with Ansible.
Expand Down
6 changes: 3 additions & 3 deletions roles/grafana_agent/tasks/configure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
owner: root
group: root
mode: 0644
notify: "restart grafana-agent"
notify: "restart grafana-agent"

- name: Create the Service Environment file
ansible.builtin.template:
Expand All @@ -37,7 +37,7 @@
owner: root
group: "{{ grafana_agent_user_group }}"
mode: 0640
notify: "restart grafana-agent"
notify: "restart grafana-agent"
when: grafana_agent_provisioned_config_file | length == 0

- name: Copy Grafana Agent config
Expand All @@ -47,5 +47,5 @@
owner: root
group: "{{ grafana_agent_user_group }}"
mode: 0640
notify: "restart grafana-agent"
notify: "restart grafana-agent"
when: grafana_agent_provisioned_config_file | length > 0
12 changes: 6 additions & 6 deletions roles/grafana_agent/tasks/ga-started.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
register: _result
failed_when: false
until: _result.status == 200
retries: 3
retries: 3
delay: 5
changed_when: false

- name: Check system logs if Grafana Agent is not started
when: _result.status != 200
when: _result.status != 200
block:
- name: Run journalctl

Check failure on line 17 in roles/grafana_agent/tasks/ga-started.yaml

View workflow job for this annotation

GitHub Actions / Perform Linting

command-instead-of-shell

Use shell only when shell functionality is required.
ansible.builtin.shell:
cmd: "journalctl -u grafana-agent -b -n20 --no-pager"
cmd: "journalctl -u grafana-agent -b -n20 --no-pager"
register: journal_ret
changed_when: false
- name: Output Grafana agent logs
ansible.builtin.debug:
var: journal_ret.stdout_lines
- name: Rise alerts
var: journal_ret.stdout_lines
- name: Rise alerts
ansible.builtin.assert:
that: false
fail_msg: "Service grafana-agent hasn't started."
fail_msg: "Service grafana-agent hasn't started."
Loading