From 9c17c7ad199722e0994b070bbb48a14f1057a98c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20REY?= Date: Tue, 29 Oct 2019 22:39:38 +0100 Subject: [PATCH] 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 datasource --- .../targets/grafana_datasource/aliases | 1 + .../targets/grafana_datasource/meta/main.yml | 2 + .../grafana_datasource/tasks/cloudwatch.yml | 67 ++++++++++++++++ .../grafana_datasource/tasks/elastic.yml | 77 +++++++++++++++++++ .../grafana_datasource/tasks/influx.yml | 61 +++++++++++++++ .../targets/grafana_datasource/tasks/main.yml | 8 ++ .../grafana_datasource/tasks/postgres.yml | 61 +++++++++++++++ .../targets/setup_grafana/files/grafana.repo | 9 +++ .../targets/setup_grafana/tasks/main.yml | 2 + .../targets/setup_grafana/tasks/setup.yml | 30 ++++++++ 10 files changed, 318 insertions(+) create mode 100644 test/integration/targets/grafana_datasource/aliases create mode 100644 test/integration/targets/grafana_datasource/meta/main.yml create mode 100644 test/integration/targets/grafana_datasource/tasks/cloudwatch.yml create mode 100644 test/integration/targets/grafana_datasource/tasks/elastic.yml create mode 100644 test/integration/targets/grafana_datasource/tasks/influx.yml create mode 100644 test/integration/targets/grafana_datasource/tasks/main.yml create mode 100644 test/integration/targets/grafana_datasource/tasks/postgres.yml create mode 100644 test/integration/targets/setup_grafana/files/grafana.repo create mode 100644 test/integration/targets/setup_grafana/tasks/main.yml create mode 100644 test/integration/targets/setup_grafana/tasks/setup.yml diff --git a/test/integration/targets/grafana_datasource/aliases b/test/integration/targets/grafana_datasource/aliases new file mode 100644 index 00000000000..a6dafcf8cd8 --- /dev/null +++ b/test/integration/targets/grafana_datasource/aliases @@ -0,0 +1 @@ +shippable/posix/group1 diff --git a/test/integration/targets/grafana_datasource/meta/main.yml b/test/integration/targets/grafana_datasource/meta/main.yml new file mode 100644 index 00000000000..af628245fb3 --- /dev/null +++ b/test/integration/targets/grafana_datasource/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - setup_grafana diff --git a/test/integration/targets/grafana_datasource/tasks/cloudwatch.yml b/test/integration/targets/grafana_datasource/tasks/cloudwatch.yml new file mode 100644 index 00000000000..1119eb1ac1c --- /dev/null +++ b/test/integration/targets/grafana_datasource/tasks/cloudwatch.yml @@ -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" diff --git a/test/integration/targets/grafana_datasource/tasks/elastic.yml b/test/integration/targets/grafana_datasource/tasks/elastic.yml new file mode 100644 index 00000000000..471a2ece5bb --- /dev/null +++ b/test/integration/targets/grafana_datasource/tasks/elastic.yml @@ -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" diff --git a/test/integration/targets/grafana_datasource/tasks/influx.yml b/test/integration/targets/grafana_datasource/tasks/influx.yml new file mode 100644 index 00000000000..821ea07e186 --- /dev/null +++ b/test/integration/targets/grafana_datasource/tasks/influx.yml @@ -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" diff --git a/test/integration/targets/grafana_datasource/tasks/main.yml b/test/integration/targets/grafana_datasource/tasks/main.yml new file mode 100644 index 00000000000..73a1f60f059 --- /dev/null +++ b/test/integration/targets/grafana_datasource/tasks/main.yml @@ -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' diff --git a/test/integration/targets/grafana_datasource/tasks/postgres.yml b/test/integration/targets/grafana_datasource/tasks/postgres.yml new file mode 100644 index 00000000000..e540515e071 --- /dev/null +++ b/test/integration/targets/grafana_datasource/tasks/postgres.yml @@ -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" diff --git a/test/integration/targets/setup_grafana/files/grafana.repo b/test/integration/targets/setup_grafana/files/grafana.repo new file mode 100644 index 00000000000..f4b6f1f3f11 --- /dev/null +++ b/test/integration/targets/setup_grafana/files/grafana.repo @@ -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 diff --git a/test/integration/targets/setup_grafana/tasks/main.yml b/test/integration/targets/setup_grafana/tasks/main.yml new file mode 100644 index 00000000000..9ebe59b624a --- /dev/null +++ b/test/integration/targets/setup_grafana/tasks/main.yml @@ -0,0 +1,2 @@ +- include: setup.yml + when: ansible_distribution == 'Ubuntu' and ansible_distribution_release != 'trusty' diff --git a/test/integration/targets/setup_grafana/tasks/setup.yml b/test/integration/targets/setup_grafana/tasks/setup.yml new file mode 100644 index 00000000000..34e780bd233 --- /dev/null +++ b/test/integration/targets/setup_grafana/tasks/setup.yml @@ -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