Remove hard coding of policy_type value

Method `get_vnf_policy_by_type` accepts policy_type parameter,
but inside this method, if it's doesn't find policy as specified
in parameter `policy_type`, then it raise VnfPolicyTypeInvalid
in which type is hard coded to constants.POLICY_ALARMING.

This patch removes the hard coded value of policy_type and used
the parameter which is passed to `get_vnf_policy_by_type` method.

Change-Id: I34346fdc51749530a1413a98a3a4b2ee65f78b08
This commit is contained in:
bhagyashris 2018-08-15 18:09:53 +09:00
parent 21bd3f13c6
commit c93c9ebecd
3 changed files with 15 additions and 2 deletions

View File

@ -53,6 +53,7 @@ POLICY_SCALING_ACTIONS = (ACTION_SCALE_OUT,
ACTION_SCALE_IN) = ('out', 'in')
POLICY_ACTIONS = {POLICY_SCALING: POLICY_SCALING_ACTIONS}
POLICY_ALARMING = 'tosca.policies.tacker.Alarming'
VALID_POLICY_TYPES = [POLICY_SCALING, POLICY_ALARMING]
DEFAULT_ALARM_ACTIONS = ['respawn', 'log', 'log_and_kill', 'notify']
RES_TYPE_VNFD = "vnfd"

View File

@ -20,6 +20,7 @@ from mock import patch
from oslo_utils import uuidutils
import yaml
from tacker.common import exceptions
from tacker import context
from tacker.db.common_services import common_services_db_plugin
from tacker.db.nfvo import nfvo_db
@ -542,3 +543,13 @@ class TestVNFMPlugin(db_base.SqlTestCase):
self.assertRaises(vnfm.InvalidMgmtDriver,
self.vnfm_plugin.create_vnfd,
self.context, vnfd_obj)
@mock.patch('tacker.vnfm.plugin.VNFMPlugin.get_vnf_policies')
def test_get_vnf_policy_by_type(self, mock_get_vnf_policies):
mock_get_vnf_policies.return_value = None
self.assertRaises(exceptions.VnfPolicyTypeInvalid,
self.vnfm_plugin.get_vnf_policy_by_type,
self.context,
uuidutils.generate_uuid(),
policy_type='invalid_policy_type')

View File

@ -745,8 +745,9 @@ class VNFMPlugin(vnfm_db.VNFMPluginDb, VNFMMgmtMixin):
if policies:
return policies[0]
raise exceptions.VnfPolicyTypeInvalid(type=constants.POLICY_ALARMING,
vnf_id=vnf_id)
raise exceptions.VnfPolicyTypeInvalid(
type=policy_type, policy=None,
valid_types=constants.VALID_POLICY_TYPES)
def _validate_alarming_policy(self, context, vnf_id, trigger):
# validate alarm status