Fix vnf scaling action policy to use infra_driver
ActionPolicy getter was recently changed to use infra_driver [1]. However the alarm monitor handling of scaling policy missed passing infra_driver causing scaling due to alarm monitoring trigger to fail. This fix now correctly passes infra_driver for monitor ActionPolicy.get_policy method in this specific case. [1] https://review.openstack.org/#/c/375181/ Change-Id: I545f959fb889036846282cd78e7967822604975f Closes-Bug: #1627975
This commit is contained in:
parent
3596172ee6
commit
e6e7385ffb
|
@ -38,7 +38,10 @@ vnffgd_tosca_template = yaml.load(_get_template('tosca_vnffgd_template.yaml'))
|
|||
vnffgd_invalid_tosca_template = yaml.load(_get_template(
|
||||
'tosca_invalid_vnffgd_template.yaml'))
|
||||
vnfd_scale_tosca_template = _get_template('tosca_scale.yaml')
|
||||
vnfd_alarm_tosca_template = _get_template('test_tosca_vnfd_alarm_respawn.yaml')
|
||||
vnfd_alarm_respawn_tosca_template = _get_template(
|
||||
'test_tosca_vnfd_alarm_respawn.yaml')
|
||||
vnfd_alarm_scale_tosca_template = _get_template(
|
||||
'test_tosca_vnfd_alarm_scale.yaml')
|
||||
|
||||
|
||||
def get_dummy_vnfd_obj():
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0
|
||||
description: Demo example
|
||||
|
||||
metadata:
|
||||
template_name: sample-tosca-vnfd
|
||||
|
||||
topology_template:
|
||||
node_templates:
|
||||
VDU1:
|
||||
type: tosca.nodes.nfv.VDU.Tacker
|
||||
capabilities:
|
||||
nfv_compute:
|
||||
properties:
|
||||
disk_size: 1 GB
|
||||
mem_size: 512 MB
|
||||
num_cpus: 2
|
||||
properties:
|
||||
image: cirros-0.3.4-x86_64-uec
|
||||
mgmt_driver: noop
|
||||
availability_zone: nova
|
||||
|
||||
CP1:
|
||||
type: tosca.nodes.nfv.CP.Tacker
|
||||
properties:
|
||||
management: true
|
||||
anti_spoofing_protection: false
|
||||
requirements:
|
||||
- virtualLink:
|
||||
node: VL1
|
||||
- virtualBinding:
|
||||
node: VDU1
|
||||
|
||||
VL1:
|
||||
type: tosca.nodes.nfv.VL
|
||||
properties:
|
||||
network_name: net_mgmt
|
||||
vendor: Tacker
|
||||
|
||||
policies:
|
||||
- SP1:
|
||||
type: tosca.policy.tacker.Scaling
|
||||
properties:
|
||||
increment: 1
|
||||
cooldown: 120
|
||||
min_instances: 1
|
||||
max_instances: 3
|
||||
default_instances: 2
|
||||
targets: [VDU1]
|
||||
|
||||
- vdu1_cpu_usage_monitoring_policy:
|
||||
type: tosca.policies.tacker.Alarming
|
||||
triggers:
|
||||
resize_compute:
|
||||
event_type:
|
||||
type: tosca.events.resource.utilization
|
||||
implementation: ceilometer
|
||||
metrics: cpu_util
|
||||
condition:
|
||||
threshold: 50
|
||||
constraint: utilization greater_than 50%
|
||||
period: 600
|
||||
evaluations: 1
|
||||
method: avg
|
||||
comparison_operator: gt
|
||||
action:
|
||||
resize_compute:
|
||||
action_name: SP1
|
|
@ -386,25 +386,53 @@ class TestVNFMPlugin(db_base.SqlTestCase):
|
|||
def test_scale_vnf_in(self):
|
||||
self._test_scale_vnf('in', constants.PENDING_SCALE_IN)
|
||||
|
||||
@patch('tacker.vnfm.monitor.ActionPolicy')
|
||||
def test_create_vnf_trigger_respawn(self, mock_action_policy):
|
||||
action_policy_cls = mock_action_policy.return_value
|
||||
action_policy_cls.get_policy.return_value = mock.Mock()
|
||||
def _get_dummy_active_vnf(self, vnfd_template):
|
||||
dummy_vnf = utils.get_dummy_device_obj()
|
||||
dummy_vnf['vnfd']['attributes']['vnfd'] = vnfd_template
|
||||
dummy_vnf['status'] = 'ACTIVE'
|
||||
dummy_vnf['instance_id'] = '4c00108e-c69d-4624-842d-389c77311c1d'
|
||||
dummy_vnf['vim_id'] = '437ac8ef-a8fb-4b6e-8d8a-a5e86a376e8b'
|
||||
return dummy_vnf
|
||||
|
||||
def _test_create_vnf_trigger(self, action_value):
|
||||
vnf_id = "6261579e-d6f3-49ad-8bc3-a9cb974778fe"
|
||||
trigger_request = {"trigger": {"action_name": "respawn", "params": {
|
||||
trigger_request = {"trigger": {"action_name": action_value, "params": {
|
||||
"credential": "026kll6n", "data": {"current": "alarm",
|
||||
'alarm_id':
|
||||
"b7fa9ffd-0a4f-4165-954b-5a8d0672a35f"}},
|
||||
"policy_name": "vdu1_cpu_usage_monitoring_policy"}}
|
||||
self._insert_dummy_device_template()
|
||||
self._insert_dummy_vnfd_attributes(utils.vnfd_alarm_tosca_template)
|
||||
self._insert_dummy_device()
|
||||
expected_result = {"action_name": "respawn", "params": {
|
||||
expected_result = {"action_name": action_value, "params": {
|
||||
"credential": "026kll6n", "data": {"current": "alarm",
|
||||
"alarm_id": "b7fa9ffd-0a4f-4165-954b-5a8d0672a35f"}},
|
||||
"policy_name": "vdu1_cpu_usage_monitoring_policy"}
|
||||
self._vnf_alarm_monitor.process_alarm_for_vnf.return_value = True
|
||||
|
||||
trigger_result = self.vnfm_plugin.create_vnf_trigger(
|
||||
self.context, vnf_id, trigger_request)
|
||||
self.assertEqual(expected_result, trigger_result)
|
||||
|
||||
@patch('tacker.db.vnfm.vnfm_db.VNFMPluginDb.get_vnf')
|
||||
@patch('tacker.vnfm.monitor.ActionPolicy.get_policy')
|
||||
def test_create_vnf_trigger_respawn(self, mock_get_policy, mock_get_vnf):
|
||||
dummy_vnf = self._get_dummy_active_vnf(
|
||||
utils.vnfd_alarm_respawn_tosca_template)
|
||||
mock_get_vnf.return_value = dummy_vnf
|
||||
mock_action_class = mock.Mock()
|
||||
mock_get_policy.return_value = mock_action_class
|
||||
self._test_create_vnf_trigger(action_value="respawn")
|
||||
mock_get_policy.assert_called_once_with('respawn', 'test_vim')
|
||||
mock_action_class.execute_action.assert_called_once_with(
|
||||
self.vnfm_plugin, dummy_vnf)
|
||||
|
||||
@patch('tacker.db.vnfm.vnfm_db.VNFMPluginDb.get_vnf')
|
||||
@patch('tacker.vnfm.monitor.ActionPolicy.get_policy')
|
||||
def test_create_vnf_trigger_scale(self, mock_get_policy, mock_get_vnf):
|
||||
dummy_vnf = self._get_dummy_active_vnf(
|
||||
utils.vnfd_alarm_scale_tosca_template)
|
||||
mock_get_vnf.return_value = dummy_vnf
|
||||
mock_action_class = mock.Mock()
|
||||
mock_get_policy.return_value = mock_action_class
|
||||
scale_body = {'scale': {'policy': 'SP1', 'type': 'out'}}
|
||||
self._test_create_vnf_trigger(action_value="SP1")
|
||||
mock_get_policy.assert_called_once_with('scaling', 'test_vim')
|
||||
mock_action_class.execute_action.assert_called_once_with(
|
||||
self.vnfm_plugin, dummy_vnf, scale_body)
|
||||
|
|
|
@ -764,8 +764,10 @@ class VNFMPlugin(vnfm_db.VNFMPluginDb, VNFMMgmtMixin):
|
|||
scale.setdefault('scale', {})
|
||||
scale['scale']['type'] = 'out' if cp == 'gt' else 'in'
|
||||
scale['scale']['policy'] = bckend_policy['name']
|
||||
infra_driver, vim_auth = self._get_infra_driver(context,
|
||||
vnf_dict)
|
||||
action_cls = monitor.ActionPolicy.get_policy(action,
|
||||
vnf_dict)
|
||||
infra_driver)
|
||||
if action_cls:
|
||||
action_cls.execute_action(self, vnf_dict, scale)
|
||||
|
||||
|
|
Loading…
Reference in New Issue