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
This commit is contained in:
Hiroo Kitamura 2020-06-01 09:57:28 +09:00
parent 1825b5c509
commit 1d033f9053
19 changed files with 94 additions and 77 deletions

View File

@ -57,7 +57,7 @@ def get_client_class(api_name, version, version_map):
"one of: %(map_keys)s") "one of: %(map_keys)s")
msg = msg % {'api_name': api_name, 'version': version, msg = msg % {'api_name': api_name, 'version': version,
'map_keys': ', '.join(version_map.keys())} 'map_keys': ', '.join(version_map.keys())}
raise exceptions.UnsupportedVersion(msg) raise exceptions.UnsupportedVersion(message=msg)
return importutils.import_class(client_path) return importutils.import_class(client_path)

View File

@ -54,7 +54,7 @@ def validate_int_range(parsed_args, attr_name, min_value=None, max_value=None):
{'attr_name': attr_name.replace('_', '-'), {'attr_name': attr_name.replace('_', '-'),
'val': val}) 'val': val})
raise exceptions.CommandError(msg) raise exceptions.CommandError(message=msg)
def validate_ip_subnet(parsed_args, attr_name): def validate_ip_subnet(parsed_args, attr_name):
@ -65,5 +65,5 @@ def validate_ip_subnet(parsed_args, attr_name):
netaddr.IPNetwork(val) netaddr.IPNetwork(val)
except (netaddr.AddrFormatError, ValueError): except (netaddr.AddrFormatError, ValueError):
raise exceptions.CommandError( raise exceptions.CommandError(
(_('%(attr_name)s "%(val)s" is not a valid CIDR.') % message=(_('%(attr_name)s "%(val)s" is not a valid CIDR.') %
{'attr_name': attr_name.replace('_', '-'), 'val': val})) {'attr_name': attr_name.replace('_', '-'), 'val': val}))

View File

@ -109,9 +109,10 @@ class CreateNS(command.ShowOne):
template = yaml.load( template = yaml.load(
template, Loader=yaml.SafeLoader) template, Loader=yaml.SafeLoader)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
if not template: 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 body[_NS]['nsd_template'] = template
if parsed_args.param_file: if parsed_args.param_file:
@ -121,9 +122,10 @@ class CreateNS(command.ShowOne):
param_yaml = yaml.load( param_yaml = yaml.load(
param_yaml, Loader=yaml.SafeLoader) param_yaml, Loader=yaml.SafeLoader)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
if not param_yaml: 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} body[_NS]['attributes'] = {'param_values': param_yaml}
tackerV10.update_dict(parsed_args, body[_NS], tackerV10.update_dict(parsed_args, body[_NS],
['tenant_id', 'name', 'description', ['tenant_id', 'name', 'description',
@ -200,7 +202,7 @@ class DeleteNS(command.Command):
% {'failed_id': failed_id, % {'failed_id': failed_id,
'error': error}) 'error': error})
msg += err_msg msg += err_msg
raise exceptions.CommandError(msg) raise exceptions.CommandError(message=msg)
else: else:
print((_('All specified %(resource)s(s) deleted successfully') print((_('All specified %(resource)s(s) deleted successfully')
% {'resource': _NS})) % {'resource': _NS}))

View File

@ -71,15 +71,15 @@ class CreateNSD(command.ShowOne):
body = {_NSD: {}} body = {_NSD: {}}
nsd = None nsd = None
if not parsed_args.nsd_file: 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: with open(parsed_args.nsd_file) as f:
nsd = f.read() nsd = f.read()
try: try:
nsd = yaml.load(nsd, Loader=yaml.SafeLoader) nsd = yaml.load(nsd, Loader=yaml.SafeLoader)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
if not nsd: if not nsd:
raise exceptions.InvalidInput("nsd file is empty") raise exceptions.InvalidInput(reason="nsd file is empty")
body[_NSD]['attributes'] = {'nsd': nsd} body[_NSD]['attributes'] = {'nsd': nsd}
tackerV10.update_dict(parsed_args, body[_NSD], tackerV10.update_dict(parsed_args, body[_NSD],
['tenant_id', 'name', 'description']) ['tenant_id', 'name', 'description'])
@ -138,7 +138,7 @@ class DeleteNSD(command.Command):
% {'failed_id': failed_id, % {'failed_id': failed_id,
'error': error}) 'error': error})
msg += err_msg msg += err_msg
raise exceptions.CommandError(msg) raise exceptions.CommandError(message=msg)
else: else:
print((_('All specified %(resource)s(s) deleted successfully') print((_('All specified %(resource)s(s) deleted successfully')
% {'resource': _NSD})) % {'resource': _NSD}))

View File

@ -124,7 +124,7 @@ class CreateVIM(command.ShowOne):
config_param = yaml.load(vim_config, config_param = yaml.load(vim_config,
Loader=yaml.SafeLoader) Loader=yaml.SafeLoader)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
vim_obj = body[_VIM] vim_obj = body[_VIM]
try: try:
auth_url = config_param.pop('auth_url') auth_url = config_param.pop('auth_url')
@ -190,7 +190,7 @@ class DeleteVIM(command.Command):
% {'failed_id': failed_id, % {'failed_id': failed_id,
'error': error}) 'error': error})
msg += err_msg msg += err_msg
raise exceptions.CommandError(msg) raise exceptions.CommandError(message=msg)
else: else:
print((_('All specified %(resource)s(s) deleted successfully') print((_('All specified %(resource)s(s) deleted successfully')
% {'resource': _VIM})) % {'resource': _VIM}))
@ -232,7 +232,7 @@ class UpdateVIM(command.ShowOne):
try: try:
config_param = yaml.load(config_yaml) config_param = yaml.load(config_yaml)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
vim_obj = body[_VIM] vim_obj = body[_VIM]
if config_param is not None: if config_param is not None:
vim_utils.args2body_vim(config_param, vim_obj) vim_utils.args2body_vim(config_param, vim_obj)

View File

@ -145,9 +145,10 @@ class CreateVNFFG(command.ShowOne):
try: try:
template = yaml.load(template, Loader=yaml.SafeLoader) template = yaml.load(template, Loader=yaml.SafeLoader)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
if not template: 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 body[_VNFFG]['vnffgd_template'] = template
if parsed_args.param_file: if parsed_args.param_file:
@ -157,9 +158,10 @@ class CreateVNFFG(command.ShowOne):
param_yaml = yaml.load( param_yaml = yaml.load(
param_yaml, Loader=yaml.SafeLoader) param_yaml, Loader=yaml.SafeLoader)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
if not param_yaml: 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} body[_VNFFG]['attributes'] = {'param_values': param_yaml}
tackerV10.update_dict(parsed_args, body[_VNFFG], tackerV10.update_dict(parsed_args, body[_VNFFG],
['tenant_id', 'name', 'vnffgd_id', ['tenant_id', 'name', 'vnffgd_id',
@ -218,7 +220,7 @@ class DeleteVNFFG(command.Command):
% {'failed_id': failed_id, % {'failed_id': failed_id,
'error': error}) 'error': error})
msg += err_msg msg += err_msg
raise exceptions.CommandError(msg) raise exceptions.CommandError(message=msg)
else: else:
print((_('All specified %(resource)s(s) deleted successfully') print((_('All specified %(resource)s(s) deleted successfully')
% {'resource': _VNFFG})) % {'resource': _VNFFG}))
@ -274,9 +276,10 @@ class UpdateVNFFG(command.ShowOne):
template = yaml.load( template = yaml.load(
template, Loader=yaml.SafeLoader) template, Loader=yaml.SafeLoader)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
if not template: 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 body[_VNFFG]['vnffgd_template'] = template
if parsed_args.param_file: if parsed_args.param_file:
@ -286,9 +289,10 @@ class UpdateVNFFG(command.ShowOne):
param_yaml = yaml.load( param_yaml = yaml.load(
param_yaml, Loader=yaml.SafeLoader) param_yaml, Loader=yaml.SafeLoader)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
if not param_yaml: 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} body[_VNFFG]['attributes'] = {'param_values': param_yaml}
tackerV10.update_dict(parsed_args, body[self.resource], tackerV10.update_dict(parsed_args, body[self.resource],
['vnf_mapping', 'symmetrical', 'description']) ['vnf_mapping', 'symmetrical', 'description'])

View File

@ -71,15 +71,16 @@ class CreateVNFFGD(command.ShowOne):
body = {_VNFFGD: {}} body = {_VNFFGD: {}}
vnffgd = None vnffgd = None
if not parsed_args.vnffgd_file: 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: with open(parsed_args.vnffgd_file) as f:
vnffgd = f.read() vnffgd = f.read()
try: try:
vnffgd = yaml.load(vnffgd, Loader=yaml.SafeLoader) vnffgd = yaml.load(vnffgd, Loader=yaml.SafeLoader)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
if not vnffgd: if not vnffgd:
raise exceptions.InvalidInput("vnffgd file is empty") raise exceptions.InvalidInput(reason="vnffgd file is empty")
body[_VNFFGD]['template'] = {'vnffgd': vnffgd} body[_VNFFGD]['template'] = {'vnffgd': vnffgd}
tackerV10.update_dict(parsed_args, body[_VNFFGD], tackerV10.update_dict(parsed_args, body[_VNFFGD],
['tenant_id', 'name', 'description']) ['tenant_id', 'name', 'description'])
@ -136,7 +137,7 @@ class DeleteVNFFGD(command.Command):
% {'failed_id': failed_id, % {'failed_id': failed_id,
'error': error}) 'error': error})
msg += err_msg msg += err_msg
raise exceptions.CommandError(msg) raise exceptions.CommandError(message=msg)
else: else:
print((_('All specified %(resource)s(s) deleted successfully') print((_('All specified %(resource)s(s) deleted successfully')
% {'resource': _VNFFGD})) % {'resource': _VNFFGD}))

View File

@ -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: 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 " msg = _("File %s does not exist or user does not have read "
"privileges to it") "privileges to it")
raise exceptions.InvalidInput(msg % file_path) reason = msg % file_path
raise exceptions.InvalidInput(reason=reason)
try: try:
with open(file_path) as f: with open(file_path) as f:
body = json.load(f) body = json.load(f)
except (IOError, ValueError) as ex: except (IOError, ValueError) as ex:
msg = _("Failed to load parameter file. Error: %s") msg = _("Failed to load parameter file. Error: %s")
raise exceptions.InvalidInput(msg % ex) reason = msg % ex
raise exceptions.InvalidInput(reason=reason)
if not body: if not body:
raise exceptions.InvalidInput(_('The parameter file is empty')) reason = _('The parameter file is empty')
raise exceptions.InvalidInput(reason=reason)
return body return body
@ -304,7 +307,7 @@ class TerminateVnfLcm(command.Command):
if parsed_args.graceful_termination_timeout: if parsed_args.graceful_termination_timeout:
if parsed_args.termination_type == 'FORCEFUL': if parsed_args.termination_type == 'FORCEFUL':
exceptions.InvalidInput('--graceful-termination-timeout' exceptions.InvalidInput(reason='--graceful-termination-timeout'
' argument is invalid for "FORCEFUL"' ' argument is invalid for "FORCEFUL"'
' termination') ' termination')
body['gracefulTerminationTimeout'] = parsed_args.\ body['gracefulTerminationTimeout'] = parsed_args.\
@ -355,8 +358,8 @@ class TerminateVnfLcm(command.Command):
msg = _("Couldn't verify vnf instance is terminated within " msg = _("Couldn't verify vnf instance is terminated within "
"'%(timeout)s' seconds. Unable to delete vnf instance " "'%(timeout)s' seconds. Unable to delete vnf instance "
"%(id)s") "%(id)s")
raise exceptions.CommandError(msg % {'timeout': timeout, raise exceptions.CommandError(
'id': vnf_instance_id}) message=msg % {'timeout': timeout, 'id': vnf_instance_id})
time.sleep(SLEEP_TIME) time.sleep(SLEEP_TIME)
@ -396,7 +399,7 @@ class DeleteVnfLcm(command.Command):
msg = (_("Failed to delete %(error_count)s of %(total)s " msg = (_("Failed to delete %(error_count)s of %(total)s "
"vnf instances.") % {'error_count': error_count, "vnf instances.") % {'error_count': error_count,
'total': total}) 'total': total})
raise exceptions.CommandError(msg) raise exceptions.CommandError(message=msg)
else: else:
if total > 1: if total > 1:
print(_('All specified vnf instances are deleted ' print(_('All specified vnf instances are deleted '

View File

@ -120,7 +120,7 @@ class CreateVNF(command.ShowOne):
config = yaml.load( config = yaml.load(
config_yaml, Loader=yaml.SafeLoader) config_yaml, Loader=yaml.SafeLoader)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
if config: if config:
body[_VNF]['attributes'] = {'config': config} body[_VNF]['attributes'] = {'config': config}
@ -146,9 +146,10 @@ class CreateVNF(command.ShowOne):
template = yaml.load( template = yaml.load(
template, Loader=yaml.SafeLoader) template, Loader=yaml.SafeLoader)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
if not template: 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 body[_VNF]['vnfd_template'] = template
if parsed_args.param_file: if parsed_args.param_file:
@ -158,9 +159,10 @@ class CreateVNF(command.ShowOne):
param_yaml = yaml.load( param_yaml = yaml.load(
param_yaml, Loader=yaml.SafeLoader) param_yaml, Loader=yaml.SafeLoader)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
if not param_yaml: 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} body[_VNF]['attributes'] = {'param_values': param_yaml}
tackerV10.update_dict(parsed_args, body[_VNF], tackerV10.update_dict(parsed_args, body[_VNF],
['tenant_id', 'name', 'description', ['tenant_id', 'name', 'description',
@ -234,7 +236,7 @@ class DeleteVNF(command.Command):
% {'failed_id': failed_id, % {'failed_id': failed_id,
'error': error}) 'error': error})
msg += err_msg msg += err_msg
raise exceptions.CommandError(msg) raise exceptions.CommandError(message=msg)
else: else:
print((_('All specified %(resource)s(s) deleted successfully') print((_('All specified %(resource)s(s) deleted successfully')
% {'resource': _VNF})) % {'resource': _VNF}))

View File

@ -71,16 +71,16 @@ class CreateVNFD(command.ShowOne):
body = {_VNFD: {}} body = {_VNFD: {}}
vnfd = None vnfd = None
if not parsed_args.vnfd_file: 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: with open(parsed_args.vnfd_file) as f:
vnfd = f.read() vnfd = f.read()
try: try:
vnfd = yaml.load(vnfd, Loader=yaml.SafeLoader) vnfd = yaml.load(vnfd, Loader=yaml.SafeLoader)
except yaml.YAMLError as e: except yaml.YAMLError as e:
msg = _("yaml failed to load vnfd file. %s") % e msg = _("yaml failed to load vnfd file. %s") % e
raise exceptions.InvalidInput(msg) raise exceptions.InvalidInput(reason=msg)
if not vnfd: if not vnfd:
raise exceptions.InvalidInput("vnfd file is empty") raise exceptions.InvalidInput(reason="vnfd file is empty")
body[_VNFD]['attributes'] = {'vnfd': vnfd} body[_VNFD]['attributes'] = {'vnfd': vnfd}
tackerV10.update_dict(parsed_args, body[_VNFD], tackerV10.update_dict(parsed_args, body[_VNFD],
['tenant_id', 'name', 'description']) ['tenant_id', 'name', 'description'])
@ -139,7 +139,7 @@ class DeleteVNFD(command.Command):
% {'failed_id': failed_id, % {'failed_id': failed_id,
'error': error}) 'error': error})
msg += err_msg msg += err_msg
raise exceptions.CommandError(msg) raise exceptions.CommandError(message=msg)
else: else:
print((_('All specified %(resource)s(s) deleted successfully') print((_('All specified %(resource)s(s) deleted successfully')
% {'resource': _VNFD})) % {'resource': _VNFD}))

View File

@ -343,7 +343,7 @@ class DeleteVnfPackage(command.Command):
% {'failed_id': failed_id, % {'failed_id': failed_id,
'error': error}) 'error': error})
msg += err_msg msg += err_msg
raise exceptions.CommandError(msg) raise exceptions.CommandError(message=msg)
else: else:
print((_('All specified %(resource)s(s) deleted successfully') print((_('All specified %(resource)s(s) deleted successfully')
% {'resource': self.resource})) % {'resource': self.resource}))

View File

@ -54,9 +54,9 @@ def make_client(instance):
auth=instance._auth) auth=instance._auth)
return client return client
else: else:
raise exceptions.UnsupportedVersion(_("API version %s is not " raise exceptions.UnsupportedVersion(
"supported") % reason=_("API version %s is not supported") %
instance._api_version[API_NAME]) instance._api_version[API_NAME])
def Client(api_version, *args, **kwargs): def Client(api_version, *args, **kwargs):

View File

@ -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): if _value_number == 0 and (current_type_str or _list_flag):
# This kind of argument should have value # This kind of argument should have value
raise exceptions.CommandError( 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': if _value_number > 1 or _list_flag or current_type_str == 'list':
current_arg.update({'nargs': '+'}) current_arg.update({'nargs': '+'})
elif _value_number == 0: elif _value_number == 0:
@ -237,7 +237,8 @@ def parse_args_to_dict(values_specs):
_value_number = 0 _value_number = 0
if _item in _options: if _item in _options:
raise exceptions.CommandError( raise exceptions.CommandError(
_("Duplicated options %s") % ' '.join(values_specs)) message=_("Duplicated "
"options %s") % ' '.join(values_specs))
else: else:
_options.update({_item: {}}) _options.update({_item: {}})
current_arg = _options[_item] current_arg = _options[_item]
@ -245,7 +246,8 @@ def parse_args_to_dict(values_specs):
elif _item.startswith('type='): elif _item.startswith('type='):
if current_arg is None: if current_arg is None:
raise exceptions.CommandError( raise exceptions.CommandError(
_("Invalid values_specs %s") % ' '.join(values_specs)) message=_("Invalid "
"values_specs %s") % ' '.join(values_specs))
if 'type' not in current_arg: if 'type' not in current_arg:
current_type_str = _item.split('=', 2)[1] current_type_str = _item.split('=', 2)[1]
current_arg.update({'type': eval(current_type_str)}) 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 if (not current_item or '=' in current_item or
_item.startswith('-') and not is_number(_item)): _item.startswith('-') and not is_number(_item)):
raise exceptions.CommandError( raise exceptions.CommandError(
_("Invalid values_specs %s") % ' '.join(values_specs)) message=_("Invalid "
"values_specs %s") % ' '.join(values_specs))
_value_number += 1 _value_number += 1
_values_specs.append(_item) _values_specs.append(_item)
@ -484,7 +487,8 @@ class UpdateCommand(TackerCommand):
body[self.resource] = _extra_values body[self.resource] = _extra_values
if not body[self.resource]: if not body[self.resource]:
raise exceptions.CommandError( 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: if self.allow_names:
_id = find_resourceid_by_name_or_id( _id = find_resourceid_by_name_or_id(
tacker_client, self.resource, parsed_args.id) tacker_client, self.resource, parsed_args.id)
@ -565,7 +569,7 @@ class DeleteCommand(TackerCommand):
% {'failed_id': failed_id, % {'failed_id': failed_id,
'error': error}) 'error': error})
msg += err_msg msg += err_msg
raise exceptions.CommandError(msg) raise exceptions.CommandError(message=msg)
else: else:
print((_('All specified %(resource)s(s) %(msg)s successfully') print((_('All specified %(resource)s(s) %(msg)s successfully')
% {'msg': self.deleted_msg.get(self.resource, 'deleted'), % {'msg': self.deleted_msg.get(self.resource, 'deleted'),

View File

@ -100,9 +100,9 @@ class CreateNS(tackerV10.CreateCommand):
args['nsd_template'] = yaml.load( args['nsd_template'] = yaml.load(
template, Loader=yaml.SafeLoader) template, Loader=yaml.SafeLoader)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
if not args['nsd_template']: 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: if parsed_args.param_file:
with open(parsed_args.param_file) as f: with open(parsed_args.param_file) as f:
@ -111,7 +111,7 @@ class CreateNS(tackerV10.CreateCommand):
args['attributes']['param_values'] = yaml.load( args['attributes']['param_values'] = yaml.load(
param_yaml, Loader=yaml.SafeLoader) param_yaml, Loader=yaml.SafeLoader)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
tackerV10.update_dict(parsed_args, body[self.resource], tackerV10.update_dict(parsed_args, body[self.resource],
['tenant_id', 'name', 'description', ['tenant_id', 'name', 'description',
'nsd_id', 'vim_id']) 'nsd_id', 'vim_id'])

View File

@ -71,7 +71,7 @@ class CreateVIM(tackerV10.CreateCommand):
config_param = yaml.load(vim_config, config_param = yaml.load(vim_config,
Loader=yaml.SafeLoader) Loader=yaml.SafeLoader)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
vim_obj = body[self.resource] vim_obj = body[self.resource]
try: try:
auth_url = config_param.pop('auth_url') auth_url = config_param.pop('auth_url')
@ -119,7 +119,7 @@ class UpdateVIM(tackerV10.UpdateCommand):
try: try:
config_param = yaml.load(config_yaml) config_param = yaml.load(config_yaml)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
vim_obj = body[self.resource] vim_obj = body[self.resource]
if config_param is not None: if config_param is not None:
vim_utils.args2body_vim(config_param, vim_obj) vim_utils.args2body_vim(config_param, vim_obj)

View File

@ -153,9 +153,10 @@ class CreateVNFFG(tackerV10.CreateCommand):
args['vnffgd_template'] = yaml.load( args['vnffgd_template'] = yaml.load(
template, Loader=yaml.SafeLoader) template, Loader=yaml.SafeLoader)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
if not args['vnffgd_template']: 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: if parsed_args.param_file:
with open(parsed_args.param_file) as f: with open(parsed_args.param_file) as f:
@ -164,7 +165,7 @@ class CreateVNFFG(tackerV10.CreateCommand):
args['attributes']['param_values'] = yaml.load( args['attributes']['param_values'] = yaml.load(
param_yaml, Loader=yaml.SafeLoader) param_yaml, Loader=yaml.SafeLoader)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
tackerV10.update_dict(parsed_args, body[self.resource], tackerV10.update_dict(parsed_args, body[self.resource],
['tenant_id', 'name', 'vnffgd_id', ['tenant_id', 'name', 'vnffgd_id',
@ -217,9 +218,10 @@ class UpdateVNFFG(tackerV10.UpdateCommand):
args['vnffgd_template'] = yaml.load( args['vnffgd_template'] = yaml.load(
template, Loader=yaml.SafeLoader) template, Loader=yaml.SafeLoader)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
if not args['vnffgd_template']: 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], tackerV10.update_dict(parsed_args, body[self.resource],
['tenant_id', 'vnf_mapping', 'symmetrical']) ['tenant_id', 'vnf_mapping', 'symmetrical'])

View File

@ -94,7 +94,7 @@ class CreateVNF(tackerV10.CreateCommand):
config = yaml.load( config = yaml.load(
config_yaml, Loader=yaml.SafeLoader) config_yaml, Loader=yaml.SafeLoader)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
if config: if config:
args['attributes']['config'] = config args['attributes']['config'] = config
@ -123,7 +123,7 @@ class CreateVNF(tackerV10.CreateCommand):
args['vnfd_template'] = yaml.load( args['vnfd_template'] = yaml.load(
template, Loader=yaml.SafeLoader) template, Loader=yaml.SafeLoader)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
if parsed_args.param_file: if parsed_args.param_file:
with open(parsed_args.param_file) as f: with open(parsed_args.param_file) as f:
@ -132,7 +132,7 @@ class CreateVNF(tackerV10.CreateCommand):
args['attributes']['param_values'] = yaml.load( args['attributes']['param_values'] = yaml.load(
param_yaml, Loader=yaml.SafeLoader) param_yaml, Loader=yaml.SafeLoader)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
tackerV10.update_dict(parsed_args, body[self.resource], tackerV10.update_dict(parsed_args, body[self.resource],
['tenant_id', 'name', 'description', ['tenant_id', 'name', 'description',
'vnfd_id', 'vim_id']) 'vnfd_id', 'vim_id'])

View File

@ -77,15 +77,15 @@ class CreateVNFD(tackerV10.CreateCommand):
body = {self.resource: {}} body = {self.resource: {}}
vnfd = None vnfd = None
if not parsed_args.vnfd_file: 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: with open(parsed_args.vnfd_file) as f:
vnfd = f.read() vnfd = f.read()
try: try:
vnfd = yaml.load(vnfd, Loader=yaml.SafeLoader) vnfd = yaml.load(vnfd, Loader=yaml.SafeLoader)
except yaml.YAMLError as e: except yaml.YAMLError as e:
raise exceptions.InvalidInput(e) raise exceptions.InvalidInput(reason=e)
if not vnfd: if not vnfd:
raise exceptions.InvalidInput("vnfd file is empty") raise exceptions.InvalidInput(reason="vnfd file is empty")
body[self.resource]['attributes'] = {'vnfd': vnfd} body[self.resource]['attributes'] = {'vnfd': vnfd}
tackerV10.update_dict(parsed_args, body[self.resource], tackerV10.update_dict(parsed_args, body[self.resource],
['tenant_id', 'name', 'description']) ['tenant_id', 'name', 'description'])

View File

@ -253,9 +253,9 @@ class TestInstantiateVnfLcm(TestVnfLcm):
self.instantiate_vnf_lcm.take_action, self.instantiate_vnf_lcm.take_action,
parsed_args) parsed_args)
expected_msg = ("File %s does not exist or user does not have read " expected_msg = ("Invalid input: File %s does not exist "
"privileges to it") "or user does not have read privileges to it")
self.assertEqual(expected_msg % sample_param_file, ex.message) self.assertEqual(expected_msg % sample_param_file, str(ex))
@mock.patch("os.open") @mock.patch("os.open")
@mock.patch("os.access") @mock.patch("os.access")
@ -275,9 +275,8 @@ class TestInstantiateVnfLcm(TestVnfLcm):
ex = self.assertRaises(exceptions.InvalidInput, ex = self.assertRaises(exceptions.InvalidInput,
self.instantiate_vnf_lcm.take_action, self.instantiate_vnf_lcm.take_action,
parsed_args) parsed_args)
expected_msg = "Failed to load parameter file." expected_msg = "Failed to load parameter file."
self.assertIn(expected_msg, ex.message) self.assertIn(expected_msg, str(ex))
@ddt.ddt @ddt.ddt