Fix DC error messages for forbidden requests
The CLI error messages for users with reader role were not clear to the operator and this change fixes this. The problem was caused by an exception in string manipulation that was handled locally (the position "2" of the list of lines didn't exist, check file "base.py"). The error messages of DC CLI commands have either the format "<Explanation of why the operation failed> ERROR (app) Unable to <do operation X on subcloud Y>" or simply "ERROR (app) <Explanation of why the operation failed>". In the case of command "dcmanager subcloud reconfig", that uses the first format, the part where "<Explanation of why the operation failed>" was printed was missing, so a "print(exception)" was added (see "subcloud_manager.py" file, some other declarations of method "_get_resources" in the same file use this pattern). Test Plan: PASS: In a DC with this change present, create a new openstack user with reader role and through this user execute the commands: dcmanager subcloud list dcmanager subcloud manage subcloud1 dcmanager subcloud-group add --name test dcmanager subcloud reconfig --deploy-config file001 subcloud1 and check that the "subcloud list" command is executed without errors and that the error message of the other commands changes from "b'<html>\n <head>\n <title>403 Forbidden</title>\n </head>\n <body>\n <h1>403 Forbidden</h1>\n Access was denied to this resource.<br /><br />\n\n\n\n </body>\n</html>' ERROR (app) Unable to manage subcloud subcloud1", "ERROR (app) b'<html>\n <head>\n <title>403 Forbidden</title>\n </head> \n <body>\n <h1>403 Forbidden</h1>\n Access was denied to this resource.<br /><br />\n\n\n\n </body>\n</html>'" and "ERROR (app) Unable to reconfigure subcloud subcloud1" to "Access was denied to this resource. ERROR (app) Unable to manage subcloud subcloud1", "ERROR (app) Access was denied to this resource." and "Access was denied to this resource. ERROR (app) Unable to reconfigure subcloud subcloud1". Story: 2010149 Task: 46621 Signed-off-by: Joao Victor Portal <Joao.VictorPortal@windriver.com> Change-Id: I254813df075e49d2dece0667cc26b42fc3676a51
This commit is contained in:
parent
a18e4d367d
commit
e0d8e1fcc6
|
@ -130,11 +130,13 @@ class ResourceManager(object):
|
|||
error_html = resp.content
|
||||
soup = BeautifulSoup(error_html, 'html.parser')
|
||||
# Get the raw html with get_text, strip out the blank lines on
|
||||
# front and back, then get rid of the 2 lines of error code number
|
||||
# and error code explanation so that we are left with just the
|
||||
# meaningful error text.
|
||||
# front and back, then get rid of the first line of error code
|
||||
# so that we are left with just the meaningful error text.
|
||||
try:
|
||||
error_msg = soup.body.get_text().lstrip().rstrip().split('\n')[2]
|
||||
line_list = soup.body.get_text().lstrip().rstrip().split('\n')[1:]
|
||||
error_msg = line_list[0].lstrip().rstrip()
|
||||
for line in line_list[1:]:
|
||||
error_msg += ' ' + line.lstrip().rstrip()
|
||||
except Exception:
|
||||
error_msg = resp.content
|
||||
|
||||
|
|
|
@ -543,7 +543,8 @@ class ReconfigSubcloud(base.DCManagerShowOne):
|
|||
try:
|
||||
return dcmanager_client.subcloud_manager.reconfigure_subcloud(
|
||||
subcloud_ref=subcloud_ref, files=files, data=data)
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
print(e)
|
||||
error_msg = "Unable to reconfigure subcloud %s" % (subcloud_ref)
|
||||
raise exceptions.DCManagerClientException(error_msg)
|
||||
|
||||
|
|
Loading…
Reference in New Issue