Add Integration tests for the modules
* add integration tests * add tests * add checkout * check cat of the file * updatng tests * rename folder * update action * test str api key * update config file name * updated versions for tests * updated action * updated action * update test * updated ytests * updated check * Delete play.yml * updated check * update delete test * updated conditional check * updated check * updated tests * updated tests * Updated tests * Add folder test * fail test * updated tests * updated tests * update tests * add cloud stack test * update stack test * update test * update test * update test * update test * update test * update test * update tests * update tests * updated test * add plugin test * updated tests * add api key test * updat etest * updated tests * add notification policy tree test * reorg * fix * fix * update * add contact point test * update action * Seperate actions * update action name * update action * update action * update seq number * Updating CI tests * Edit Actions
This commit is contained in:
parent
43091e1e3c
commit
c718a25d7d
48
.github/workflows/ansible-test.yml
vendored
48
.github/workflows/ansible-test.yml
vendored
@ -1,48 +0,0 @@
|
||||
name: CI
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
schedule:
|
||||
- cron: '0 6 * * *'
|
||||
env:
|
||||
NAMESPACE: grafana
|
||||
COLLECTION_NAME: grafana
|
||||
|
||||
jobs:
|
||||
|
||||
sanity:
|
||||
name: Sanity (Ⓐ${{ matrix.ansible }})
|
||||
strategy:
|
||||
matrix:
|
||||
ansible:
|
||||
- stable-2.10
|
||||
- stable-2.11
|
||||
- stable-2.12
|
||||
- devel
|
||||
runs-on: ubuntu-latest
|
||||
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.9'
|
||||
|
||||
- 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 --docker -v --color --coverage
|
||||
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
|
||||
|
||||
- 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}}
|
||||
|
||||
- uses: codecov/codecov-action@v3
|
||||
with:
|
||||
fail_ci_if_error: false
|
88
.github/workflows/ci-test.yml
vendored
Normal file
88
.github/workflows/ci-test.yml
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
name: CI Tests
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
schedule:
|
||||
- cron: '0 6 * * *'
|
||||
env:
|
||||
NAMESPACE: grafana
|
||||
COLLECTION_NAME: grafana
|
||||
|
||||
jobs:
|
||||
|
||||
sanity:
|
||||
name: Sanity (Ⓐ${{ matrix.ansible }})
|
||||
strategy:
|
||||
matrix:
|
||||
ansible:
|
||||
- stable-2.10
|
||||
- stable-2.11
|
||||
- stable-2.12
|
||||
- devel
|
||||
runs-on: ubuntu-latest
|
||||
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.9'
|
||||
|
||||
- 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 --docker -v --color --coverage
|
||||
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
|
||||
|
||||
- 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}}
|
||||
|
||||
- uses: codecov/codecov-action@v3
|
||||
with:
|
||||
fail_ci_if_error: false
|
||||
|
||||
integration:
|
||||
runs-on: ubuntu-latest
|
||||
name: Integration ${{ matrix.ansible }}-py${{ matrix.python }})
|
||||
strategy:
|
||||
fail-fast: false
|
||||
max-parallel: 1
|
||||
matrix:
|
||||
ansible:
|
||||
- stable-2.13
|
||||
python:
|
||||
- '3.9'
|
||||
|
||||
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
|
||||
stack_name: ${{ secrets.ANSIBLE_TEST_STACK_NAME }}
|
||||
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 }}
|
||||
EOF
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: 3.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
|
||||
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
|
69
.github/workflows/full-integration-test.yml
vendored
Normal file
69
.github/workflows/full-integration-test.yml
vendored
Normal file
@ -0,0 +1,69 @@
|
||||
name: Full Integration Test
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 0 * * 0'
|
||||
env:
|
||||
NAMESPACE: grafana
|
||||
COLLECTION_NAME: grafana
|
||||
|
||||
jobs:
|
||||
|
||||
integration:
|
||||
runs-on: ubuntu-latest
|
||||
name: ${{ matrix.ansible }}-py${{ matrix.python }})
|
||||
strategy:
|
||||
fail-fast: false
|
||||
max-parallel: 1
|
||||
matrix:
|
||||
ansible:
|
||||
- stable-2.9
|
||||
- stable-2.10
|
||||
- stable-2.11
|
||||
- stable-2.12
|
||||
- stable-2.13
|
||||
# - devel
|
||||
# - milestone
|
||||
python:
|
||||
- '2.7'
|
||||
- '3.5'
|
||||
- '3.6'
|
||||
- '3.7'
|
||||
- '3.8'
|
||||
- '3.9'
|
||||
exclude:
|
||||
- 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@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
|
||||
stack_name: ${{ secrets.ANSIBLE_TEST_STACK_NAME }}
|
||||
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 }}
|
||||
EOF
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: 3.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
|
||||
working-directory: ./ansible_collections/${{env.NAMESPACE}}/${{env.COLLECTION_NAME}}
|
53
tests/integration/targets/alert_contact_point/tasks/main.yml
Normal file
53
tests/integration/targets/alert_contact_point/tasks/main.yml
Normal file
@ -0,0 +1,53 @@
|
||||
- name: Create Alerting contact point
|
||||
grafana.grafana.alert_contact_point:
|
||||
name: ops-email
|
||||
uid: opsemail
|
||||
type: email
|
||||
settings: {
|
||||
addresses: "ops@mydomain.com,devs@mydomain.com"
|
||||
}
|
||||
stack_slug: "{{ stack_name }}"
|
||||
grafana_api_key: "{{ grafana_api_key }}"
|
||||
state: present
|
||||
register: add_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- add_result.failed == false
|
||||
- add_result.output.provenance == "api"
|
||||
|
||||
- name: Update Alerting contact point
|
||||
grafana.grafana.alert_contact_point:
|
||||
name: ops-email
|
||||
uid: opsemail
|
||||
type: email
|
||||
settings: {
|
||||
addresses: "ops@mydomain.com,devs@mydomain.com,admin@mydomain.com"
|
||||
}
|
||||
stack_slug: "{{ stack_name }}"
|
||||
grafana_api_key: "{{ grafana_api_key }}"
|
||||
state: present
|
||||
register: update_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- update_result.failed == false
|
||||
- update_result.output.provenance == "api"
|
||||
|
||||
- name: Delete Alerting contact point
|
||||
grafana.grafana.alert_contact_point:
|
||||
name: ops-email
|
||||
uid: opsemail
|
||||
type: email
|
||||
settings: {
|
||||
addresses: "ops@mydomain.com,devs@mydomain.com,admin@mydomain.com"
|
||||
}
|
||||
stack_slug: "{{ stack_name }}"
|
||||
grafana_api_key: "{{ grafana_api_key }}"
|
||||
state: absent
|
||||
register: delete_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- delete_result.failed == false
|
||||
- delete_result.output.message == "contactpoint deleted"
|
@ -0,0 +1,16 @@
|
||||
- name: Set Notification policy tree
|
||||
grafana.grafana.alert_notification_policy:
|
||||
stack_slug: "{{ stack_name }}"
|
||||
grafana_api_key: "{{ grafana_api_key }}"
|
||||
routes: [
|
||||
{
|
||||
receiver: grafana-default-email,
|
||||
object_matchers: [["env", "=", "Production"]],
|
||||
}
|
||||
]
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.failed == false
|
||||
- result.output.provenance == "api"
|
43
tests/integration/targets/cloud_api_key/tasks/main.yml
Normal file
43
tests/integration/targets/cloud_api_key/tasks/main.yml
Normal file
@ -0,0 +1,43 @@
|
||||
- name: Create Grafana Cloud API key
|
||||
grafana.grafana.cloud_api_key:
|
||||
name: ansible-integration-test
|
||||
role: Admin
|
||||
org_slug: "{{ org_name }}"
|
||||
existing_cloud_api_key: "{{ grafana_cloud_api_key }}"
|
||||
fail_if_already_created: False
|
||||
state: present
|
||||
register: add_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- add_result.changed == true
|
||||
- add_result.output.name == "ansible-integration-test"
|
||||
|
||||
- name: Re-run previous task
|
||||
grafana.grafana.cloud_api_key:
|
||||
name: ansible-integration-test
|
||||
role: Admin
|
||||
org_slug: "{{ org_name }}"
|
||||
existing_cloud_api_key: "{{ grafana_cloud_api_key }}"
|
||||
fail_if_already_created: False
|
||||
state: present
|
||||
register: update_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- update_result.changed == false
|
||||
- update_result.output == "A Cloud API key with the same name already exists"
|
||||
|
||||
- name: Delete Grafana Cloud API key
|
||||
grafana.grafana.cloud_api_key:
|
||||
name: ansible-integration-test
|
||||
role: Admin
|
||||
org_slug: "{{ org_name }}"
|
||||
existing_cloud_api_key: "{{ grafana_cloud_api_key }}"
|
||||
state: absent
|
||||
register: delete_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- delete_result.changed == true
|
||||
- delete_result.output == "Cloud API key is deleted"
|
41
tests/integration/targets/cloud_plugin/tasks/main.yml
Normal file
41
tests/integration/targets/cloud_plugin/tasks/main.yml
Normal file
@ -0,0 +1,41 @@
|
||||
- name: Add a plugin
|
||||
grafana.grafana.cloud_plugin:
|
||||
name: grafana-github-datasource
|
||||
version: 1.0.14
|
||||
stack_slug: "{{ stack_name }}"
|
||||
cloud_api_key: "{{ grafana_cloud_api_key }}"
|
||||
state: present
|
||||
register: add_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- add_result.changed == true
|
||||
- add_result.pluginName == "GitHub"
|
||||
|
||||
- name: update a plugin
|
||||
grafana.grafana.cloud_plugin:
|
||||
name: grafana-github-datasource
|
||||
version: 1.0.15
|
||||
stack_slug: "{{ stack_name }}"
|
||||
cloud_api_key: "{{ grafana_cloud_api_key }}"
|
||||
state: present
|
||||
register: update_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- update_result.changed == true
|
||||
- update_result.pluginName == "GitHub"
|
||||
|
||||
- name: Delete a plugin
|
||||
grafana.grafana.cloud_plugin:
|
||||
name: grafana-github-datasource
|
||||
version: 1.0.15
|
||||
stack_slug: "{{ stack_name }}"
|
||||
cloud_api_key: "{{ grafana_cloud_api_key }}"
|
||||
state: absent
|
||||
register: delete_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- delete_result.changed == true
|
||||
- delete_result.pluginName == "GitHub"
|
30
tests/integration/targets/cloud_stack/tasks/main.yml
Normal file
30
tests/integration/targets/cloud_stack/tasks/main.yml
Normal file
@ -0,0 +1,30 @@
|
||||
- name: Create a Grafana Cloud stack
|
||||
grafana.grafana.cloud_stack:
|
||||
name: ansiblestack
|
||||
stack_slug: ansiblestack
|
||||
cloud_api_key: "{{ grafana_cloud_api_key }}"
|
||||
org_slug: "{{ org_name }}"
|
||||
state: present
|
||||
register: create_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- create_result.url == "https://ansiblestack.grafana.net"
|
||||
|
||||
- name: Sleep for 30 seconds
|
||||
ansible.builtin.wait_for:
|
||||
timeout: 30
|
||||
|
||||
- name: Delete a Grafana Cloud stack
|
||||
grafana.grafana.cloud_stack:
|
||||
name: ansiblestack
|
||||
stack_slug: ansiblestack
|
||||
cloud_api_key: "{{ grafana_cloud_api_key }}"
|
||||
org_slug: "{{ org_name }}"
|
||||
state: absent
|
||||
register: delete_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- delete_result.changed == true
|
||||
- delete_result.url == "https://ansiblestack.grafana.net"
|
47
tests/integration/targets/dashboard/tasks/main.yml
Normal file
47
tests/integration/targets/dashboard/tasks/main.yml
Normal file
@ -0,0 +1,47 @@
|
||||
- name: Create/Update a dashboard
|
||||
grafana.grafana.dashboard:
|
||||
dashboard: {
|
||||
"dashboard": {
|
||||
"uid": test1234,
|
||||
"title": "Ansible Integration Test",
|
||||
"tags": [ "templated" ],
|
||||
"timezone": "browser",
|
||||
"schemaVersion": 16,
|
||||
"version": 0,
|
||||
"refresh": "25s"
|
||||
},
|
||||
"overwrite": true
|
||||
}
|
||||
stack_slug: "{{ stack_name }}"
|
||||
grafana_api_key: "{{ grafana_api_key }}"
|
||||
state: present
|
||||
register: result_present
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result_present.changed == true
|
||||
- result_present.output.status == "success"
|
||||
|
||||
- name: Delete dashboard
|
||||
grafana.grafana.dashboard:
|
||||
dashboard: {
|
||||
"dashboard": {
|
||||
"uid": test1234,
|
||||
"title": "Ansible Integration Test",
|
||||
"tags": [ "templated" ],
|
||||
"timezone": "browser",
|
||||
"schemaVersion": 16,
|
||||
"version": 0,
|
||||
"refresh": "25s"
|
||||
},
|
||||
"overwrite": true
|
||||
}
|
||||
stack_slug: "{{ stack_name }}"
|
||||
grafana_api_key: "{{ grafana_api_key }}"
|
||||
state: absent
|
||||
register: result_absent
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result_absent.changed == true
|
||||
- result_absent.output.message == "Dashboard Ansible Integration Test deleted"
|
23
tests/integration/targets/datasource/tasks/main.yml
Normal file
23
tests/integration/targets/datasource/tasks/main.yml
Normal file
@ -0,0 +1,23 @@
|
||||
- name: Create/Update a Data Source
|
||||
grafana.grafana.datasource:
|
||||
datasource: {
|
||||
name: "ansible-integration",
|
||||
type: "influxdb",
|
||||
url: "https://grafana.github.com/grafana-ansible-collection",
|
||||
user: "user",
|
||||
secureJsonData:
|
||||
{ password: "password" },
|
||||
database: "db-name",
|
||||
id: 123,
|
||||
uid: "ansibletest",
|
||||
access: "proxy"
|
||||
}
|
||||
stack_slug: "{{ stack_name }}"
|
||||
grafana_api_key: "{{ grafana_api_key }}"
|
||||
state: present
|
||||
register: create_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- create_result.changed == true
|
||||
- create_result.output.message == "Datasource added" or create_result.output.message == "Datasource updated"
|
29
tests/integration/targets/folder/tasks/main.yml
Normal file
29
tests/integration/targets/folder/tasks/main.yml
Normal file
@ -0,0 +1,29 @@
|
||||
- name: Create/Update a Folder in Grafana
|
||||
grafana.grafana.folder:
|
||||
title: Ansible Integration test
|
||||
uid: test123
|
||||
overwrite: true
|
||||
stack_slug: "{{ stack_name }}"
|
||||
grafana_api_key: "{{ grafana_api_key }}"
|
||||
state: present
|
||||
register: create_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- create_result.changed == true
|
||||
- create_result.output.url == "/dashboards/f/test123/ansible-integration-test"
|
||||
|
||||
- name: Delete a folder
|
||||
grafana.grafana.folder:
|
||||
title: Ansible Integration test
|
||||
uid: test123
|
||||
overwrite: true
|
||||
stack_slug: "{{ stack_name }}"
|
||||
grafana_api_key: "{{ grafana_api_key }}"
|
||||
state: absent
|
||||
register: delete_result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- delete_result.changed == true
|
||||
- delete_result.output.message == "Folder Ansible Integration test deleted"
|
Loading…
Reference in New Issue
Block a user