Fix bug 713 82/7582/2
authorEduardo Sousa <eduardo.sousa@canonical.com>
Thu, 30 May 2019 17:32:20 +0000 (18:32 +0100)
committerEduardo Sousa <eduardo.sousa@canonical.com>
Fri, 31 May 2019 12:24:49 +0000 (13:24 +0100)
Change-Id: I2e6f9f31a20909282e40a13b70dd47cce993fd3a
Signed-off-by: Eduardo Sousa <eduardo.sousa@canonical.com>
osm_nbi/auth.py

index dda1d22..bb65738 100644 (file)
@@ -231,7 +231,12 @@ class Authenticator:
 
                 if self.config["authentication"]["backend"] != "internal" and \
                         role_with_operations["role"] != "anonymous":
-                    keystone_id = self.backend.create_role(role_with_operations["role"])
+                    keystone_id = [role for role in self.backend.get_role_list() 
+                                   if role["name"] == role_with_operations["role"]]
+                    if keystone_id:
+                        keystone_id = keystone_id[0]
+                    else:
+                        keystone_id = self.backend.create_role(role_with_operations["role"])
                     operation_to_roles_item["_id"] = keystone_id["_id"]
 
                 self.db.create("roles_operations", operation_to_roles_item)