TVD: fix project plugin OSC to display errors

The project plugin mapping used by the TVD plugin uses the openstack
client for configration by the admin user.
This patch catches the plugin exceptions to make sure the user sees
the error.

Change-Id: I8dce5e1daf2d0c4796c53e831b81462b27e8bc9c
This commit is contained in:
Adit Sarfaty 2018-04-15 08:55:53 +03:00
parent 9da1930583
commit 64e4050ed1

View File

@ -13,10 +13,14 @@
"""Project Plugin mapping action implementations""" """Project Plugin mapping action implementations"""
import six
from openstack import exceptions as os_exceptions
from openstack.network import network_service from openstack.network import network_service
from openstack import resource from openstack import resource
from openstackclient.i18n import _ from openstackclient.i18n import _
from osc_lib.command import command from osc_lib.command import command
from osc_lib import exceptions as osc_exceptions
from osc_lib import utils from osc_lib import utils
project_plugin_maps_path = "/project-plugin-maps" project_plugin_maps_path = "/project-plugin-maps"
@ -82,7 +86,13 @@ class CreateProjectPluginMap(command.ShowOne):
def take_action(self, parsed_args): def take_action(self, parsed_args):
client = self.app.client_manager.network client = self.app.client_manager.network
attrs = _get_attrs(parsed_args) attrs = _get_attrs(parsed_args)
obj = client._create(ProjectPluginMap, **attrs) try:
obj = client._create(ProjectPluginMap, **attrs)
except os_exceptions.HttpException as exc:
msg = _("Error while executing command: %s") % exc.message
if exc.details:
msg += ", " + six.text_type(exc.details)
raise osc_exceptions.CommandError(msg)
display_columns, columns = _get_columns(obj) display_columns, columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters={}) data = utils.get_item_properties(obj, columns, formatters={})
return (display_columns, data) return (display_columns, data)