Adding CI tests

This commit is contained in:
Ishan Jain 2022-08-11 10:39:04 +05:30
parent 52d5131587
commit 3c3d7655e7
15 changed files with 400 additions and 52 deletions

214
.github/workflows/ansible-test.yml vendored Normal file
View File

@ -0,0 +1,214 @@
# README FIRST
# 1. replace "NAMESPACE" and "COLLECTION_NAME" with the correct name in the env section (e.g. with 'community' and 'mycollection')
# 2. If you don't have unit tests remove that section
# 3. If your collection depends on other collections ensure they are installed, see "Install collection dependencies"
# If you need help please ask in #ansible-community on the Libera.chat IRC network
name: CI
on:
# Run CI against all pushes (direct commits, also merged PRs), Pull Requests
push:
branches:
- main
- stable-*
pull_request:
# Run CI once per day (at 06:00 UTC)
# This ensures that even if there haven't been commits that we are still testing against latest version of ansible-test for each ansible-base version
schedule:
- cron: '0 6 * * *'
env:
NAMESPACE: NAMESPACE
COLLECTION_NAME: COLLECTION_NAME
jobs:
###
# Sanity tests (REQUIRED)
#
# https://docs.ansible.com/ansible/latest/dev_guide/testing_sanity.html
sanity:
name: Sanity (Ⓐ${{ matrix.ansible }})
strategy:
matrix:
ansible:
# It's important that Sanity is tested against all stable-X.Y branches
# Testing against `devel` may fail as new tests are added.
# - stable-2.9 # Only if your collection supports Ansible 2.9
- stable-2.10
- stable-2.11
- stable-2.12
- devel
runs-on: ubuntu-latest
steps:
# ansible-test requires the collection to be in a directory in the form
# .../ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}/
- 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:
# it is just required to run that once as "ansible-test sanity" in the docker image
# will run on all python versions it supports.
python-version: '3.10'
# Install the head of the given branch (devel, stable-2.10)
- name: Install ansible-base (${{ matrix.ansible }})
run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check
# run ansible-test sanity inside of Docker.
# The docker container has all the pinned dependencies that are required
# and all python versions ansible supports.
- name: Run sanity tests
run: ansible-test sanity --docker -v --color --coverage
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
# ansible-test support producing code coverage date
- name: Generate coverage report
run: ansible-test coverage xml -v --requirements --group-by command --group-by version
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
# See the reports at https://codecov.io/gh/GITHUBORG/REPONAME
- uses: codecov/codecov-action@v3
with:
fail_ci_if_error: false
###
# Unit tests (OPTIONAL)
#
# https://docs.ansible.com/ansible/latest/dev_guide/testing_units.html
units:
runs-on: ubuntu-latest
name: Units (Ⓐ${{ matrix.ansible }})
strategy:
# As soon as the first unit test fails, cancel the others to free up the CI queue
fail-fast: true
matrix:
ansible:
# - stable-2.9 # Only if your collection supports Ansible 2.9
- stable-2.10
- stable-2.11
- stable-2.12
- devel
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:
# it is just required to run that once as "ansible-test units" in the docker image
# will run on all python versions it supports.
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
# OPTIONAL If your unit test requires Python libraries from other collections
# Install them like this
- name: Install collection dependencies
run: ansible-galaxy collection install ansible.netcommon ansible.utils -p .
# Run the unit tests
- name: Run unit test
run: ansible-test units -v --color --docker --coverage
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
# ansible-test support producing code coverage date
- name: Generate coverage report
run: ansible-test coverage xml -v --requirements --group-by command --group-by version
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
# See the reports at https://codecov.io/gh/GITHUBORG/REPONAME
- uses: codecov/codecov-action@v3
with:
fail_ci_if_error: false
###
# Integration tests (RECOMMENDED)
#
# https://docs.ansible.com/ansible/latest/dev_guide/testing_integration.html
# If the application you are testing is available as a docker container and you want to test
# multiple versions see the following for an example:
# https://github.com/ansible-collections/community.zabbix/tree/master/.github/workflows
integration:
runs-on: ubuntu-latest
name: I (Ⓐ${{ matrix.ansible }}+py${{ matrix.python }})
strategy:
fail-fast: false
matrix:
ansible:
# - stable-2.9 # Only if your collection supports Ansible 2.9
- stable-2.10
- stable-2.11
- stable-2.12
- devel
python:
- '2.6'
- '2.7'
- '3.5'
- '3.6'
- '3.7'
- '3.8'
- '3.9'
- '3.10'
exclude:
# Because ansible-test doesn't support Python 3.9 for Ansible 2.9
# and Python 3.10 is supported in 2.12 or later.
- ansible: stable-2.9
python: '3.9'
- ansible: stable-2.9
python: '3.10'
- ansible: stable-2.10
python: '3.10'
- ansible: stable-2.11
python: '3.10'
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:
# it is just required to run that once as "ansible-test integration" in the docker image
# will run on all python versions it supports.
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
# OPTIONAL If your integration test requires Python libraries or modules from other collections
# Install them like this
- name: Install collection dependencies
run: ansible-galaxy collection install ansible.netcommon -p .
# Run the integration tests
- name: Run integration test
run: ansible-test integration -v --color --retry-on-error --continue-on-error --diff --python ${{ matrix.python }} --docker --coverage
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
# ansible-test support producing code coverage date
- name: Generate coverage report
run: ansible-test coverage xml -v --requirements --group-by command --group-by version
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
# See the reports at https://codecov.io/gh/GITHUBORG/REPONAME
- uses: codecov/codecov-action@v3
with:
fail_ci_if_error: false

24
CHANGELOG.rst Normal file
View File

@ -0,0 +1,24 @@
=============================
Grafana.Grafana Release Notes
=============================
.. contents:: Topics
v0.0.2
======
v0.0.1
======
New Modules
-----------
- grafana.grafana.alert_contact_point - Manage Alerting Contact points in Grafana
- grafana.grafana.alert_notification_policy - Sets the notification policy tree in Grafana Alerting
- grafana.grafana.cloud_api_key - Manage Grafana Cloud API keys
- grafana.grafana.cloud_plugin - Manage Grafana Cloud Plugins
- grafana.grafana.cloud_stack - Manage Grafana Cloud stack
- grafana.grafana.dashboard - Manage Dashboards in Grafana
- grafana.grafana.datasource - Manage Data sources in Grafana
- grafana.grafana.folder - Manage Folders in Grafana

View File

@ -2,13 +2,10 @@
This collection contains modules and plugins to assist in automating managing of resources in Grafana with Ansible.
## Installation and Usage
### Requirements
## Ansible version compatibility
The collection is tested and supported with:
* ansible >= 2.10.0
* python >= 3.10
* ansible >= 2.9
## Installing the collection
@ -85,6 +82,9 @@ and work on it there.
We use `ansible-test` for sanity.
## Code of Conduct
This collection follows the Ansible project's [Code of Conduct](https://docs.ansible.com/ansible/devel/community/code_of_conduct.html). Please read and familiarize yourself with this doc
## More information
- [Ansible Collection overview](https://github.com/ansible-collections/overview)

View File

@ -0,0 +1,57 @@
objects:
role: {}
plugins:
become: {}
cache: {}
callback: {}
cliconf: {}
connection: {}
httpapi: {}
inventory: {}
lookup: {}
module:
alert_contact_point:
description: Manage Alerting Contact points in Grafana
name: alert_contact_point
namespace: ''
version_added: 0.0.1
alert_notification_policy:
description: Sets the notification policy tree in Grafana Alerting
name: alert_notification_policy
namespace: ''
version_added: 0.0.1
cloud_api_key:
description: Manage Grafana Cloud API keys
name: cloud_api_key
namespace: ''
version_added: 0.0.1
cloud_plugin:
description: Manage Grafana Cloud Plugins
name: cloud_plugin
namespace: ''
version_added: 0.0.1
cloud_stack:
description: Manage Grafana Cloud stack
name: cloud_stack
namespace: ''
version_added: 0.0.1
dashboard:
description: Manage Dashboards in Grafana
name: dashboard
namespace: ''
version_added: 0.0.1
datasource:
description: Manage Data sources in Grafana
name: datasource
namespace: ''
version_added: 0.0.1
folder:
description: Manage Folders in Grafana
name: folder
namespace: ''
version_added: 0.0.1
netconf: {}
shell: {}
strategy: {}
vars: {}
version: 0.0.2

31
changelogs/changelog.yaml Normal file
View File

@ -0,0 +1,31 @@
ancestor: null
releases:
0.0.1:
modules:
- description: Manage Alerting Contact points in Grafana
name: alert_contact_point
namespace: ''
- description: Sets the notification policy tree in Grafana Alerting
name: alert_notification_policy
namespace: ''
- description: Manage Grafana Cloud API keys
name: cloud_api_key
namespace: ''
- description: Manage Grafana Cloud Plugins
name: cloud_plugin
namespace: ''
- description: Manage Grafana Cloud stack
name: cloud_stack
namespace: ''
- description: Manage Dashboards in Grafana
name: dashboard
namespace: ''
- description: Manage Data sources in Grafana
name: datasource
namespace: ''
- description: Manage Folders in Grafana
name: folder
namespace: ''
release_date: '2022-08-11'
0.0.2:
release_date: '2022-08-11'

32
changelogs/config.yaml Normal file
View File

@ -0,0 +1,32 @@
changelog_filename_template: ../CHANGELOG.rst
changelog_filename_version_depth: 0
changes_file: changelog.yaml
changes_format: combined
ignore_other_fragment_extensions: true
keep_fragments: false
mention_ancestor: true
new_plugins_after_name: removed_features
notesdir: fragments
prelude_section_name: release_summary
prelude_section_title: Release Summary
sanitize_changelog: true
sections:
- - major_changes
- Major Changes
- - minor_changes
- Minor Changes
- - breaking_changes
- Breaking Changes / Porting Guide
- - deprecated_features
- Deprecated Features
- - removed_features
- Removed Features (previously deprecated)
- - security_fixes
- Security Fixes
- - bugfixes
- Bugfixes
- - known_issues
- Known Issues
title: Grafana.Grafana
trivial_section_name: trivial
use_fqcn: true

View File

@ -1,12 +1,2 @@
---
requires_ansible: '>=2.10.0'
action_groups:
grafana:
- alert_contact_point
- alert_notification_policy
- cloud_api_key
- cloud_plugin
- cloud_stack
- dashboard
- datasource
- folder
requires_ansible: '>=2.19'

View File

@ -2,7 +2,7 @@
DOCUMENTATION = '''
---
module: alert_contact_point
module: grafana.grafana.alert_contact_point
author:
- Ishan Jain (@ishanjainn)
version_added: "0.0.1"
@ -50,7 +50,7 @@ options:
EXAMPLES = '''
- name: Create/Update Alerting contact point
alert_contact_point:
grafana.grafana.alert_contact_point:
name: ops-email
uid: opsemail
type: email
@ -62,7 +62,7 @@ EXAMPLES = '''
state: present
- name: Delete Alerting contact point
alert_contact_point:
grafana.grafana.alert_contact_point:
name: ops-email
uid: opsemail
type: email
@ -196,4 +196,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -2,7 +2,7 @@
DOCUMENTATION = '''
---
module: alert_notification_policy
module: grafana.grafana.alert_notification_policy
author:
- Ishan Jain (@ishanjainn)
version_added: "0.0.1"
@ -73,7 +73,7 @@ options:
EXAMPLES = '''
- name: Set Notification policy tree
alert_notification_policy:
grafana.grafana.alert_notification_policy:
stack_slug: "{{ stack_slug }}"
grafana_api_key: "{{ grafana_api_key }}"
routes: [
@ -84,7 +84,7 @@ EXAMPLES = '''
]
- name: Set nested Notification policies
alert_notification_policy:
grafana.grafana.alert_notification_policy:
routes: [
{
receiver: myReceiver,
@ -185,4 +185,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -2,7 +2,7 @@
DOCUMENTATION = '''
---
module: cloud_api_key
module: grafana.grafana.cloud_api_key
author:
- Ishan Jain (@ishanjainn)
version_added: "0.0.1"
@ -45,7 +45,7 @@ options:
EXAMPLES = '''
- name: Create Grafana Cloud API key
cloud_api_key:
grafana.grafana.cloud_api_key:
name: key_name
role: Admin
org_slug: "{{ org_slug }}"
@ -54,7 +54,7 @@ EXAMPLES = '''
state: present
- name: Delete Grafana Cloud API key
cloud_api_key:
grafana.grafana.cloud_api_key:
name: key_name
org_slug: "{{ org_slug }}"
existing_cloud_api_key: "{{ grafana_cloud_api_key }}"
@ -125,4 +125,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -2,7 +2,7 @@
DOCUMENTATION = '''
---
module: cloud_plugin
module: grafana.grafana.cloud_plugin
author:
- Ishan Jain (@ishanjainn)
version_added: "0.0.1"
@ -40,7 +40,7 @@ options:
EXAMPLES = '''
- name: Create/Update a plugin
cloud_plugin:
grafana.grafana.cloud_plugin:
name: grafana-github-datasource
version: 1.0.14
stack_slug: "{{ stack_slug }}"
@ -48,7 +48,7 @@ EXAMPLES = '''
state: present
- name: Delete a Grafana Cloud stack
cloud_plugin:
grafana.grafana.cloud_plugin:
name: grafana-github-datasource
stack_slug: "{{ stack_slug }}"
cloud_api_key: "{{ grafana_cloud_api_key }}"
@ -150,4 +150,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -2,7 +2,7 @@
DOCUMENTATION = '''
---
module: cloud_stack
module: grafana.grafana.cloud_stack
author:
- Ishan Jain (@ishanjainn)
version_added: "0.0.1"
@ -51,7 +51,7 @@ options:
EXAMPLES = '''
- name: Create a Grafana Cloud stack
cloud_stack:
grafana.grafana.cloud_stack:
name: company_name
slug: company_name
cloud_api_key: "{{ grafana_cloud_api_key }}"
@ -60,7 +60,7 @@ EXAMPLES = '''
state: present
- name: Delete a Grafana Cloud stack
cloud_stack:
grafana.grafana.cloud_stack:
name: company_name
slug: company_name
cloud_api_key: "{{ grafana_cloud_api_key }}"
@ -191,4 +191,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -2,7 +2,7 @@
DOCUMENTATION = '''
---
module: dashboard
module: grafana.grafana.dashboard
author:
- Ishan Jain (@ishanjainn)
version_added: "0.0.1"
@ -35,15 +35,15 @@ options:
EXAMPLES = '''
- name: Create/Update a dashboard
dashboard:
datasource: "{{ lookup('file', 'dashboard.json') }}"
grafana.grafana.dashboard:
datasource: "{{ lookup('ansible.builtin.file', 'dashboard.json') }}"
stack_slug: "{{ stack_slug }}"
cloud_api_key: "{{ grafana_cloud_api_key }}"
state: present
- name: Delete dashboard
dashboard:
datasource: "{{ lookup('file', 'dashboard.json') }}"
grafana.grafana.dashboard:
datasource: "{{ lookup('ansible.builtin.file', 'dashboard.json') }}"
stack_slug: "{{ stack_slug }}"
cloud_api_key: "{{ grafana_cloud_api_key }}"
state: absent
@ -147,4 +147,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -2,7 +2,7 @@
DOCUMENTATION = '''
---
module: datasource
module: grafana.grafana.datasource
author:
- Ishan Jain (@ishanjainn)
version_added: "0.0.1"
@ -35,15 +35,15 @@ options:
EXAMPLES = '''
- name: Create/Update Data sources
datasource:
datasource: "{{ lookup('file', 'datasource.json') }}"
grafana.grafana.datasource:
datasource: "{{ lookup('ansible.builtin.file', 'datasource.json') }}"
stack_slug: "{{ stack_slug }}"
cloud_api_key: "{{ grafana_cloud_api_key }}"
state: present
- name: Delete Data sources
datasource:
datasource: "{{ lookup('file', 'datasource.json') }}"
grafana.grafana.datasource:
datasource: "{{ lookup('ansible.builtin.file', 'datasource.json') }}"
stack_slug: "{{ stack_slug }}"
cloud_api_key: "{{ grafana_cloud_api_key }}"
state: absent
@ -140,4 +140,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@ -2,7 +2,7 @@
DOCUMENTATION = '''
---
module: folder
module: grafana.grafana.folder
author:
- Ishan Jain (@ishanjainn)
version_added: "0.0.1"
@ -41,7 +41,7 @@ options:
EXAMPLES = '''
- name: Create/Update a Folder in Grafana
folder:
grafana.grafana.folder:
title: folder_name
uid: folder_name
overwrite: true
@ -50,7 +50,7 @@ EXAMPLES = '''
state: present
- name: Delete a Folder in Grafana
folder:
grafana.grafana.folder:
uid: folder_name
stack_slug: "{{ stack_slug }}"
cloud_api_key: "{{ grafana_cloud_api_key }}"
@ -200,4 +200,4 @@ def main():
if __name__ == '__main__':
main()
main()