b4ec741a7f5221f52e0ccb92a42dd6def838ebdf
1 # -*- coding: utf-8 -*-
3 # Copyright 2018 Whitestack, LLC
4 # *************************************************************
6 # This file is part of OSM Monitoring module
7 # All Rights Reserved to Whitestack, LLC
9 # Licensed under the Apache License, Version 2.0 (the "License"); you may
10 # not use this file except in compliance with the License. You may obtain
11 # a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18 # License for the specific language governing permissions and limitations
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact: bdiaz@whitestack.com or glavado@whitestack.com
26 from kafka
import KafkaProducer
27 from kafka
.errors
import KafkaError
28 from osm_common
import dbmongo
30 from osm_mon
.collector
.collector
import MonCollector
31 from osm_mon
.core
.database
import VimCredentials
, DatabaseManager
32 from osm_mon
.core
.message_bus
.common_consumer
import CommonConsumer
35 @mock.patch
.object(dbmongo
.DbMongo
, "db_connect", mock
.Mock())
36 class MonCollectorTest(unittest
.TestCase
):
37 def test_generate_metric_data_payloads(self
):
39 "_id": "0d9d06ad-3fc2-418c-9934-465e815fafe2",
40 "ip-address": "192.168.160.2",
41 "created-time": 1535392482.0044956,
42 "vim-account-id": "be48ae31-1d46-4892-a4b4-d69abd55714b",
47 "mac-address": "fa:16:3e:71:fd:b8",
49 "ip-address": "192.168.160.2"
53 "vim-id": "63a65636-9fc8-4022-b070-980823e6266a",
54 "name": "cirros_ns-1-cirros_vnfd-VM-1",
55 "status-detailed": None,
56 "ip-address": "192.168.160.2",
57 "vdu-id-ref": "cirros_vnfd-VM"
60 "id": "0d9d06ad-3fc2-418c-9934-465e815fafe2",
61 "vnfd-ref": "cirros_vdu_scaling_vnf",
62 "vnfd-id": "63f44c41-45ee-456b-b10d-5f08fb1796e0",
64 "created": 1535392482.0067868,
68 "modified": 1535392482.0067868,
73 "nsr-id-ref": "87776f33-b67c-417a-8119-cb08e4098951",
74 "member-vnf-index-ref": "1",
79 "connection-point-id": None
84 "_id": "63f44c41-45ee-456b-b10d-5f08fb1796e0",
85 "name": "cirros_vdu_scaling_vnf",
89 "name": "cirros_vnfd-VM",
92 "id": "cirros_vnfd-VM_memory_util",
93 "nfvi-metric": "average_memory_utilization"
101 "description": "cirros_vnfd-VM",
103 "id": "cirros_vnfd-VM",
107 "external-connection-point-ref": "eth0",
109 "virtual-interface": {
112 "vpci": "0000:00:0a.0"
119 "monitoring-param": [
121 "id": "cirros_vnf_memory_util",
122 "name": "cirros_vnf_memory_util",
123 "aggregation-type": "AVERAGE",
124 "vdu-monitoring-param-ref": "cirros_vnfd-VM_memory_util",
125 "vdu-ref": "cirros_vnfd-VM"
128 "description": "Simple VNF example with a cirros and a scaling group descriptor",
129 "id": "cirros_vdu_scaling_vnf",
130 "logo": "cirros-64.png",
132 "connection-point": [
141 "scaling-group-descriptor": [
143 "name": "scale_cirros_vnfd-VM",
144 "min-instance-count": 1,
148 "vdu-id-ref": "cirros_vnfd-VM"
151 "max-instance-count": 10,
154 "name": "auto_memory_util_above_threshold",
155 "scaling-type": "automatic",
157 "threshold-time": 10,
158 "scaling-criteria": [
160 "name": "group1_memory_util_above_threshold",
161 "vnf-monitoring-param-ref": "cirros_vnf_memory_util",
162 "scale-out-threshold": 80,
163 "scale-out-relational-operation": "GT",
164 "scale-in-relational-operation": "LT",
165 "scale-in-threshold": 20
172 "short-name": "cirros_vdu_scaling_vnf",
174 "created": 1535392242.6281035,
175 "modified": 1535392242.6281035,
177 "zipfile": "package.tar.gz",
178 "pkg-dir": "cirros_vnf",
179 "path": "/app/storage/",
180 "folder": "63f44c41-45ee-456b-b10d-5f08fb1796e0",
182 "descriptor": "cirros_vnf/cirros_vdu_scaling_vnfd.yaml"
184 "usageSate": "NOT_IN_USE",
185 "onboardingState": "ONBOARDED",
192 "operationalState": "ENABLED",
198 payloads
= MonCollector
._generate
_metric
_data
_payloads
(vnfr
, vnfd
)
199 expected_payload
= {'ns_id': '87776f33-b67c-417a-8119-cb08e4098951',
200 'vnf_member_index': '1',
201 'metric_name': 'average_memory_utilization',
202 'collection_period': 1,
203 'collection_unit': 'DAY',
204 'vdu_name': 'cirros_ns-1-cirros_vnfd-VM-1'}
205 self
.assertEqual(len(payloads
), 1)
206 self
.assertEqual(set(expected_payload
.items()).issubset(set(payloads
[0].items())), True)