mirror of https://github.com/ansible/ansible.git
Add integration tests for grafana_datasource module (#63986)
* Add setup_grafana role for integration tests * grafana_datasource: add integration tests for elastic datasource * grafana_datasource: add integration tests for influxdb datasource * grafana_datasource: add integration tests for postgres datasource * grafana_datasource: add integration tests for cloudwatch datasourcepull/63697/head
parent
0d905a0496
commit
9c17c7ad19
@ -0,0 +1 @@
|
||||
shippable/posix/group1
|
@ -0,0 +1,2 @@
|
||||
dependencies:
|
||||
- setup_grafana
|
@ -0,0 +1,67 @@
|
||||
---
|
||||
|
||||
- name: Create cloudwatch datasource
|
||||
grafana_datasource:
|
||||
name: "datasource-cloudwatch"
|
||||
grafana_url: "http://127.0.0.1:3000"
|
||||
grafana_user: "admin"
|
||||
grafana_password: "admin"
|
||||
org_id: "1"
|
||||
ds_type: "cloudwatch"
|
||||
url: "http://monitoring.us-west-1.amazonaws.com"
|
||||
aws_auth_type: "keys"
|
||||
aws_default_region: "us-west-1"
|
||||
aws_access_key: "speakFriendAndEnter"
|
||||
aws_secret_key: "mel10n"
|
||||
aws_custom_metrics_namespaces: "n1,n2"
|
||||
register: result
|
||||
|
||||
- debug:
|
||||
var: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "result.name == 'datasource-cloudwatch'"
|
||||
- "result.msg == 'Datasource datasource-cloudwatch created : Datasource added'"
|
||||
|
||||
- name: Check cloudwatch datasource creation idempotency
|
||||
grafana_datasource:
|
||||
name: "datasource-cloudwatch"
|
||||
grafana_url: "http://127.0.0.1:3000"
|
||||
grafana_user: "admin"
|
||||
grafana_password: "admin"
|
||||
org_id: "1"
|
||||
ds_type: "cloudwatch"
|
||||
url: "http://monitoring.us-west-1.amazonaws.com"
|
||||
aws_auth_type: "keys"
|
||||
aws_default_region: "us-west-1"
|
||||
aws_access_key: "speakFriendAndEnter"
|
||||
aws_secret_key: "mel10n"
|
||||
aws_custom_metrics_namespaces: "n1,n2"
|
||||
register: result
|
||||
|
||||
- debug:
|
||||
var: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
# Idempotency is not working currently
|
||||
# "result.changed == false"
|
||||
- "result.name == 'datasource-cloudwatch'"
|
||||
- "result.after.access == 'proxy'"
|
||||
- "result.after.basicAuth == false"
|
||||
- "result.after.database == None"
|
||||
- "result.after.isDefault == false"
|
||||
- "result.after.jsonData.authType == 'keys'"
|
||||
- "result.after.jsonData.customMetricsNamespaces == 'n1,n2'"
|
||||
- "result.after.jsonData.defaultRegion == 'us-west-1'"
|
||||
- "result.after.jsonData.tlsAuth == false"
|
||||
- "result.after.jsonData.tlsAuthWithCACert == false"
|
||||
- "result.after.name == 'datasource-cloudwatch'"
|
||||
- "result.after.orgId == 1"
|
||||
- "result.after.password == ''"
|
||||
- "result.after.type == 'cloudwatch'"
|
||||
- "result.after.url == 'http://monitoring.us-west-1.amazonaws.com'"
|
||||
- "result.after.user == ''"
|
||||
- "result.after.withCredentials == false"
|
@ -0,0 +1,77 @@
|
||||
---
|
||||
|
||||
- name: Create elasticsearch datasource
|
||||
grafana_datasource:
|
||||
name: "datasource-elastic"
|
||||
grafana_url: "http://127.0.0.1:3000"
|
||||
grafana_user: "admin"
|
||||
grafana_password: "admin"
|
||||
org_id: "1"
|
||||
ds_type: "elasticsearch"
|
||||
ds_url: "https://elastic.company.com:9200"
|
||||
database: "[logstash_]YYYY.MM.DD"
|
||||
basic_auth_user: "grafana"
|
||||
basic_auth_password: "******"
|
||||
time_field: "@timestamp"
|
||||
time_interval: "1m"
|
||||
interval: "Daily"
|
||||
es_version: 56
|
||||
max_concurrent_shard_requests: 42
|
||||
tls_ca_cert: "/etc/ssl/certs/ca.pem"
|
||||
register: result
|
||||
|
||||
- debug:
|
||||
var: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "result.name == 'datasource-elastic'"
|
||||
- "result.msg == 'Datasource datasource-elastic created : Datasource added'"
|
||||
|
||||
- name: Check elasticsearch datasource creation idempotency
|
||||
grafana_datasource:
|
||||
name: "datasource-elastic"
|
||||
grafana_url: "http://127.0.0.1:3000"
|
||||
grafana_user: "admin"
|
||||
grafana_password: "admin"
|
||||
org_id: "1"
|
||||
ds_type: "elasticsearch"
|
||||
ds_url: "https://elastic.company.com:9200"
|
||||
database: "[logstash_]YYYY.MM.DD"
|
||||
basic_auth_user: "grafana"
|
||||
basic_auth_password: "******"
|
||||
time_field: "@timestamp"
|
||||
time_interval: "1m"
|
||||
interval: "Daily"
|
||||
es_version: 56
|
||||
max_concurrent_shard_requests: 42
|
||||
tls_ca_cert: "/etc/ssl/certs/ca.pem"
|
||||
register: result
|
||||
|
||||
- debug:
|
||||
var: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
# Idempotency is not working currently
|
||||
# "result.changed == false"
|
||||
- "result.name == 'datasource-elastic'"
|
||||
- "result.after.basicAuth == true"
|
||||
- "result.after.basicAuthUser == 'grafana'"
|
||||
- "result.after.access == 'proxy'"
|
||||
- "result.after.database == '[logstash_]YYYY.MM.DD'"
|
||||
- "result.after.isDefault == false"
|
||||
- "result.after.jsonData.esVersion == 56"
|
||||
- "result.after.jsonData.interval == 'Daily'"
|
||||
- "result.after.jsonData.maxConcurrentShardRequests == 42"
|
||||
- "result.after.jsonData.timeField == '@timestamp'"
|
||||
- "result.after.jsonData.tlsAuth == false"
|
||||
- "result.after.jsonData.tlsAuthWithCACert == false"
|
||||
- "result.after.name == 'datasource-elastic'"
|
||||
- "result.after.orgId == 1"
|
||||
- "result.after.password == ''"
|
||||
- "result.after.type == 'elasticsearch'"
|
||||
- "result.after.url == 'https://elastic.company.com:9200'"
|
||||
- "result.after.user == ''"
|
||||
- "result.after.withCredentials == false"
|
@ -0,0 +1,61 @@
|
||||
---
|
||||
|
||||
- name: Create influxdb datasource
|
||||
grafana_datasource:
|
||||
name: "datasource-influxdb"
|
||||
grafana_url: "http://127.0.0.1:3000"
|
||||
grafana_user: "admin"
|
||||
grafana_password: "admin"
|
||||
org_id: "1"
|
||||
ds_type: "influxdb"
|
||||
ds_url: "https://influx.company.com:8086"
|
||||
database: "telegraf"
|
||||
time_interval: ">10s"
|
||||
tls_ca_cert: "/etc/ssl/certs/ca.pem"
|
||||
register: result
|
||||
|
||||
- debug:
|
||||
var: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "result.name == 'datasource-influxdb'"
|
||||
- "result.msg == 'Datasource datasource-influxdb created : Datasource added'"
|
||||
|
||||
- name: Check influxdb datasource creation idempotency
|
||||
grafana_datasource:
|
||||
name: "datasource-influxdb"
|
||||
grafana_url: "http://127.0.0.1:3000"
|
||||
grafana_user: "admin"
|
||||
grafana_password: "admin"
|
||||
org_id: "1"
|
||||
ds_type: "influxdb"
|
||||
ds_url: "https://influx.company.com:8086"
|
||||
database: "telegraf"
|
||||
time_interval: ">10s"
|
||||
tls_ca_cert: "/etc/ssl/certs/ca.pem"
|
||||
register: result
|
||||
|
||||
- debug:
|
||||
var: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
# Idempotency is not working currently
|
||||
# "result.changed == false"
|
||||
- "result.name == 'datasource-influxdb'"
|
||||
- "result.after.basicAuth == false"
|
||||
- "result.after.access == 'proxy'"
|
||||
- "result.after.database == 'telegraf'"
|
||||
- "result.after.isDefault == false"
|
||||
- "result.after.jsonData.timeInterval == '>10s'"
|
||||
- "result.after.jsonData.tlsAuth == false"
|
||||
- "result.after.jsonData.tlsAuthWithCACert == false"
|
||||
- "result.after.name == 'datasource-influxdb'"
|
||||
- "result.after.orgId == 1"
|
||||
- "result.after.password == ''"
|
||||
- "result.after.type == 'influxdb'"
|
||||
- "result.after.url == 'https://influx.company.com:8086'"
|
||||
- "result.after.user == ''"
|
||||
- "result.after.withCredentials == false"
|
@ -0,0 +1,8 @@
|
||||
- block:
|
||||
- include: elastic.yml
|
||||
- include: influx.yml
|
||||
- include: postgres.yml
|
||||
- include: cloudwatch.yml
|
||||
when:
|
||||
- ansible_distribution == 'Ubuntu'
|
||||
- ansible_distribution_release != 'trusty'
|
@ -0,0 +1,61 @@
|
||||
---
|
||||
|
||||
- name: Create postgres datasource
|
||||
grafana_datasource:
|
||||
name: "datasource-postgres"
|
||||
grafana_url: "http://127.0.0.1:3000"
|
||||
grafana_user: "admin"
|
||||
grafana_password: "admin"
|
||||
org_id: "1"
|
||||
ds_type: "postgres"
|
||||
ds_url: "postgres.company.com:5432"
|
||||
database: "db"
|
||||
user: "postgres"
|
||||
password: "iampgroot"
|
||||
sslmode: "verify-full"
|
||||
register: result
|
||||
|
||||
- debug:
|
||||
var: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "result.name == 'datasource-postgres'"
|
||||
- "result.msg == 'Datasource datasource-postgres created : Datasource added'"
|
||||
|
||||
- name: Check postgres datasource creation idempotency
|
||||
grafana_datasource:
|
||||
name: "datasource-postgres"
|
||||
grafana_url: "http://127.0.0.1:3000"
|
||||
grafana_user: "admin"
|
||||
grafana_password: "admin"
|
||||
org_id: "1"
|
||||
ds_type: "postgres"
|
||||
ds_url: "postgres.company.com:5432"
|
||||
database: "db"
|
||||
user: "postgres"
|
||||
password: "iampgroot"
|
||||
sslmode: "verify-full"
|
||||
register: result
|
||||
|
||||
- debug:
|
||||
var: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
# Idempotency is not working currently
|
||||
# "result.changed == false"
|
||||
- "result.name == 'datasource-postgres'"
|
||||
- "result.after.basicAuth == false"
|
||||
- "result.after.database == 'db'"
|
||||
- "result.after.isDefault == false"
|
||||
- "result.after.jsonData.sslmode == 'verify-full'"
|
||||
- "result.after.jsonData.tlsAuth == false"
|
||||
- "result.after.jsonData.tlsAuthWithCACert == false"
|
||||
- "result.after.name == 'datasource-postgres'"
|
||||
- "result.after.orgId == 1"
|
||||
- "result.after.type == 'postgres'"
|
||||
- "result.after.url == 'postgres.company.com:5432'"
|
||||
- "result.after.user == 'postgres'"
|
||||
- "result.after.withCredentials == false"
|
@ -0,0 +1,9 @@
|
||||
[grafana]
|
||||
name=grafana
|
||||
baseurl=https://packages.grafana.com/oss/rpm
|
||||
repo_gpgcheck=1
|
||||
enabled=1
|
||||
gpgcheck=1
|
||||
gpgkey=https://packages.grafana.com/gpg.key
|
||||
sslverify=1
|
||||
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
|
@ -0,0 +1,2 @@
|
||||
- include: setup.yml
|
||||
when: ansible_distribution == 'Ubuntu' and ansible_distribution_release != 'trusty'
|
@ -0,0 +1,30 @@
|
||||
- name: Install deps
|
||||
package:
|
||||
name:
|
||||
- apt-transport-https
|
||||
- software-properties-common
|
||||
|
||||
- name: Add the Grafana GPG key
|
||||
apt_key:
|
||||
url: https://packages.grafana.com/gpg.key
|
||||
state: present
|
||||
|
||||
- name: Add grafana apt repository
|
||||
apt_repository:
|
||||
repo: deb https://packages.grafana.com/oss/deb stable main
|
||||
state: present
|
||||
|
||||
- name: Install Grafana server
|
||||
apt:
|
||||
allow_unauthenticated: yes
|
||||
name: grafana
|
||||
|
||||
- name: start Grafana
|
||||
service:
|
||||
name: grafana-server
|
||||
state: started
|
||||
|
||||
- name: wait for grafana to be up
|
||||
wait_for:
|
||||
host: 127.0.0.1
|
||||
port: 3000
|
Loading…
Reference in New Issue