Browse Source

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
tags/1.2.0^0
Hiroo Kitamura 1 month ago
parent
commit
1d033f9053
19 changed files with 94 additions and 77 deletions
  1. +1
    -1
      tackerclient/common/utils.py
  2. +3
    -3
      tackerclient/common/validators.py
  3. +7
    -5
      tackerclient/osc/v1/nfvo/ns.py
  4. +4
    -4
      tackerclient/osc/v1/nfvo/nsd.py
  5. +3
    -3
      tackerclient/osc/v1/nfvo/vim.py
  6. +13
    -9
      tackerclient/osc/v1/nfvo/vnffg.py
  7. +5
    -4
      tackerclient/osc/v1/nfvo/vnffgd.py
  8. +10
    -7
      tackerclient/osc/v1/vnflcm/vnflcm.py
  9. +8
    -6
      tackerclient/osc/v1/vnfm/vnf.py
  10. +4
    -4
      tackerclient/osc/v1/vnfm/vnfd.py
  11. +1
    -1
      tackerclient/osc/v1/vnfpkgm/vnf_package.py
  12. +3
    -3
      tackerclient/tacker/client.py
  13. +10
    -6
      tackerclient/tacker/v1_0/__init__.py
  14. +3
    -3
      tackerclient/tacker/v1_0/nfvo/ns.py
  15. +2
    -2
      tackerclient/tacker/v1_0/nfvo/vim.py
  16. +7
    -5
      tackerclient/tacker/v1_0/nfvo/vnffg.py
  17. +3
    -3
      tackerclient/tacker/v1_0/vnfm/vnf.py
  18. +3
    -3
      tackerclient/tacker/v1_0/vnfm/vnfd.py
  19. +4
    -5
      tackerclient/tests/unit/osc/v1/test_vnflcm.py

+ 1
- 1
tackerclient/common/utils.py View File

@@ -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)



+ 3
- 3
tackerclient/common/validators.py 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('_', '-'),
'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}))

+ 7
- 5
tackerclient/osc/v1/nfvo/ns.py View File

@@ -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}))


+ 4
- 4
tackerclient/osc/v1/nfvo/nsd.py View File

@@ -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}))


+ 3
- 3
tackerclient/osc/v1/nfvo/vim.py View File

@@ -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)


+ 13
- 9
tackerclient/osc/v1/nfvo/vnffg.py View File

@@ -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'])


+ 5
- 4
tackerclient/osc/v1/nfvo/vnffgd.py View File

@@ -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}))


+ 10
- 7
tackerclient/osc/v1/vnflcm/vnflcm.py 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:
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 '


+ 8
- 6
tackerclient/osc/v1/vnfm/vnf.py View File

@@ -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}))


+ 4
- 4
tackerclient/osc/v1/vnfm/vnfd.py View File

@@ -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}))


+ 1
- 1
tackerclient/osc/v1/vnfpkgm/vnf_package.py View File

@@ -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}))


+ 3
- 3
tackerclient/tacker/client.py View File

@@ -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):


+ 10
- 6
tackerclient/tacker/v1_0/__init__.py 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):
# 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'),


+ 3
- 3
tackerclient/tacker/v1_0/nfvo/ns.py View File

@@ -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'])


+ 2
- 2
tackerclient/tacker/v1_0/nfvo/vim.py View File

@@ -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)


+ 7
- 5
tackerclient/tacker/v1_0/nfvo/vnffg.py View File

@@ -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'])


+ 3
- 3
tackerclient/tacker/v1_0/vnfm/vnf.py View File

@@ -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'])


+ 3
- 3
tackerclient/tacker/v1_0/vnfm/vnfd.py View File

@@ -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'])


+ 4
- 5
tackerclient/tests/unit/osc/v1/test_vnflcm.py View File

@@ -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


Loading…
Cancel
Save