Remove yaml string deprecation warning

Starting from Ocata tacker payloads will only accept
YAML dict for config and param payload values. Hence
remove the warning when something other than YAML dict
is received by the API.

Change-Id: I9f06bf0e0f89b6633c25994b7a7d08cdf93547a2
Closes-Bug: #1656416
Co-Authored-By: lijiale<lijiale@cmss.chinamobile.com>
Co-Authored-By: Dharmendra Kushwaha<dharmendra.kushwaha@india.nec.com>
This commit is contained in:
Li Jiale 2018-06-20 13:43:55 +08:00 committed by dharmendra kushwaha
parent 48a5f80be7
commit b8c561493d
4 changed files with 32 additions and 28 deletions

View File

@ -32,7 +32,6 @@ import netaddr
from oslo_concurrency import lockutils
from oslo_config import cfg
from oslo_log import log as logging
from oslo_log import versionutils
from oslo_utils import importutils
from stevedore import driver
@ -213,12 +212,6 @@ def deep_update(orig_dict, new_dict):
orig_dict[key] = value
def deprecate_warning(what, as_of, in_favor_of=None, remove_in=1):
versionutils.deprecation_warning(as_of=as_of, what=what,
in_favor_of=in_favor_of,
remove_in=remove_in)
def generate_resource_name(resource, prefix='tmpl'):
return prefix + '-' \
+ ''.join(random.SystemRandom().choice(

View File

@ -55,6 +55,10 @@ class InvalidInfraDriver(exceptions.InvalidInput):
message = _('VIM type %(vim_name)s is not supported as an infra driver')
class InvalidAPIAttributeType(exceptions.InvalidInput):
message = _('Expecting dict type for API attribute instead of %(atype)s ')
class InvalidServiceType(exceptions.InvalidInput):
message = _('invalid service type %(service_type)s')

View File

@ -380,6 +380,15 @@ class TestVNFMPlugin(db_base.SqlTestCase):
self.vnfm_plugin.create_vnfd,
self.context, vnfd_obj)
def test_create_vnfd_without_dict_type_attributes(self):
vnfd_obj = utils.get_dummy_vnfd_obj()
# Convert dict to string.
vnfd_obj['vnfd']['attributes']['vnfd'] = str(
vnfd_obj['vnfd']['attributes']['vnfd'])
self.assertRaises(vnfm.InvalidAPIAttributeType,
self.vnfm_plugin.create_vnfd,
self.context, vnfd_obj)
def test_create_vnf_sync(self):
self._insert_dummy_vnf_template()
vnf_obj = utils.get_dummy_vnf_obj()
@ -462,16 +471,14 @@ class TestVNFMPlugin(db_base.SqlTestCase):
self.vnfm_plugin.create_vnf,
self.context, vnf_obj)
@patch('tacker.vnfm.plugin.VNFMPlugin._report_deprecated_yaml_str')
def test_create_vnf_with_invalid_param_and_config_format(self,
mock_report_deprecated_yaml_str):
def test_create_vnf_with_invalid_param_and_config_format(self):
self._insert_dummy_vnf_template()
vnf_obj = utils.get_dummy_vnf_obj()
vnf_obj['vnf']['attributes']['param_values'] = 'image_name'
vnf_obj['vnf']['attributes']['config'] = "test"
result = self.vnfm_plugin.create_vnf(self.context, vnf_obj)
self.assertEqual(3, mock_report_deprecated_yaml_str.call_count)
self.assertEqual('ACTIVE', result['status'])
vnf_obj['vnf']['attributes']['config'] = 'test'
self.assertRaises(vnfm.InvalidAPIAttributeType,
self.vnfm_plugin.create_vnf,
self.context, vnf_obj)
@patch('tacker.vnfm.plugin.VNFMPlugin.delete_vnf')
def test_create_vnf_fail(self, mock_delete_vnf):
@ -693,16 +700,14 @@ class TestVNFMPlugin(db_base.SqlTestCase):
res_state=mock.ANY, res_type=constants.RES_TYPE_VNF,
tstamp=mock.ANY)
@mock.patch('tacker.vnfm.plugin.VNFMPlugin._report_deprecated_yaml_str')
def test_update_vnf_invalid_config_format(self,
mock_report_deprecated_yaml_str):
def test_update_vnf_invalid_config_format(self):
self._insert_dummy_vnf_template()
dummy_vnf_obj = self._insert_dummy_vnf()
vnf_config_obj = utils.get_dummy_vnf_config_obj()
vnf_config_obj['vnf']['attributes']['config'] = 'test'
vnf_config_obj['vnf']['attributes']['config'] = {'vdus': {
'vdu1': {'config': {'firewall': 'dummy_firewall_values'}}}}
result = self.vnfm_plugin.update_vnf(self.context, dummy_vnf_obj[
'id'], vnf_config_obj)
self.assertEqual(1, mock_report_deprecated_yaml_str.call_count)
self.assertEqual(constants.ACTIVE, result['status'])
@patch('tacker.db.vnfm.vnfm_db.VNFMPluginDb.set_vnf_error_status_reason')

View File

@ -168,8 +168,8 @@ class VNFMPlugin(vnfm_db.VNFMPluginDb, VNFMMgmtMixin):
# key value string pairs in vnf attributes table
vnfd_data['attributes']['vnfd'] = yaml.safe_dump(
template)
elif isinstance(template, str):
self._report_deprecated_yaml_str()
else:
raise vnfm.InvalidAPIAttributeType(atype=type(template))
if "tosca_definitions_version" not in template:
raise exceptions.Invalid('Not a valid template: '
'tosca_definitions_version is missing.')
@ -273,6 +273,12 @@ class VNFMPlugin(vnfm_db.VNFMPluginDb, VNFMMgmtMixin):
config = vnf_dict['attributes'].get('config')
if not config:
return
if isinstance(config, str):
# TODO(dkushwaha) remove this load once db supports storing
# json format of yaml files in a separate column instead of
# key value string pairs in vnf attributes table.
config = yaml.safe_load(config)
eventlet.sleep(self.boot_wait) # wait for vm to be ready
vnf_id = vnf_dict['id']
update = {
@ -398,7 +404,7 @@ class VNFMPlugin(vnfm_db.VNFMPluginDb, VNFMMgmtMixin):
# key value string pairs in vnf attributes table
vnf_attributes['param_values'] = yaml.safe_dump(param)
else:
self._report_deprecated_yaml_str()
raise vnfm.InvalidAPIAttributeType(atype=type(param))
if vnf_attributes.get('config'):
config = vnf_attributes['config']
if isinstance(config, dict):
@ -407,7 +413,7 @@ class VNFMPlugin(vnfm_db.VNFMPluginDb, VNFMMgmtMixin):
# key value string pairs in vnf attributes table
vnf_attributes['config'] = yaml.safe_dump(config)
else:
self._report_deprecated_yaml_str()
raise vnfm.InvalidAPIAttributeType(atype=type(config))
vnf_dict = self._create_vnf(context, vnf_info, vim_auth, infra_driver)
@ -488,7 +494,7 @@ class VNFMPlugin(vnfm_db.VNFMPluginDb, VNFMMgmtMixin):
# key value string pairs in vnf attributes table
vnf_attributes['config'] = yaml.safe_dump(config)
else:
self._report_deprecated_yaml_str()
raise vnfm.InvalidAPIAttributeType(atype=type(config))
vnf_dict = self._update_vnf_pre(context, vnf_id,
constants.PENDING_UPDATE)
driver_name, vim_auth = self._get_infra_driver(context, vnf_dict)
@ -737,10 +743,6 @@ class VNFMPlugin(vnfm_db.VNFMPluginDb, VNFMMgmtMixin):
return policy
def _report_deprecated_yaml_str(self):
utils.deprecate_warning(what='yaml as string',
as_of='N', in_favor_of='yaml as dictionary')
def _make_policy_dict(self, vnf, name, policy):
p = {}
p['type'] = policy.get('type')