From: K Sai Kiran Date: Wed, 27 May 2020 11:00:10 +0000 (+0530) Subject: Bug 1078 fixed by using try block for user update X-Git-Tag: release-v8.0-start~11 X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=commitdiff_plain;h=974276d1b4e7fe9cf177702eb6d657aa42618a41;hp=f00430d3af1d7bb8780862a074474344084b6154 Bug 1078 fixed by using try block for user update Following the documentation of LDAP in devops repo, the user profiles are read only. Try Except block resolves the issue. Raise error to NBI when change for username/password is requested. Change-Id: Id5919af575ec7cd128424fc53f7365d6cd4c29a7 Signed-off-by: K Sai Kiran --- diff --git a/osm_nbi/authconn_keystone.py b/osm_nbi/authconn_keystone.py index 408b72f..05f803a 100644 --- a/osm_nbi/authconn_keystone.py +++ b/osm_nbi/authconn_keystone.py @@ -345,8 +345,14 @@ class AuthconnKeystone(Authconn): or user_info.get("add_project_role_mappings") or user_info.get("remove_project_role_mappings"): # if user_index>0, it is an external domain, that should not be updated ctime = user_obj._admin.get("created", 0) if hasattr(user_obj, "_admin") else 0 - self.keystone.users.update(user_id, password=user_info.get("password"), name=user_info.get("username"), - _admin={"created": ctime, "modified": time.time()}) + try: + self.keystone.users.update(user_id, password=user_info.get("password"), + name=user_info.get("username"), + _admin={"created": ctime, "modified": time.time()}) + except Exception as e: + if user_info.get("username") or user_info.get("password"): + raise AuthconnOperationException("Error during username/password change: {}".format(str(e))) + self.logger.error("Error during updating user profile: {}".format(str(e))) for mapping in user_info.get("remove_project_role_mappings", []): self.remove_role_from_user(user_obj, mapping["project"], mapping["role"])