bug(keystone): dashboards for projects saved in keystone instead of mongoDB. Bug... 89/10289/1
authorbravof <fbravo@whitestack.com>
Thu, 28 Jan 2021 00:22:19 +0000 (21:22 -0300)
committerpalsus <subhankar.pal@aricent.com>
Thu, 11 Feb 2021 06:34:05 +0000 (07:34 +0100)
Change-Id: I5faa44c7fe443813705efce625f0bb15b8250853
Signed-off-by: bravof <fbravo@whitestack.com>
(cherry picked from commit 2fe71f21fe75ee283d39e66391d7d3a094713569)

docker/Dockerfile
osm_mon/core/keystone.py [new file with mode: 0644]
osm_mon/core/mon.yaml
osm_mon/dashboarder/dashboarder.py
osm_mon/dashboarder/service.py
requirements.txt
setup.py

index e9d355d..c22058b 100644 (file)
@@ -58,6 +58,7 @@ ENV OSMMON_GRAFANA_URL http://grafana:3000
 ENV OSMMON_GRAFANA_USER admin
 ENV OSMMON_GRAFANA_PASSWORD admin
 
+
 EXPOSE 8000
 
 HEALTHCHECK --interval=5s --timeout=2s --retries=12 \
diff --git a/osm_mon/core/keystone.py b/osm_mon/core/keystone.py
new file mode 100644 (file)
index 0000000..d79ea89
--- /dev/null
@@ -0,0 +1,58 @@
+# -*- coding: utf-8 -*-
+
+# Copyright 2021 Whitestack, LLC
+# *************************************************************
+
+# This file is part of OSM Monitoring module
+# All Rights Reserved to Whitestack, LLC
+
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+
+#         http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: fbravo@whitestack.com
+##
+
+from keystoneauth1.identity import v3
+from keystoneauth1 import session
+from keystoneclient.v3 import client
+
+
+class KeystoneConnection:
+    """
+    Object representing a connection with keystone, it's main use is to collect
+    projects and users from the OSM platform stored in keystone instead MongoDB
+    """
+    def __init__(self, config):
+        self.auth_url = config.get('keystone', 'url')
+        self.username = config.get('keystone', 'service_user')
+        self.project_name = config.get('keystone', 'service_project')
+        self.project_domain_name_list = config.get('keystone', 'service_project_domain_name').split(",")
+        self.password = config.get('keystone', 'service_password')
+        self.user_domain_name_list = config.get('keystone', 'domain_name').split(",")
+
+        self.auth = v3.Password(
+            auth_url=self.auth_url,
+            user_domain_name=self.user_domain_name_list[0],
+            username=self.username,
+            password=self.password,
+            project_domain_name=self.project_domain_name_list[0],
+            project_name=self.project_name
+        )
+
+        self.keystone_session = session.Session(auth=self.auth)
+        self.keystone_client = client.Client(session=self.keystone_session, endpoint_override=self.auth_url)
+
+    def getProjects(self):
+        """
+        Grabs projects from keystone using the client and session build in the constructor
+        """
+        return self.keystone_client.projects.list()
index 321e485..2ce2fc1 100644 (file)
@@ -65,3 +65,12 @@ vca:
   secret: secret
   user: admin
   cacert: cacert
+
+keystone:
+  enabled: false
+  url: http://keystone:5000/v3
+  domain_name: default
+  service_project: service
+  service_user: nbi
+  service_password: apassword
+  service_project_domain_name: default
index 22aa1bf..a6ff5bc 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 
-# Copyright 2018 Whitestack, LLC
+# Copyright 2021 Whitestack, LLC
 # *************************************************************
 
 # This file is part of OSM Monitoring module
@@ -18,8 +18,9 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 # For those usages not covered by the Apache License, Version 2.0 please
-# contact: bdiaz@whitestack.com or glavado@whitestack.com
+# contact: fbravo@whitestack.com or glavado@whitestack.com
 ##
+
 import logging
 import time
 import socket
@@ -99,4 +100,4 @@ class Dashboarder:
 
     def create_dashboards(self):
         self.service.create_dashboards()
-        log.debug('I just called the dashboarder service!')
+        log.debug('Dashboarder Service > create_dashboards called!')
index 3f83550..32128c2 100644 (file)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 
-# Copyright 2018 Whitestack, LLC
+# Copyright 2021 Whitestack, LLC
 # *************************************************************
 
 # This file is part of OSM Monitoring module
@@ -24,6 +24,7 @@ import logging
 
 from osm_mon.core.common_db import CommonDbClient
 from osm_mon.core.config import Config
+from osm_mon.core.keystone import KeystoneConnection
 from osm_mon.dashboarder.backends.grafana import GrafanaBackend
 from osm_mon import __path__ as mon_path
 from osm_mon.dashboarder.utils import find_in_list
@@ -37,14 +38,29 @@ class DashboarderService:
         self.common_db = CommonDbClient(self.conf)
         self.grafana = GrafanaBackend(self.conf)
 
+        if bool(self.conf.get('keystone', 'enabled')):
+            self.keystone = KeystoneConnection(self.conf)
+        else:
+            self.keystone = None
+
     def create_dashboards(self):
         # TODO lavado: migrate these methods to mongo change streams
         # Lists all dashboards and OSM resources for later comparisons
         dashboard_uids = self.grafana.get_all_dashboard_uids()
         osm_resource_uids = []
+        projects = []
+
+        # Check if keystone is the auth/projects backend and get projects from there
+        if self.keystone:
+            try:
+                projects.extend(
+                    map(lambda project: {'_id': project.id, 'name': project.name}, self.keystone.getProjects())
+                )
+            except Exception:
+                log.error('Cannot retrieve projects from keystone')
 
         # Reads existing project list and creates a dashboard for each
-        projects = self.common_db.get_projects()
+        projects.extend(self.common_db.get_projects())
         for project in projects:
             project_id = project['_id']
             # Collect Project IDs for periodical dashboard clean-up
index eab965e..b2e7aa5 100644 (file)
@@ -23,7 +23,7 @@ lxml==4.6.2
 humanfriendly==9.0.*
 aiokafka==0.6.0
 requests==2.25.*
-python-keystoneclient==3.15.*
+python-keystoneclient==4.2.0
 six==1.15.0
 pyyaml>=5.1.2
 prometheus_client==0.4.*
index dfe455e..4377e45 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -53,7 +53,7 @@ setup(
     install_requires=[
         "aiokafka==0.6.0",
         "requests==2.25.*",
-        "python-keystoneclient==3.15.*",
+        "python-keystoneclient==4.2.0",
         "six",
         "pyyaml>=5.1.2",
         "prometheus_client==0.4.*",