This patch will focus on: 1. Fixing hardcoded metadata 2. Adding functional test for alarm monitor 3. Refactoring tosca template for alarm monitor 4. Refactoring scaling in/out support in alarm monitor 5. Supporting multi-trigger Partial-bug: #1630614 Change-Id: Ic5d0046d0dc0b4381713bda01c485cecae17abeachanges/79/382479/28
parent
a1dd7fd73d
commit
0eafa5b1bf
@ -0,0 +1,57 @@
|
||||
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
|
||||
metadata: {metering.vnf: VDU1}
|
||||
|
||||
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:
|
||||
- vdu1_cpu_usage_monitoring_policy:
|
||||
type: tosca.policies.tacker.Alarming
|
||||
triggers:
|
||||
vdu_hcpu_usage_respawning:
|
||||
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
|
||||
metadata: VDU1
|
||||
actions: [respawn]
|
@ -0,0 +1,82 @@
|
||||
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
|
||||
metadata: {metering.vnf: SG1}
|
||||
|
||||
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.policies.tacker.Scaling
|
||||
properties:
|
||||
increment: 1
|
||||
cooldown: 60
|
||||
min_instances: 1
|
||||
max_instances: 3
|
||||
default_instances: 2
|
||||
targets: [VDU1]
|
||||
|
||||
- vdu_cpu_usage_monitoring_policy:
|
||||
type: tosca.policies.tacker.Alarming
|
||||
triggers:
|
||||
vdu_hcpu_usage_scaling_out:
|
||||
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
|
||||
metadata: SG1
|
||||
actions: [SP1]
|
||||
|
||||
vdu_hcpu_usage_scaling_in:
|
||||
event_type:
|
||||
type: tosca.events.resource.utilization
|
||||
implementation: ceilometer
|
||||
metrics: cpu_util
|
||||
condition:
|
||||
threshold: 10
|
||||
constraint: utilization less_than 10%
|
||||
period: 600
|
||||
evaluations: 1
|
||||
method: avg
|
||||
comparison_operator: lt
|
||||
metadata: SG1
|
||||
actions: [SP1]
|
@ -0,0 +1,150 @@
|
||||
#
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import json
|
||||
import time
|
||||
|
||||
from tacker.plugins.common import constants as evt_constants
|
||||
from tacker.tests import constants
|
||||
from tacker.tests.functional import base
|
||||
from tacker.tests.utils import read_file
|
||||
|
||||
import yaml
|
||||
|
||||
|
||||
class VnfTestAlarmMonitor(base.BaseTackerTest):
|
||||
|
||||
def _test_vnf_tosca_alarm(self, vnfd_file, vnf_name):
|
||||
vnf_trigger_path = '/vnfs/%s/triggers'
|
||||
data = dict()
|
||||
data['tosca'] = read_file(vnfd_file)
|
||||
tosca_dict = yaml.safe_load(data['tosca'])
|
||||
toscal = data['tosca']
|
||||
tosca_arg = {'vnfd': {'name': vnf_name,
|
||||
'attributes': {'vnfd': toscal}}}
|
||||
|
||||
# Create vnfd with tosca template
|
||||
vnfd_instance = self.client.create_vnfd(body=tosca_arg)
|
||||
self.assertIsNotNone(vnfd_instance)
|
||||
|
||||
# Create vnf with vnfd_id
|
||||
vnfd_id = vnfd_instance['vnfd']['id']
|
||||
vnf_arg = {'vnf': {'vnfd_id': vnfd_id, 'name': vnf_name}}
|
||||
vnf_instance = self.client.create_vnf(body=vnf_arg)
|
||||
|
||||
self.validate_vnf_instance(vnfd_instance, vnf_instance)
|
||||
|
||||
vnf_id = vnf_instance['vnf']['id']
|
||||
|
||||
def _waiting_time(count):
|
||||
self.wait_until_vnf_active(
|
||||
vnf_id,
|
||||
constants.VNF_CIRROS_CREATE_TIMEOUT,
|
||||
constants.ACTIVE_SLEEP_TIME)
|
||||
vnf = self.client.show_vnf(vnf_id)['vnf']
|
||||
# {"VDU1": ["10.0.0.14", "10.0.0.5"]}
|
||||
self.assertEqual(count, len(json.loads(vnf['mgmt_url'])['VDU1']))
|
||||
|
||||
def trigger_vnf(vnf, policy_name, policy_action):
|
||||
credential = 'g0jtsxu9'
|
||||
body = {"trigger": {'policy_name': policy_name,
|
||||
'action_name': policy_action,
|
||||
'params': {
|
||||
'data': {'alarm_id': '35a80852-e24f-46ed-bd34-e2f831d00172', 'current': 'alarm'}, # noqa
|
||||
'credential': credential}
|
||||
}
|
||||
}
|
||||
self.client.post(vnf_trigger_path % vnf, body)
|
||||
|
||||
def _inject_monitoring_policy(vnfd_dict):
|
||||
if vnfd_dict.get('tosca_definitions_version'):
|
||||
polices = vnfd_dict['topology_template'].get('policies', [])
|
||||
mon_policy = dict()
|
||||
for policy_dict in polices:
|
||||
for name, policy in policy_dict.items():
|
||||
if policy['type'] == constants.POLICY_ALARMING:
|
||||
triggers = policy['triggers']
|
||||
for trigger_name, trigger_dict in triggers.items():
|
||||
policy_action_list = trigger_dict['actions']
|
||||
for policy_action in policy_action_list:
|
||||
mon_policy[trigger_name] = policy_action
|
||||
return mon_policy
|
||||
|
||||
def verify_policy(policy_dict, kw_policy):
|
||||
for name, action in policy_dict.items():
|
||||
if kw_policy in name:
|
||||
return name
|
||||
|
||||
# trigger alarm
|
||||
monitoring_policy = _inject_monitoring_policy(tosca_dict)
|
||||
for mon_policy_name, mon_policy_action in monitoring_policy.items():
|
||||
if mon_policy_action in constants.DEFAULT_ALARM_ACTIONS:
|
||||
self.wait_until_vnf_active(
|
||||
vnf_id,
|
||||
constants.VNF_CIRROS_CREATE_TIMEOUT,
|
||||
constants.ACTIVE_SLEEP_TIME)
|
||||
trigger_vnf(vnf_id, mon_policy_name, mon_policy_action)
|
||||
else:
|
||||
if 'scaling_out' in mon_policy_name:
|
||||
_waiting_time(2)
|
||||
time.sleep(constants.SCALE_WINDOW_SLEEP_TIME)
|
||||
# scaling-out backend action
|
||||
scaling_out_action = mon_policy_action + '-out'
|
||||
trigger_vnf(vnf_id, mon_policy_name, scaling_out_action)
|
||||
|
||||
_waiting_time(3)
|
||||
|
||||
scaling_in_name = verify_policy(monitoring_policy,
|
||||
kw_policy='scaling_in')
|
||||
if scaling_in_name:
|
||||
time.sleep(constants.SCALE_WINDOW_SLEEP_TIME)
|
||||
# scaling-in backend action
|
||||
scaling_in_action = mon_policy_action + '-in'
|
||||
trigger_vnf(vnf_id, scaling_in_name, scaling_in_action)
|
||||
|
||||
_waiting_time(2)
|
||||
|
||||
self.verify_vnf_crud_events(
|
||||
vnf_id, evt_constants.RES_EVT_SCALE,
|
||||
evt_constants.ACTIVE, cnt=2)
|
||||
self.verify_vnf_crud_events(
|
||||
vnf_id, evt_constants.RES_EVT_SCALE,
|
||||
evt_constants.PENDING_SCALE_OUT, cnt=1)
|
||||
self.verify_vnf_crud_events(
|
||||
vnf_id, evt_constants.RES_EVT_SCALE,
|
||||
evt_constants.PENDING_SCALE_IN, cnt=1)
|
||||
# Delete vnf_instance with vnf_id
|
||||
try:
|
||||
self.client.delete_vnf(vnf_id)
|
||||
except Exception:
|
||||
assert False, ("Failed to delete vnf %s after the monitor test" %
|
||||
vnf_id)
|
||||
|
||||
# Verify VNF monitor events captured for states, ACTIVE and DEAD
|
||||
vnf_state_list = [evt_constants.ACTIVE, evt_constants.DEAD]
|
||||
self.verify_vnf_monitor_events(vnf_id, vnf_state_list)
|
||||
|
||||
# Delete vnfd_instance
|
||||
self.addCleanup(self.client.delete_vnfd, vnfd_id)
|
||||
self.addCleanup(self.wait_until_vnf_delete, vnf_id,
|
||||
constants.VNF_CIRROS_DELETE_TIMEOUT)
|
||||
|
||||
def test_vnf_alarm_respawn(self):
|
||||
self._test_vnf_tosca_alarm(
|
||||
'sample-tosca-alarm-respawn.yaml',
|
||||
'alarm and respawn vnf')
|
||||
|
||||
def test_vnf_alarm_scale(self):
|
||||
self._test_vnf_tosca_alarm(
|
||||
'sample-tosca-alarm-scale.yaml',
|
||||
'alarm and scale vnf')
|
@ -0,0 +1,24 @@
|
||||
heat_template_version: 2013-05-23
|
||||
description: 'sample-tosca-vnfd-scaling
|
||||
|
||||
'
|
||||
outputs:
|
||||
mgmt_ip-VDU1:
|
||||
value:
|
||||
get_attr: [CP1, fixed_ips, 0, ip_address]
|
||||
parameters: {}
|
||||
resources:
|
||||
CP1:
|
||||
properties: {network: net_mgmt, port_security_enabled: false}
|
||||
type: OS::Neutron::Port
|
||||
VDU1:
|
||||
properties:
|
||||
availability_zone: nova
|
||||
config_drive: false
|
||||
flavor: m1.tiny
|
||||
image: cirros-0.3.4-x86_64-uec
|
||||
metadata: {metering.vnf: SG1}
|
||||
networks:
|
||||
- port: {get_resource: CP1}
|
||||
user_data_format: SOFTWARE_CONFIG
|
||||
type: OS::Nova::Server
|
@ -0,0 +1,41 @@
|
||||
heat_template_version: 2013-05-23
|
||||
description: 'An exception will be raised when having the mismatched metadata
|
||||
(metadata is described in monitoring policy but unavailable in VDU properties).
|
||||
'
|
||||
|
||||
outputs:
|
||||
mgmt_ip-VDU1:
|
||||
value:
|
||||
get_attr: [CP1, fixed_ips, 0, ip_address]
|
||||
parameters: {}
|
||||
resources:
|
||||
VDU1:
|
||||
properties:
|
||||
availability_zone: nova
|
||||
config_drive: false
|
||||
flavor: {get_resource: VDU1_flavor}
|
||||
image: cirros-0.3.4-x86_64-uec
|
||||
networks:
|
||||
- port: {get_resource: CP1}
|
||||
user_data_format: SOFTWARE_CONFIG
|
||||
type: OS::Nova::Server
|
||||
CP1:
|
||||
properties: {network: net_mgmt, port_security_enabled: false}
|
||||
type: OS::Neutron::Port
|
||||
VDU1_flavor:
|
||||
type: OS::Nova::Flavor
|
||||
properties:
|
||||
disk: 1
|
||||
ram: 512
|
||||
vcpus: 2
|
||||
vdu_hcpu_usage_respawning:
|
||||
type: OS::Aodh::Alarm
|
||||
properties:
|
||||
description: utilization greater_than 50%
|
||||
meter_name: cpu_util
|
||||
threshold: 50
|
||||
period: 60
|
||||
statistic: average
|
||||
evaluation_periods: 1
|
||||
comparison_operator: gt
|
||||
'matching_metadata': {'metadata.user_metadata.vnf': 'VDU1'}
|
@ -0,0 +1,49 @@
|
||||
heat_template_version: 2013-05-23
|
||||
description: Tacker scaling template
|
||||
parameters: {}
|
||||
resources:
|
||||
G1:
|
||||
properties:
|
||||
cooldown: 60
|
||||
desired_capacity: 2
|
||||
max_size: 3
|
||||
min_size: 1
|
||||
resource: {type: scaling.yaml}
|
||||
type: OS::Heat::AutoScalingGroup
|
||||
SP1_scale_in:
|
||||
properties:
|
||||
adjustment_type: change_in_capacity
|
||||
auto_scaling_group_id: {get_resource: G1}
|
||||
cooldown: 60
|
||||
scaling_adjustment: '-1'
|
||||
type: OS::Heat::ScalingPolicy
|
||||
SP1_scale_out:
|
||||
properties:
|
||||
adjustment_type: change_in_capacity
|
||||
auto_scaling_group_id: {get_resource: G1}
|
||||
cooldown: 60
|
||||
scaling_adjustment: 1
|
||||
type: OS::Heat::ScalingPolicy
|
||||
|
||||
vdu_hcpu_usage_scaling_out:
|
||||
type: OS::Aodh::Alarm
|
||||
properties:
|
||||
description: utilization greater_than 50%
|
||||
meter_name: cpu_util
|
||||
statistic: avg
|
||||
period: 600
|
||||
evaluation_periods: 1
|
||||
threshold: 50
|
||||
matching_metadata: {'metadata.user_metadata.vnf': SG1}
|
||||
comparison_operator: gt
|
||||
vdu_lcpu_usage_scaling_in:
|
||||
type: OS::Aodh::Alarm
|
||||
properties:
|
||||
description: utilization less_than 10%
|
||||
meter_name: cpu_util
|
||||
statistic: avg
|
||||
period: 600
|
||||
evaluation_periods: 1
|
||||
threshold: 10
|
||||
matching_metadata: {'metadata.user_metadata.vnf': SG1}
|
||||
comparison_operator: lt
|
@ -0,0 +1,60 @@
|
||||
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0
|
||||
description: >
|
||||
An exception will be raised when having the mismatched metadata
|
||||
(metadata is described in monitoring policy but unavailable in
|
||||
VDU properties).
|
||||
|
||||
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:
|
||||
- vdu1_cpu_usage_monitoring_policy:
|
||||
type: tosca.policies.tacker.Alarming
|
||||
triggers:
|
||||
vdu_hcpu_usage_respawning:
|
||||
event_type:
|
||||
type: tosca.events.resource.utilization
|
||||
implementation: Ceilometer
|
||||
metrics: cpu_util
|
||||
condition:
|
||||
threshold: 50
|
||||
constraint: utilization greater_than 50%
|
||||
period: 60
|
||||
evaluations: 1
|
||||
method: average
|
||||
comparison_operator: gt
|
||||
metadata: VDU1
|
||||
actions: ''
|
@ -0,0 +1,78 @@
|
||||
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0
|
||||
|
||||
description: sample-tosca-vnfd-scaling
|
||||
|
||||
metadata:
|
||||
template_name: sample-tosca-vnfd-scaling
|
||||
|
||||
topology_template:
|
||||
node_templates:
|
||||
VDU1:
|
||||
type: tosca.nodes.nfv.VDU.Tacker
|
||||
properties:
|
||||
image: cirros-0.3.4-x86_64-uec
|
||||
mgmt_driver: noop
|
||||
availability_zone: nova
|
||||
flavor: m1.tiny
|
||||
metadata: {metering.vnf: SG1}
|
||||
|
||||
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.policies.tacker.Scaling
|
||||
properties:
|
||||
increment: 1
|
||||
cooldown: 60
|
||||
min_instances: 1
|
||||
max_instances: 3
|
||||
default_instances: 2
|
||||
targets: [VDU1]
|
||||
|
||||
- vdu_cpu_usage_monitoring_policy:
|
||||
type: tosca.policies.tacker.Alarming
|
||||
triggers:
|
||||
vdu_hcpu_usage_scaling_out:
|
||||
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
|
||||
metadata: SG1
|
||||
actions: [SP1]
|
||||
|
||||
vdu_lcpu_usage_scaling_in:
|
||||
event_type:
|
||||
type: tosca.events.resource.utilization
|
||||
implementation: ceilometer
|
||||
metrics: cpu_util
|
||||
condition:
|
||||
threshold: 10
|
||||
constraint: utilization less_than 10%
|
||||
period: 600
|
||||
evaluations: 1
|
||||
method: avg
|
||||
comparison_operator: lt
|
||||
metadata: SG1
|
||||
actions: [SP1]
|