From 1d033f9053a12ed4d5406d38a768009c9a109397 Mon Sep 17 00:00:00 2001 From: Hiroo Kitamura Date: Mon, 1 Jun 2020 09:57:28 +0900 Subject: [PATCH] Fix exception message Fix some exception messages because some exception messages are not outputed as expected. In addition, the codes that seems to improve readability by explicitly specifying the arguments are also modified. Change-Id: I425d15ea9f5a3d0b6132ffd03cb577e583239c3a Closes-Bug: #1881510 --- tackerclient/common/utils.py | 2 +- tackerclient/common/validators.py | 6 ++--- tackerclient/osc/v1/nfvo/ns.py | 12 +++++----- tackerclient/osc/v1/nfvo/nsd.py | 8 +++---- tackerclient/osc/v1/nfvo/vim.py | 6 ++--- tackerclient/osc/v1/nfvo/vnffg.py | 22 +++++++++++-------- tackerclient/osc/v1/nfvo/vnffgd.py | 9 ++++---- tackerclient/osc/v1/vnflcm/vnflcm.py | 17 ++++++++------ tackerclient/osc/v1/vnfm/vnf.py | 14 +++++++----- tackerclient/osc/v1/vnfm/vnfd.py | 8 +++---- tackerclient/osc/v1/vnfpkgm/vnf_package.py | 2 +- tackerclient/tacker/client.py | 6 ++--- tackerclient/tacker/v1_0/__init__.py | 16 +++++++++----- tackerclient/tacker/v1_0/nfvo/ns.py | 6 ++--- tackerclient/tacker/v1_0/nfvo/vim.py | 4 ++-- tackerclient/tacker/v1_0/nfvo/vnffg.py | 12 +++++----- tackerclient/tacker/v1_0/vnfm/vnf.py | 6 ++--- tackerclient/tacker/v1_0/vnfm/vnfd.py | 6 ++--- tackerclient/tests/unit/osc/v1/test_vnflcm.py | 9 ++++---- 19 files changed, 94 insertions(+), 77 deletions(-) diff --git a/tackerclient/common/utils.py b/tackerclient/common/utils.py index fb62cf5f..e4cd8e27 100644 --- a/tackerclient/common/utils.py +++ b/tackerclient/common/utils.py @@ -57,7 +57,7 @@ def get_client_class(api_name, version, version_map): "one of: %(map_keys)s") msg = msg % {'api_name': api_name, 'version': version, 'map_keys': ', '.join(version_map.keys())} - raise exceptions.UnsupportedVersion(msg) + raise exceptions.UnsupportedVersion(message=msg) return importutils.import_class(client_path) diff --git a/tackerclient/common/validators.py b/tackerclient/common/validators.py index 39964dbb..4b7fa4b7 100644 --- a/tackerclient/common/validators.py +++ b/tackerclient/common/validators.py @@ -54,7 +54,7 @@ def validate_int_range(parsed_args, attr_name, min_value=None, max_value=None): {'attr_name': attr_name.replace('_', '-'), 'val': val}) - raise exceptions.CommandError(msg) + raise exceptions.CommandError(message=msg) def validate_ip_subnet(parsed_args, attr_name): @@ -65,5 +65,5 @@ def validate_ip_subnet(parsed_args, attr_name): netaddr.IPNetwork(val) except (netaddr.AddrFormatError, ValueError): raise exceptions.CommandError( - (_('%(attr_name)s "%(val)s" is not a valid CIDR.') % - {'attr_name': attr_name.replace('_', '-'), 'val': val})) + message=(_('%(attr_name)s "%(val)s" is not a valid CIDR.') % + {'attr_name': attr_name.replace('_', '-'), 'val': val})) diff --git a/tackerclient/osc/v1/nfvo/ns.py b/tackerclient/osc/v1/nfvo/ns.py index b3ad3663..7ce2c92d 100644 --- a/tackerclient/osc/v1/nfvo/ns.py +++ b/tackerclient/osc/v1/nfvo/ns.py @@ -109,9 +109,10 @@ class CreateNS(command.ShowOne): template = yaml.load( template, Loader=yaml.SafeLoader) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) if not template: - raise exceptions.InvalidInput('The nsd file is empty') + raise exceptions.InvalidInput( + reason='The nsd file is empty') body[_NS]['nsd_template'] = template if parsed_args.param_file: @@ -121,9 +122,10 @@ class CreateNS(command.ShowOne): param_yaml = yaml.load( param_yaml, Loader=yaml.SafeLoader) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) if not param_yaml: - raise exceptions.InvalidInput('The parameter file is empty') + raise exceptions.InvalidInput( + reason='The parameter file is empty') body[_NS]['attributes'] = {'param_values': param_yaml} tackerV10.update_dict(parsed_args, body[_NS], ['tenant_id', 'name', 'description', @@ -200,7 +202,7 @@ class DeleteNS(command.Command): % {'failed_id': failed_id, 'error': error}) msg += err_msg - raise exceptions.CommandError(msg) + raise exceptions.CommandError(message=msg) else: print((_('All specified %(resource)s(s) deleted successfully') % {'resource': _NS})) diff --git a/tackerclient/osc/v1/nfvo/nsd.py b/tackerclient/osc/v1/nfvo/nsd.py index 2ce22a23..dccc26e7 100644 --- a/tackerclient/osc/v1/nfvo/nsd.py +++ b/tackerclient/osc/v1/nfvo/nsd.py @@ -71,15 +71,15 @@ class CreateNSD(command.ShowOne): body = {_NSD: {}} nsd = None if not parsed_args.nsd_file: - raise exceptions.InvalidInput("Invalid input for nsd file") + raise exceptions.InvalidInput(reason="Invalid input for nsd file") with open(parsed_args.nsd_file) as f: nsd = f.read() try: nsd = yaml.load(nsd, Loader=yaml.SafeLoader) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) if not nsd: - raise exceptions.InvalidInput("nsd file is empty") + raise exceptions.InvalidInput(reason="nsd file is empty") body[_NSD]['attributes'] = {'nsd': nsd} tackerV10.update_dict(parsed_args, body[_NSD], ['tenant_id', 'name', 'description']) @@ -138,7 +138,7 @@ class DeleteNSD(command.Command): % {'failed_id': failed_id, 'error': error}) msg += err_msg - raise exceptions.CommandError(msg) + raise exceptions.CommandError(message=msg) else: print((_('All specified %(resource)s(s) deleted successfully') % {'resource': _NSD})) diff --git a/tackerclient/osc/v1/nfvo/vim.py b/tackerclient/osc/v1/nfvo/vim.py index aa0ba072..c1c64113 100644 --- a/tackerclient/osc/v1/nfvo/vim.py +++ b/tackerclient/osc/v1/nfvo/vim.py @@ -124,7 +124,7 @@ class CreateVIM(command.ShowOne): config_param = yaml.load(vim_config, Loader=yaml.SafeLoader) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) vim_obj = body[_VIM] try: auth_url = config_param.pop('auth_url') @@ -190,7 +190,7 @@ class DeleteVIM(command.Command): % {'failed_id': failed_id, 'error': error}) msg += err_msg - raise exceptions.CommandError(msg) + raise exceptions.CommandError(message=msg) else: print((_('All specified %(resource)s(s) deleted successfully') % {'resource': _VIM})) @@ -232,7 +232,7 @@ class UpdateVIM(command.ShowOne): try: config_param = yaml.load(config_yaml) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) vim_obj = body[_VIM] if config_param is not None: vim_utils.args2body_vim(config_param, vim_obj) diff --git a/tackerclient/osc/v1/nfvo/vnffg.py b/tackerclient/osc/v1/nfvo/vnffg.py index f0060dc1..72dec716 100644 --- a/tackerclient/osc/v1/nfvo/vnffg.py +++ b/tackerclient/osc/v1/nfvo/vnffg.py @@ -145,9 +145,10 @@ class CreateVNFFG(command.ShowOne): try: template = yaml.load(template, Loader=yaml.SafeLoader) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) if not template: - raise exceptions.InvalidInput('The vnffgd file is empty') + raise exceptions.InvalidInput( + reason='The vnffgd file is empty') body[_VNFFG]['vnffgd_template'] = template if parsed_args.param_file: @@ -157,9 +158,10 @@ class CreateVNFFG(command.ShowOne): param_yaml = yaml.load( param_yaml, Loader=yaml.SafeLoader) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) if not param_yaml: - raise exceptions.InvalidInput('The parameter file is empty') + raise exceptions.InvalidInput( + reason='The parameter file is empty') body[_VNFFG]['attributes'] = {'param_values': param_yaml} tackerV10.update_dict(parsed_args, body[_VNFFG], ['tenant_id', 'name', 'vnffgd_id', @@ -218,7 +220,7 @@ class DeleteVNFFG(command.Command): % {'failed_id': failed_id, 'error': error}) msg += err_msg - raise exceptions.CommandError(msg) + raise exceptions.CommandError(message=msg) else: print((_('All specified %(resource)s(s) deleted successfully') % {'resource': _VNFFG})) @@ -274,9 +276,10 @@ class UpdateVNFFG(command.ShowOne): template = yaml.load( template, Loader=yaml.SafeLoader) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) if not template: - raise exceptions.InvalidInput('The vnffgd file is empty') + raise exceptions.InvalidInput( + reason='The vnffgd file is empty') body[_VNFFG]['vnffgd_template'] = template if parsed_args.param_file: @@ -286,9 +289,10 @@ class UpdateVNFFG(command.ShowOne): param_yaml = yaml.load( param_yaml, Loader=yaml.SafeLoader) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) if not param_yaml: - raise exceptions.InvalidInput('The parameter file is empty') + raise exceptions.InvalidInput( + reason='The parameter file is empty') body[_VNFFG]['attributes'] = {'param_values': param_yaml} tackerV10.update_dict(parsed_args, body[self.resource], ['vnf_mapping', 'symmetrical', 'description']) diff --git a/tackerclient/osc/v1/nfvo/vnffgd.py b/tackerclient/osc/v1/nfvo/vnffgd.py index 6a76d529..f12ec83f 100644 --- a/tackerclient/osc/v1/nfvo/vnffgd.py +++ b/tackerclient/osc/v1/nfvo/vnffgd.py @@ -71,15 +71,16 @@ class CreateVNFFGD(command.ShowOne): body = {_VNFFGD: {}} vnffgd = None if not parsed_args.vnffgd_file: - raise exceptions.InvalidInput("Invalid input for vnffgd file") + raise exceptions.InvalidInput( + reason="Invalid input for vnffgd file") with open(parsed_args.vnffgd_file) as f: vnffgd = f.read() try: vnffgd = yaml.load(vnffgd, Loader=yaml.SafeLoader) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) if not vnffgd: - raise exceptions.InvalidInput("vnffgd file is empty") + raise exceptions.InvalidInput(reason="vnffgd file is empty") body[_VNFFGD]['template'] = {'vnffgd': vnffgd} tackerV10.update_dict(parsed_args, body[_VNFFGD], ['tenant_id', 'name', 'description']) @@ -136,7 +137,7 @@ class DeleteVNFFGD(command.Command): % {'failed_id': failed_id, 'error': error}) msg += err_msg - raise exceptions.CommandError(msg) + raise exceptions.CommandError(message=msg) else: print((_('All specified %(resource)s(s) deleted successfully') % {'resource': _VNFFGD})) diff --git a/tackerclient/osc/v1/vnflcm/vnflcm.py b/tackerclient/osc/v1/vnflcm/vnflcm.py index 049a9ecb..c4afc3c4 100644 --- a/tackerclient/osc/v1/vnflcm/vnflcm.py +++ b/tackerclient/osc/v1/vnflcm/vnflcm.py @@ -187,17 +187,20 @@ def instantiate_vnf_args2body(file_path): if file_path is not None and os.access(file_path, os.R_OK) is False: msg = _("File %s does not exist or user does not have read " "privileges to it") - raise exceptions.InvalidInput(msg % file_path) + reason = msg % file_path + raise exceptions.InvalidInput(reason=reason) try: with open(file_path) as f: body = json.load(f) except (IOError, ValueError) as ex: msg = _("Failed to load parameter file. Error: %s") - raise exceptions.InvalidInput(msg % ex) + reason = msg % ex + raise exceptions.InvalidInput(reason=reason) if not body: - raise exceptions.InvalidInput(_('The parameter file is empty')) + reason = _('The parameter file is empty') + raise exceptions.InvalidInput(reason=reason) return body @@ -304,7 +307,7 @@ class TerminateVnfLcm(command.Command): if parsed_args.graceful_termination_timeout: if parsed_args.termination_type == 'FORCEFUL': - exceptions.InvalidInput('--graceful-termination-timeout' + exceptions.InvalidInput(reason='--graceful-termination-timeout' ' argument is invalid for "FORCEFUL"' ' termination') body['gracefulTerminationTimeout'] = parsed_args.\ @@ -355,8 +358,8 @@ class TerminateVnfLcm(command.Command): msg = _("Couldn't verify vnf instance is terminated within " "'%(timeout)s' seconds. Unable to delete vnf instance " "%(id)s") - raise exceptions.CommandError(msg % {'timeout': timeout, - 'id': vnf_instance_id}) + raise exceptions.CommandError( + message=msg % {'timeout': timeout, 'id': vnf_instance_id}) time.sleep(SLEEP_TIME) @@ -396,7 +399,7 @@ class DeleteVnfLcm(command.Command): msg = (_("Failed to delete %(error_count)s of %(total)s " "vnf instances.") % {'error_count': error_count, 'total': total}) - raise exceptions.CommandError(msg) + raise exceptions.CommandError(message=msg) else: if total > 1: print(_('All specified vnf instances are deleted ' diff --git a/tackerclient/osc/v1/vnfm/vnf.py b/tackerclient/osc/v1/vnfm/vnf.py index 71859a4b..7173cbe7 100644 --- a/tackerclient/osc/v1/vnfm/vnf.py +++ b/tackerclient/osc/v1/vnfm/vnf.py @@ -120,7 +120,7 @@ class CreateVNF(command.ShowOne): config = yaml.load( config_yaml, Loader=yaml.SafeLoader) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) if config: body[_VNF]['attributes'] = {'config': config} @@ -146,9 +146,10 @@ class CreateVNF(command.ShowOne): template = yaml.load( template, Loader=yaml.SafeLoader) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) if not template: - raise exceptions.InvalidInput('The vnfd file is empty') + raise exceptions.InvalidInput( + reason='The vnfd file is empty') body[_VNF]['vnfd_template'] = template if parsed_args.param_file: @@ -158,9 +159,10 @@ class CreateVNF(command.ShowOne): param_yaml = yaml.load( param_yaml, Loader=yaml.SafeLoader) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) if not param_yaml: - raise exceptions.InvalidInput('The parameter file is empty') + raise exceptions.InvalidInput( + reason='The parameter file is empty') body[_VNF]['attributes'] = {'param_values': param_yaml} tackerV10.update_dict(parsed_args, body[_VNF], ['tenant_id', 'name', 'description', @@ -234,7 +236,7 @@ class DeleteVNF(command.Command): % {'failed_id': failed_id, 'error': error}) msg += err_msg - raise exceptions.CommandError(msg) + raise exceptions.CommandError(message=msg) else: print((_('All specified %(resource)s(s) deleted successfully') % {'resource': _VNF})) diff --git a/tackerclient/osc/v1/vnfm/vnfd.py b/tackerclient/osc/v1/vnfm/vnfd.py index cbbcbd9f..704061e0 100644 --- a/tackerclient/osc/v1/vnfm/vnfd.py +++ b/tackerclient/osc/v1/vnfm/vnfd.py @@ -71,16 +71,16 @@ class CreateVNFD(command.ShowOne): body = {_VNFD: {}} vnfd = None if not parsed_args.vnfd_file: - raise exceptions.InvalidInput("Invalid input for vnfd file") + raise exceptions.InvalidInput(reason="Invalid input for vnfd file") with open(parsed_args.vnfd_file) as f: vnfd = f.read() try: vnfd = yaml.load(vnfd, Loader=yaml.SafeLoader) except yaml.YAMLError as e: msg = _("yaml failed to load vnfd file. %s") % e - raise exceptions.InvalidInput(msg) + raise exceptions.InvalidInput(reason=msg) if not vnfd: - raise exceptions.InvalidInput("vnfd file is empty") + raise exceptions.InvalidInput(reason="vnfd file is empty") body[_VNFD]['attributes'] = {'vnfd': vnfd} tackerV10.update_dict(parsed_args, body[_VNFD], ['tenant_id', 'name', 'description']) @@ -139,7 +139,7 @@ class DeleteVNFD(command.Command): % {'failed_id': failed_id, 'error': error}) msg += err_msg - raise exceptions.CommandError(msg) + raise exceptions.CommandError(message=msg) else: print((_('All specified %(resource)s(s) deleted successfully') % {'resource': _VNFD})) diff --git a/tackerclient/osc/v1/vnfpkgm/vnf_package.py b/tackerclient/osc/v1/vnfpkgm/vnf_package.py index 77af1cf6..f8891c75 100644 --- a/tackerclient/osc/v1/vnfpkgm/vnf_package.py +++ b/tackerclient/osc/v1/vnfpkgm/vnf_package.py @@ -343,7 +343,7 @@ class DeleteVnfPackage(command.Command): % {'failed_id': failed_id, 'error': error}) msg += err_msg - raise exceptions.CommandError(msg) + raise exceptions.CommandError(message=msg) else: print((_('All specified %(resource)s(s) deleted successfully') % {'resource': self.resource})) diff --git a/tackerclient/tacker/client.py b/tackerclient/tacker/client.py index 8443eb15..8efbba7a 100644 --- a/tackerclient/tacker/client.py +++ b/tackerclient/tacker/client.py @@ -54,9 +54,9 @@ def make_client(instance): auth=instance._auth) return client else: - raise exceptions.UnsupportedVersion(_("API version %s is not " - "supported") % - instance._api_version[API_NAME]) + raise exceptions.UnsupportedVersion( + reason=_("API version %s is not supported") % + instance._api_version[API_NAME]) def Client(api_version, *args, **kwargs): diff --git a/tackerclient/tacker/v1_0/__init__.py b/tackerclient/tacker/v1_0/__init__.py index a16e71dc..6064def8 100644 --- a/tackerclient/tacker/v1_0/__init__.py +++ b/tackerclient/tacker/v1_0/__init__.py @@ -166,7 +166,7 @@ def _process_previous_argument(current_arg, _value_number, current_type_str, if _value_number == 0 and (current_type_str or _list_flag): # This kind of argument should have value raise exceptions.CommandError( - _("Invalid values_specs %s") % ' '.join(values_specs)) + message=_("Invalid values_specs %s") % ' '.join(values_specs)) if _value_number > 1 or _list_flag or current_type_str == 'list': current_arg.update({'nargs': '+'}) elif _value_number == 0: @@ -237,7 +237,8 @@ def parse_args_to_dict(values_specs): _value_number = 0 if _item in _options: raise exceptions.CommandError( - _("Duplicated options %s") % ' '.join(values_specs)) + message=_("Duplicated " + "options %s") % ' '.join(values_specs)) else: _options.update({_item: {}}) current_arg = _options[_item] @@ -245,7 +246,8 @@ def parse_args_to_dict(values_specs): elif _item.startswith('type='): if current_arg is None: raise exceptions.CommandError( - _("Invalid values_specs %s") % ' '.join(values_specs)) + message=_("Invalid " + "values_specs %s") % ' '.join(values_specs)) if 'type' not in current_arg: current_type_str = _item.split('=', 2)[1] current_arg.update({'type': eval(current_type_str)}) @@ -267,7 +269,8 @@ def parse_args_to_dict(values_specs): if (not current_item or '=' in current_item or _item.startswith('-') and not is_number(_item)): raise exceptions.CommandError( - _("Invalid values_specs %s") % ' '.join(values_specs)) + message=_("Invalid " + "values_specs %s") % ' '.join(values_specs)) _value_number += 1 _values_specs.append(_item) @@ -484,7 +487,8 @@ class UpdateCommand(TackerCommand): body[self.resource] = _extra_values if not body[self.resource]: raise exceptions.CommandError( - _("Must specify new values to update %s") % self.resource) + message=_("Must specify new" + " values to update %s") % self.resource) if self.allow_names: _id = find_resourceid_by_name_or_id( tacker_client, self.resource, parsed_args.id) @@ -565,7 +569,7 @@ class DeleteCommand(TackerCommand): % {'failed_id': failed_id, 'error': error}) msg += err_msg - raise exceptions.CommandError(msg) + raise exceptions.CommandError(message=msg) else: print((_('All specified %(resource)s(s) %(msg)s successfully') % {'msg': self.deleted_msg.get(self.resource, 'deleted'), diff --git a/tackerclient/tacker/v1_0/nfvo/ns.py b/tackerclient/tacker/v1_0/nfvo/ns.py index 90dbd660..0c68607e 100644 --- a/tackerclient/tacker/v1_0/nfvo/ns.py +++ b/tackerclient/tacker/v1_0/nfvo/ns.py @@ -100,9 +100,9 @@ class CreateNS(tackerV10.CreateCommand): args['nsd_template'] = yaml.load( template, Loader=yaml.SafeLoader) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) if not args['nsd_template']: - raise exceptions.InvalidInput('The nsd file is empty') + raise exceptions.InvalidInput(reason='The nsd file is empty') if parsed_args.param_file: with open(parsed_args.param_file) as f: @@ -111,7 +111,7 @@ class CreateNS(tackerV10.CreateCommand): args['attributes']['param_values'] = yaml.load( param_yaml, Loader=yaml.SafeLoader) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) tackerV10.update_dict(parsed_args, body[self.resource], ['tenant_id', 'name', 'description', 'nsd_id', 'vim_id']) diff --git a/tackerclient/tacker/v1_0/nfvo/vim.py b/tackerclient/tacker/v1_0/nfvo/vim.py index 0f924b83..949e2050 100644 --- a/tackerclient/tacker/v1_0/nfvo/vim.py +++ b/tackerclient/tacker/v1_0/nfvo/vim.py @@ -71,7 +71,7 @@ class CreateVIM(tackerV10.CreateCommand): config_param = yaml.load(vim_config, Loader=yaml.SafeLoader) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) vim_obj = body[self.resource] try: auth_url = config_param.pop('auth_url') @@ -119,7 +119,7 @@ class UpdateVIM(tackerV10.UpdateCommand): try: config_param = yaml.load(config_yaml) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) vim_obj = body[self.resource] if config_param is not None: vim_utils.args2body_vim(config_param, vim_obj) diff --git a/tackerclient/tacker/v1_0/nfvo/vnffg.py b/tackerclient/tacker/v1_0/nfvo/vnffg.py index b07f9de9..efbe2a58 100644 --- a/tackerclient/tacker/v1_0/nfvo/vnffg.py +++ b/tackerclient/tacker/v1_0/nfvo/vnffg.py @@ -153,9 +153,10 @@ class CreateVNFFG(tackerV10.CreateCommand): args['vnffgd_template'] = yaml.load( template, Loader=yaml.SafeLoader) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) if not args['vnffgd_template']: - raise exceptions.InvalidInput('The vnffgd file is empty') + raise exceptions.InvalidInput( + reason='The vnffgd file is empty') if parsed_args.param_file: with open(parsed_args.param_file) as f: @@ -164,7 +165,7 @@ class CreateVNFFG(tackerV10.CreateCommand): args['attributes']['param_values'] = yaml.load( param_yaml, Loader=yaml.SafeLoader) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) tackerV10.update_dict(parsed_args, body[self.resource], ['tenant_id', 'name', 'vnffgd_id', @@ -217,9 +218,10 @@ class UpdateVNFFG(tackerV10.UpdateCommand): args['vnffgd_template'] = yaml.load( template, Loader=yaml.SafeLoader) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) if not args['vnffgd_template']: - raise exceptions.InvalidInput('The vnffgd template is empty') + raise exceptions.InvalidInput( + reason='The vnffgd template is empty') tackerV10.update_dict(parsed_args, body[self.resource], ['tenant_id', 'vnf_mapping', 'symmetrical']) diff --git a/tackerclient/tacker/v1_0/vnfm/vnf.py b/tackerclient/tacker/v1_0/vnfm/vnf.py index 855acceb..4f7bfdb1 100644 --- a/tackerclient/tacker/v1_0/vnfm/vnf.py +++ b/tackerclient/tacker/v1_0/vnfm/vnf.py @@ -94,7 +94,7 @@ class CreateVNF(tackerV10.CreateCommand): config = yaml.load( config_yaml, Loader=yaml.SafeLoader) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) if config: args['attributes']['config'] = config @@ -123,7 +123,7 @@ class CreateVNF(tackerV10.CreateCommand): args['vnfd_template'] = yaml.load( template, Loader=yaml.SafeLoader) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) if parsed_args.param_file: with open(parsed_args.param_file) as f: @@ -132,7 +132,7 @@ class CreateVNF(tackerV10.CreateCommand): args['attributes']['param_values'] = yaml.load( param_yaml, Loader=yaml.SafeLoader) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) tackerV10.update_dict(parsed_args, body[self.resource], ['tenant_id', 'name', 'description', 'vnfd_id', 'vim_id']) diff --git a/tackerclient/tacker/v1_0/vnfm/vnfd.py b/tackerclient/tacker/v1_0/vnfm/vnfd.py index 57b4049f..d07a93e0 100644 --- a/tackerclient/tacker/v1_0/vnfm/vnfd.py +++ b/tackerclient/tacker/v1_0/vnfm/vnfd.py @@ -77,15 +77,15 @@ class CreateVNFD(tackerV10.CreateCommand): body = {self.resource: {}} vnfd = None if not parsed_args.vnfd_file: - raise exceptions.InvalidInput("Invalid input for vnfd file") + raise exceptions.InvalidInput(reason="Invalid input for vnfd file") with open(parsed_args.vnfd_file) as f: vnfd = f.read() try: vnfd = yaml.load(vnfd, Loader=yaml.SafeLoader) except yaml.YAMLError as e: - raise exceptions.InvalidInput(e) + raise exceptions.InvalidInput(reason=e) if not vnfd: - raise exceptions.InvalidInput("vnfd file is empty") + raise exceptions.InvalidInput(reason="vnfd file is empty") body[self.resource]['attributes'] = {'vnfd': vnfd} tackerV10.update_dict(parsed_args, body[self.resource], ['tenant_id', 'name', 'description']) diff --git a/tackerclient/tests/unit/osc/v1/test_vnflcm.py b/tackerclient/tests/unit/osc/v1/test_vnflcm.py index da5ea6b4..997c295e 100644 --- a/tackerclient/tests/unit/osc/v1/test_vnflcm.py +++ b/tackerclient/tests/unit/osc/v1/test_vnflcm.py @@ -253,9 +253,9 @@ class TestInstantiateVnfLcm(TestVnfLcm): self.instantiate_vnf_lcm.take_action, parsed_args) - expected_msg = ("File %s does not exist or user does not have read " - "privileges to it") - self.assertEqual(expected_msg % sample_param_file, ex.message) + expected_msg = ("Invalid input: File %s does not exist " + "or user does not have read privileges to it") + self.assertEqual(expected_msg % sample_param_file, str(ex)) @mock.patch("os.open") @mock.patch("os.access") @@ -275,9 +275,8 @@ class TestInstantiateVnfLcm(TestVnfLcm): ex = self.assertRaises(exceptions.InvalidInput, self.instantiate_vnf_lcm.take_action, parsed_args) - expected_msg = "Failed to load parameter file." - self.assertIn(expected_msg, ex.message) + self.assertIn(expected_msg, str(ex)) @ddt.ddt