From cdc1d5ada2283a742ee5946b54ac2f87efa5e431 Mon Sep 17 00:00:00 2001
From: Doug Szumski <doug@stackhpc.com>
Date: Sat, 28 Mar 2020 17:08:38 +0000
Subject: [PATCH] Fix loading of Monasca Grafana dashboards

This is a minimal fix to support loading dashboards into the Monasca
Grafana fork. It firstly aligns the default Monasca Grafana control
plane organisation and Monasca Grafana local admin username with Kolla
Ansible to make the feature easier to use. Secondly, it extracts the
associated OpenStack project name from this variable by stripping off
the OpenStack domain.

Longer term we may wish to move the dashboard loading functionality into
Kolla Ansible, now that it supports deploying Monasca.

Affects Rocky onwards.

Change-Id: I77c94edf654565a12ce8be681e3c9b16caa55c86
Story: 2007477
Task: 39186
---
 ansible/group_vars/all/grafana                |  4 ++--
 ansible/overcloud-grafana-configure.yml       | 22 +++++++++++++++----
 ...ana-dashboard-config-b81781cf10c2a236.yaml |  6 +++++
 3 files changed, 26 insertions(+), 6 deletions(-)
 create mode 100644 releasenotes/notes/bugfix-monasca-grafana-dashboard-config-b81781cf10c2a236.yaml

diff --git a/ansible/group_vars/all/grafana b/ansible/group_vars/all/grafana
index 6b60f786..38f37f31 100644
--- a/ansible/group_vars/all/grafana
+++ b/ansible/group_vars/all/grafana
@@ -4,7 +4,7 @@
 
 # Grafana local admin user name. If you are deploying Monasca Grafana this
 # should not conflict with an OpenStack user name.
-grafana_local_admin_user_name: "admin"
+grafana_local_admin_user_name: "grafana_local_admin"
 
 # Path to git repo containing Grafana dashboards. Eg.
 # https://github.com/stackhpc/grafana-reference-dashboards.git
@@ -23,7 +23,7 @@ grafana_monitoring_node_dashboard_repo_path:
 # The Grafana organisation for the control plane. Note that for Monasca
 # Grafana with domain support the format is:
 # organisation_name@openstack_domain
-grafana_control_plane_organisation: "control_plane"
+grafana_control_plane_organisation: "monasca_control_plane@default"
 
 # A dict of datasources to configure. See the stackhpc.grafana-conf role
 # for all supported datasources. Example:
diff --git a/ansible/overcloud-grafana-configure.yml b/ansible/overcloud-grafana-configure.yml
index 5fd9cddc..b4794dbf 100644
--- a/ansible/overcloud-grafana-configure.yml
+++ b/ansible/overcloud-grafana-configure.yml
@@ -1,12 +1,12 @@
 ---
-- name: Check whether Grafana is enabled
+- name: Check whether Monasca is enabled
   hosts: overcloud
   tags:
     - grafana
   tasks:
     - name: Create monitoring group with grafana enabled
       group_by:
-        key: "monitoring_with_grafana_enabled_{{ kolla_enable_grafana | bool }}"
+        key: "monitoring_with_grafana_enabled_{{ kolla_enable_monasca | bool }}"
 
 - name: Set the Monasca control plane project ID
   hosts: monitoring_with_grafana_enabled_True[0]
@@ -15,6 +15,20 @@
     - grafana
   vars:
     venv: "{{ virtualenv_path }}/openstacksdk"
+  pre_tasks:
+    - name: Validate OpenStack password authentication parameters
+      fail:
+        msg: >
+          Required OpenStack authentication parameter {{ item }} is
+          {% if item in openstack_auth %}empty{% else %}not present{% endif %}
+          in openstack_auth. Have you sourced the environment file?
+      when:
+        - openstack_auth_type == 'password'
+        - item not in openstack_auth or not openstack_auth[item]
+      with_items: "{{ openstack_auth_password_required_params }}"
+      tags:
+        - config-validation
+
   roles:
     - role: stackhpc.os-openstackclient
       os_openstackclient_venv: "{{ venv }}"
@@ -27,7 +41,7 @@
     - name: Look up Monasca control plane project ID
       shell: >
         source {{ venv }}/bin/activate &&
-        openstack project show monasca --format json --column id
+        openstack project show {{ grafana_control_plane_organisation.split("@")[0] }} --format json --column id
       register: monasca_project_show
       changed_when: False
       environment: "{{ openstack_auth_env }}"
@@ -61,7 +75,7 @@
     - role: stackhpc.grafana-conf
       grafana_conf_organisation: "{{ grafana_control_plane_organisation }}"
       grafana_conf_grafana_admin_user: "{{ grafana_local_admin_user_name }}"
-      grafana_conf_grafana_admin_pass: "{{ grafana_admin_password }}"
+      grafana_conf_grafana_admin_pass: "{{ monasca_grafana_admin_password }}"
       grafana_conf_grafana_dashboard_repo:
         repo: "{{ grafana_monitoring_node_dashboard_repo }}"
         version: "{{ grafana_monitoring_node_dashboard_repo_version }}"
diff --git a/releasenotes/notes/bugfix-monasca-grafana-dashboard-config-b81781cf10c2a236.yaml b/releasenotes/notes/bugfix-monasca-grafana-dashboard-config-b81781cf10c2a236.yaml
new file mode 100644
index 00000000..cc0ea9bd
--- /dev/null
+++ b/releasenotes/notes/bugfix-monasca-grafana-dashboard-config-b81781cf10c2a236.yaml
@@ -0,0 +1,6 @@
+---
+fixes:
+  - |
+    Fixes an issue where it was not possible to load dashboards into the
+    Monasca Grafana fork when the default Monasca control plane OpenStack
+    project name is used from Kolla Ansible.
-- 
GitLab