1 # -*- coding: utf-8 -*-
4 # Copyright 2017-2018 VMware Inc.
5 # This file is part of ETSI OSM
8 # Licensed under the Apache License, Version 2.0 (the "License"); you may
9 # not use this file except in compliance with the License. You may obtain
10 # a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 # 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: osslegalrouting@vmware.com
24 """ Mock tests for VMware vROPs Mon plugin """
40 log
= logging
.getLogger(__name__
)
42 sys
.path
.append(os
.path
.join(os
.path
.dirname(os
.path
.abspath(__file__
)),"..","..",".."))
44 from osm_mon
.plugins
.vRealiseOps
import mon_plugin_vrops
as monPlugin
47 class TestMonPlugin(unittest
.TestCase
):
48 """Test class for vROPs Mon Plugin class methods"""
51 """Setup the tests for plugin_receiver class methods"""
52 super(TestMonPlugin
, self
).setUp()
53 self
.mon_plugin
= monPlugin
.MonPlugin()
56 def test_get_default_Params_valid_metric_alarm_name(self
):
57 """Test get default params method"""
59 # Mock valid metric_alarm_name and response
60 metric_alarm_name
= "Average_Memory_Usage_Above_Threshold"
61 exepcted_return
= {'impact': 'risk', 'cancel_cycles': 2, 'adapter_kind': 'VMWARE', 'repeat': False,
62 'cancel_period': 300, 'alarm_type': 16, 'vrops_alarm': 'Avg_Mem_Usage_Above_Thr',
63 'enabled': True, 'period': 300, 'resource_kind': 'VirtualMachine', 'alarm_subType': 19,
64 'action': 'acknowledge', 'evaluation': 2, 'unit': '%'}
66 # call get default param function under test
67 actual_return
= self
.mon_plugin
.get_default_Params(metric_alarm_name
)
69 #Verify return value with expected value
70 self
.assertEqual(exepcted_return
, actual_return
)
73 def test_get_default_Params_invalid_metric_alarm_name(self
):
74 """Test get default params method-invalid metric alarm"""
76 # Mock valid metric_alarm_name and response
77 metric_alarm_name
= "Invalid_Alarm"
80 # call get default param function under test
81 actual_return
= self
.mon_plugin
.get_default_Params(metric_alarm_name
)
83 #Verify return value with expected value
84 self
.assertEqual(exepcted_return
, actual_return
)
87 @mock.patch
.object(monPlugin
.requests
, 'post')
88 def test_create_symptom_valid_req_response(self
, m_post
):
89 """Test create symptom method-valid request"""
91 # Mock valid symptom params and mock responses
92 symptom_param
= {'threshold_value': 0, 'cancel_cycles': 1, 'adapter_kind_key': 'VMWARE',
93 'resource_kind_key': 'VirtualMachine', 'severity': 'CRITICAL',
94 'symptom_name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
95 'operation': 'GT', 'wait_cycles': 1, 'metric_key': 'cpu|usage_average'}
97 m_post
.return_value
.status_code
= 201
98 m_post
.return_value
.content
= '{"id":"SymptomDefinition-351c23b4-bc3c-4c7b-b4af-1ad90a673c5d",\
99 "name":"CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
100 "adapterKindKey":"VMWARE","resourceKindKey":"VirtualMachine","waitCycles":1,\
101 "cancelCycles":1,"state":{"severity":"CRITICAL","condition":{"type":"CONDITION_HT",\
102 "key":"cpu|usage_average","operator":"GT","value":"0.0","valueType":"NUMERIC",\
103 "instanced":false,"thresholdType":"STATIC"}}}'
105 exepcted_return
= "SymptomDefinition-351c23b4-bc3c-4c7b-b4af-1ad90a673c5d"
107 # call create symptom method under test
108 actual_return
= self
.mon_plugin
.create_symptom(symptom_param
)
110 #Verify that mocked method is called
111 m_post
.assert_called()
113 #Verify return value with expected value
114 self
.assertEqual(exepcted_return
, actual_return
)
117 @mock.patch
.object(monPlugin
.requests
, 'post')
118 def test_create_symptom_invalid_req_response(self
, m_post
):
119 """Test create symptom method-invalid response"""
121 # Mock valid symptom params and invalid mock responses
122 symptom_param
= {'threshold_value': 0, 'cancel_cycles': 1, 'adapter_kind_key': 'VMWARE',
123 'resource_kind_key': 'VirtualMachine', 'severity': 'CRITICAL',
124 'symptom_name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
125 'operation': 'GT', 'wait_cycles': 1, 'metric_key': 'cpu|usage_average'}
127 m_post
.return_value
.status_code
= 404
128 m_post
.return_value
.content
= '404 Not Found'
130 exepcted_return
= None
132 # call create symptom method under test
133 actual_return
= self
.mon_plugin
.create_symptom(symptom_param
)
135 #Verify that mocked method is called
136 m_post
.assert_called()
138 #Verify return value with expected value
139 self
.assertEqual(exepcted_return
, actual_return
)
142 @mock.patch
.object(monPlugin
.requests
, 'post')
143 def test_create_symptom_incorrect_data(self
, m_post
):
144 """Test create symptom method-incorrect data"""
146 # Mock valid symptom params and invalid mock responses
147 symptom_param
= {'threshold_value': 0, 'cancel_cycles': 1, 'adapter_kind_key': 'VMWARE',
148 'resource_kind_key': 'VirtualMachine', 'severity': 'CRITICAL',
149 'symptom_name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
150 'operation': 'GT', 'metric_key': 'cpu|usage_average'}
152 exepcted_return
= None
154 # call create symptom method under test
155 actual_return
= self
.mon_plugin
.create_symptom(symptom_param
)
157 #Verify that mocked method is not called
158 m_post
.assert_not_called()
160 #Verify return value with expected value
161 self
.assertEqual(exepcted_return
, actual_return
)
164 @mock.patch
.object(monPlugin
.requests
, 'post')
165 def test_create_alarm_definition_valid_req_response(self
, m_post
):
166 """Test create alarm definition method-valid response"""
168 # Mock valid alarm params and mock responses
169 alarm_param
= {'description': 'CPU_Utilization_Above_Threshold', 'cancelCycles': 1, 'subType': 19,
170 'waitCycles': 1, 'severity': 'CRITICAL', 'impact': 'risk', 'adapterKindKey': 'VMWARE',
171 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4', 'resourceKindKey': 'VirtualMachine',
172 'symptomDefinitionId': 'SymptomDefinition-25278b06-bff8-4409-a141-9b4e064235df', 'type': 16}
174 m_post
.return_value
.status_code
= 201
175 m_post
.return_value
.content
= '{"id":"AlertDefinition-d4f21e4b-770a-45d6-b298-022eaf489115",\
176 "name":"CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
177 "description":"CPU_Utilization_Above_Threshold","adapterKindKey":"VMWARE",\
178 "resourceKindKey":"VirtualMachine","waitCycles":1,"cancelCycles":1,"type":16,\
179 "subType":19,"states":[{"severity":"CRITICAL","base-symptom-set":{"type":"SYMPTOM_SET",\
180 "relation":"SELF","aggregation":"ALL","symptomSetOperator":"AND",\
181 "symptomDefinitionIds":["SymptomDefinition-25278b06-bff8-4409-a141-9b4e064235df"]},\
182 "impact":{"impactType":"BADGE","detail":"risk"}}]}'
184 exepcted_return
= "AlertDefinition-d4f21e4b-770a-45d6-b298-022eaf489115"
186 # call create alarm definition method under test
187 actual_return
= self
.mon_plugin
.create_alarm_definition(alarm_param
)
189 # verify that mocked method is called
190 m_post
.assert_called()
192 # verify return value with expected value
193 self
.assertEqual(exepcted_return
, actual_return
)
196 @mock.patch
.object(monPlugin
.requests
, 'post')
197 def test_create_alarm_definition_invalid_req_response(self
, m_post
):
198 """Test create alarm definition method-invalid response"""
200 # Mock valid alarm params and mock responses
201 alarm_param
= {'description': 'CPU_Utilization_Above_Threshold', 'cancelCycles': 1, 'subType': 19,
202 'waitCycles': 1, 'severity': 'CRITICAL', 'impact': 'risk', 'adapterKindKey': 'VMWARE',
203 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4', 'resourceKindKey': 'VirtualMachine',
204 'symptomDefinitionId': 'SymptomDefinition-25278b06-bff8-4409-a141-9b4e064235df', 'type': 16}
206 m_post
.return_value
.status_code
= 404
207 m_post
.return_value
.content
= '404 Not Found'
209 exepcted_return
= None
211 # call create alarm definition method under test
212 actual_return
= self
.mon_plugin
.create_alarm_definition(alarm_param
)
214 # verify that mocked method is called
215 m_post
.assert_called()
217 # verify return value with expected value
218 self
.assertEqual(exepcted_return
, actual_return
)
221 @mock.patch
.object(monPlugin
.requests
, 'post')
222 def test_create_alarm_definition_incorrect_data(self
, m_post
):
223 """Test create alarm definition method-incorrect data"""
225 # Mock incorrect alarm params
226 alarm_param
= {'description': 'CPU_Utilization_Above_Threshold', 'cancelCycles': 1, 'subType': 19,
227 'waitCycles': 1, 'severity': 'CRITICAL', 'impact': 'risk', 'adapterKindKey': 'VMWARE',
228 'symptomDefinitionId': 'SymptomDefinition-25278b06-bff8-4409-a141-9b4e064235df', 'type': 16}
230 exepcted_return
= None
232 # call create symptom method under test
233 actual_return
= self
.mon_plugin
.create_alarm_definition(alarm_param
)
235 # verify that mocked method is not called
236 m_post
.assert_not_called()
238 # verify return value with expected value
239 self
.assertEqual(exepcted_return
, actual_return
)
242 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_notification_rule')
243 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
244 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
245 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_definition')
246 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_symptom')
247 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_by_name')
248 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
249 def test_configure_alarm_valid_req(self
, m_get_default_Params
,\
250 m_get_alarm_defination_by_name
,\
252 m_create_alarm_definition
,\
254 m_get_vm_resource_id
,\
255 m_create_alarm_notification_rule
):
256 """Test configure alarm valid request creating alarm"""
258 #Mock input configuration dictionary
259 config_dict
= {'threshold_value': 0, 'severity': 'CRITICAL',
260 'alarm_name': 'CPU_Utilization_Above_Threshold',
261 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
262 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
263 'statistic': 'AVERAGE', 'metric_name': 'CPU_UTILIZATION',
264 'operation': 'GT', 'unit': '%',
265 'description': 'CPU_Utilization_Above_Threshold'}
267 #symptom parameters to be passed for symptom creation
268 symptom_params
= {'threshold_value': 0,
270 'adapter_kind_key': 'VMWARE',
271 'resource_kind_key': 'VirtualMachine',
272 'severity': 'CRITICAL',
273 'symptom_name':'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
276 'metric_key': 'cpu|usage_average'}
278 #alarm parameters to be passed for alarm creation
279 alarm_params
= {'description': 'CPU_Utilization_Above_Threshold',
280 'cancelCycles': 1, 'subType': 19,
281 'waitCycles': 1, 'severity': 'CRITICAL',
282 'impact': 'risk', 'adapterKindKey': 'VMWARE',
283 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
284 'resourceKindKey': 'VirtualMachine',
285 'symptomDefinitionId': 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804',
288 vm_moref_id
= 'vm-6626'
289 vrops_alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
290 alarm_def
= 'AlertDefinition-0f3cdcb3-4e1b-4a0b-86d0-66d4b3f65220'
291 resource_id
= 'ac87622f-b761-40a0-b151-00872a2a456e'
292 alarm_def_uuid
= '0f3cdcb3-4e1b-4a0b-86d0-66d4b3f65220'
294 #Mock default Parameters for alarm & metric configuration
295 m_get_default_Params
.side_effect
= [{'impact': 'risk', 'cancel_cycles': 1,
296 'adapter_kind': 'VMWARE', 'repeat': False,
297 'cancel_period': 300, 'alarm_type': 16,
298 'vrops_alarm': 'CPU_Utilization_Above_Thr',
299 'enabled': True, 'period': 300,
300 'resource_kind': 'VirtualMachine',
301 'alarm_subType': 19, 'action': 'acknowledge',
302 'evaluation': 1, 'unit': 'msec'},
303 {'metric_key': 'cpu|usage_average', 'unit': '%'}
306 #set mocked function return values
307 m_get_alarm_defination_by_name
.return_value
= []
308 m_create_symptom
.return_value
= 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804'
309 m_create_alarm_definition
.return_value
= 'AlertDefinition-0f3cdcb3-4e1b-4a0b-86d0-66d4b3f65220'
310 m_get_vm_moref_id
.return_value
= vm_moref_id
311 m_get_vm_resource_id
.return_value
= 'ac87622f-b761-40a0-b151-00872a2a456e'
312 m_create_alarm_notification_rule
.return_value
= 'f37900e7-dd01-4383-b84c-08f519530d71'
314 #Call configure_alarm method under test
315 return_value
= self
.mon_plugin
.configure_alarm(config_dict
)
317 #Verify that mocked methods are called with correct parameters
318 self
.assertEqual(m_get_default_Params
.call_count
, 2)
319 m_get_alarm_defination_by_name
.assert_called_with(vrops_alarm_name
)
320 m_create_symptom
.assert_called_with(symptom_params
)
321 m_create_alarm_definition
.assert_called_with(alarm_params
)
322 m_get_vm_moref_id
.assert_called_with(config_dict
['resource_uuid'])
323 m_get_vm_resource_id
.assert_called_with(vm_moref_id
)
324 m_create_alarm_notification_rule
.assert_called_with(vrops_alarm_name
, alarm_def
, resource_id
)
326 #Verify return value with expected value of alarm_def_uuid
327 self
.assertEqual(return_value
, alarm_def_uuid
)
330 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_notification_rule')
331 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
332 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
333 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_definition')
334 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_symptom')
335 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_by_name')
336 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
337 def test_configure_alarm_invalid_alarm_name_req(self
, m_get_default_Params
,\
338 m_get_alarm_defination_by_name
,\
340 m_create_alarm_definition
,\
342 m_get_vm_resource_id
,\
343 m_create_alarm_notification_rule
):
344 """Test configure alarm invalid test: for invalid alarm name"""
346 #Mock input configuration dictionary
347 config_dict
= {'threshold_value': 0, 'severity': 'CRITICAL',
348 'alarm_name': 'CPU_Utilization_Above_Threshold',
349 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
350 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
351 'statistic': 'AVERAGE', 'metric_name': 'CPU_UTILIZATION',
352 'operation': 'GT', 'unit': '%',
353 'description': 'CPU_Utilization_Above_Threshold'}
355 alarm_def_uuid
= None
357 #Mock default Parameters return value to None
358 m_get_default_Params
.return_value
= {}
360 #Call configure_alarm method under test
361 return_value
= self
.mon_plugin
.configure_alarm(config_dict
)
363 #Verify that mocked methods are called with correct parameters
364 m_get_default_Params
.assert_called_once()
365 m_get_alarm_defination_by_name
.assert_not_called()
366 m_create_symptom
.assert_not_called()
367 m_create_alarm_definition
.assert_not_called()
368 m_get_vm_moref_id
.assert_not_called()
369 m_get_vm_resource_id
.assert_not_called()
370 m_create_alarm_notification_rule
.assert_not_called()
372 #Verify return value with expected value i.e. None
373 self
.assertEqual(return_value
, alarm_def_uuid
)
376 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_notification_rule')
377 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
378 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
379 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_definition')
380 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_symptom')
381 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_by_name')
382 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
383 def test_configure_alarm_invalid_metric_name_req(self
, m_get_default_Params
,\
384 m_get_alarm_defination_by_name
,\
386 m_create_alarm_definition
,\
388 m_get_vm_resource_id
,\
389 m_create_alarm_notification_rule
):
390 """Test configure alarm invalid test: for invalid metric name"""
392 #Mock input configuration dictionary
393 config_dict
= {'threshold_value': 0, 'severity': 'CRITICAL',
394 'alarm_name': 'CPU_Utilization_Above_Threshold',
395 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
396 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
397 'statistic': 'AVERAGE', 'metric_name': 'CPU_UTILIZATION',
398 'operation': 'GT', 'unit': '%',
399 'description': 'CPU_Utilization_Above_Threshold'}
401 alarm_def_uuid
= None
403 #Mock default Parameters return values for metrics to None
404 m_get_default_Params
.side_effect
= [{'impact': 'risk', 'cancel_cycles': 1,
405 'adapter_kind': 'VMWARE', 'repeat': False,
406 'cancel_period': 300, 'alarm_type': 16,
407 'vrops_alarm': 'CPU_Utilization_Above_Thr',
408 'enabled': True, 'period': 300,
409 'resource_kind': 'VirtualMachine',
410 'alarm_subType': 19, 'action': 'acknowledge',
411 'evaluation': 1, 'unit': 'msec'},
415 #Call configure_alarm method under test
416 return_value
= self
.mon_plugin
.configure_alarm(config_dict
)
418 #Verify that mocked methods are called with correct parameters
419 self
.assertEqual(m_get_default_Params
.call_count
, 2)
420 m_get_alarm_defination_by_name
.assert_not_called()
421 m_create_symptom
.assert_not_called()
422 m_create_alarm_definition
.assert_not_called()
423 m_get_vm_moref_id
.assert_not_called()
424 m_get_vm_resource_id
.assert_not_called()
425 m_create_alarm_notification_rule
.assert_not_called()
427 #Verify return value with expected value i.e. None
428 self
.assertEqual(return_value
, alarm_def_uuid
)
430 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_notification_rule')
431 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
432 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
433 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_definition')
434 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_symptom')
435 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_by_name')
436 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
437 def test_configure_alarm_invalid_already_exists(self
, m_get_default_Params
,\
438 m_get_alarm_defination_by_name
,\
440 m_create_alarm_definition
,\
442 m_get_vm_resource_id
,\
443 m_create_alarm_notification_rule
):
444 """Test configure alarm invalid test: for alarm that already exists"""
446 #Mock input configuration dictionary
447 config_dict
= {'threshold_value': 0, 'severity': 'CRITICAL',
448 'alarm_name': 'CPU_Utilization_Above_Threshold',
449 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
450 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
451 'statistic': 'AVERAGE', 'metric_name': 'CPU_UTILIZATION',
452 'operation': 'GT', 'unit': '%',
453 'description': 'CPU_Utilization_Above_Threshold'}
455 vrops_alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
456 alarm_def_uuid
= None
458 #Mock default Parameters for alarm & metric configuration
459 m_get_default_Params
.side_effect
= [{'impact': 'risk', 'cancel_cycles': 1,
460 'adapter_kind': 'VMWARE', 'repeat': False,
461 'cancel_period': 300, 'alarm_type': 16,
462 'vrops_alarm': 'CPU_Utilization_Above_Thr',
463 'enabled': True, 'period': 300,
464 'resource_kind': 'VirtualMachine',
465 'alarm_subType': 19, 'action': 'acknowledge',
466 'evaluation': 1, 'unit': 'msec'},
467 {'metric_key': 'cpu|usage_average', 'unit': '%'}
469 #set mocked function return value
470 m_get_alarm_defination_by_name
.return_value
= ['mocked_alarm_CPU_Utilization_Above_Thr']
473 #Call configure_alarm method under test
474 return_value
= self
.mon_plugin
.configure_alarm(config_dict
)
476 #Verify that mocked methods are called with correct parameters
477 self
.assertEqual(m_get_default_Params
.call_count
, 2)
478 m_get_alarm_defination_by_name
.assert_called_with(vrops_alarm_name
)
479 m_create_symptom
.assert_not_called()
480 m_create_alarm_definition
.assert_not_called()
481 m_get_vm_moref_id
.assert_not_called()
482 m_get_vm_resource_id
.assert_not_called()
483 m_create_alarm_notification_rule
.assert_not_called()
485 #Verify return value with expected value of alarm_def_uuid
486 self
.assertEqual(return_value
, alarm_def_uuid
)
489 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_notification_rule')
490 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
491 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
492 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_definition')
493 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_symptom')
494 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_by_name')
495 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
496 def test_configure_alarm_failed_symptom_creation(self
, m_get_default_Params
,\
497 m_get_alarm_defination_by_name
,\
499 m_create_alarm_definition
,\
501 m_get_vm_resource_id
,\
502 m_create_alarm_notification_rule
):
503 """Test configure alarm: failed to create symptom"""
505 #Mock input configuration dictionary
506 config_dict
= {'threshold_value': 0, 'severity': 'CRITICAL',
507 'alarm_name': 'CPU_Utilization_Above_Threshold',
508 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
509 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
510 'statistic': 'AVERAGE', 'metric_name': 'CPU_UTILIZATION',
511 'operation': 'GT', 'unit': '%',
512 'description': 'CPU_Utilization_Above_Threshold'}
514 #symptom parameters to be passed for symptom creation
515 symptom_params
= {'threshold_value': 0,
517 'adapter_kind_key': 'VMWARE',
518 'resource_kind_key': 'VirtualMachine',
519 'severity': 'CRITICAL',
520 'symptom_name':'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
523 'metric_key': 'cpu|usage_average'}
524 vrops_alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
525 alarm_def_uuid
= None
527 #Mock default Parameters for alarm & metric configuration
528 m_get_default_Params
.side_effect
= [{'impact': 'risk', 'cancel_cycles': 1,
529 'adapter_kind': 'VMWARE', 'repeat': False,
530 'cancel_period': 300, 'alarm_type': 16,
531 'vrops_alarm': 'CPU_Utilization_Above_Thr',
532 'enabled': True, 'period': 300,
533 'resource_kind': 'VirtualMachine',
534 'alarm_subType': 19, 'action': 'acknowledge',
535 'evaluation': 1, 'unit': 'msec'},
536 {'metric_key': 'cpu|usage_average', 'unit': '%'}
538 #set mocked function return values
539 m_get_alarm_defination_by_name
.return_value
= []
540 m_create_symptom
.return_value
= None
542 #Call configure_alarm method under test
543 return_value
= self
.mon_plugin
.configure_alarm(config_dict
)
545 #Verify that mocked methods are called with correct parameters
546 self
.assertEqual(m_get_default_Params
.call_count
, 2)
547 m_get_alarm_defination_by_name
.assert_called_with(vrops_alarm_name
)
548 m_create_symptom
.assert_called_with(symptom_params
)
549 m_create_alarm_definition
.assert_not_called()
550 m_get_vm_moref_id
.assert_not_called()
551 m_get_vm_resource_id
.assert_not_called()
552 m_create_alarm_notification_rule
.assert_not_called()
554 #Verify return value with expected value of alarm_def_uuid
555 self
.assertEqual(return_value
, alarm_def_uuid
)
558 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_notification_rule')
559 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
560 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
561 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_definition')
562 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_symptom')
563 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_by_name')
564 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
565 def test_configure_alarm_failed_alert_creation(self
, m_get_default_Params
,\
566 m_get_alarm_defination_by_name
,\
568 m_create_alarm_definition
,\
570 m_get_vm_resource_id
,\
571 m_create_alarm_notification_rule
):
572 """Test configure alarm: failed to create alert in vROPs"""
574 #Mock input configuration dictionary
575 config_dict
= {'threshold_value': 0, 'severity': 'CRITICAL',
576 'alarm_name': 'CPU_Utilization_Above_Threshold',
577 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
578 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
579 'statistic': 'AVERAGE', 'metric_name': 'CPU_UTILIZATION',
580 'operation': 'GT', 'unit': '%',
581 'description': 'CPU_Utilization_Above_Threshold'}
583 #symptom parameters to be passed for symptom creation
584 symptom_params
= {'threshold_value': 0,
586 'adapter_kind_key': 'VMWARE',
587 'resource_kind_key': 'VirtualMachine',
588 'severity': 'CRITICAL',
589 'symptom_name':'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
592 'metric_key': 'cpu|usage_average'}
594 #alarm parameters to be passed for alarm creation
595 alarm_params
= {'description': 'CPU_Utilization_Above_Threshold',
596 'cancelCycles': 1, 'subType': 19,
597 'waitCycles': 1, 'severity': 'CRITICAL',
598 'impact': 'risk', 'adapterKindKey': 'VMWARE',
599 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
600 'resourceKindKey': 'VirtualMachine',
601 'symptomDefinitionId': 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804',
604 vrops_alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
605 alarm_def_uuid
= None
607 #Mock default Parameters for alarm & metric configuration
608 m_get_default_Params
.side_effect
= [{'impact': 'risk', 'cancel_cycles': 1,
609 'adapter_kind': 'VMWARE', 'repeat': False,
610 'cancel_period': 300, 'alarm_type': 16,
611 'vrops_alarm': 'CPU_Utilization_Above_Thr',
612 'enabled': True, 'period': 300,
613 'resource_kind': 'VirtualMachine',
614 'alarm_subType': 19, 'action': 'acknowledge',
615 'evaluation': 1, 'unit': 'msec'},
616 {'metric_key': 'cpu|usage_average', 'unit': '%'}
618 #set mocked function return values
619 m_get_alarm_defination_by_name
.return_value
= []
620 m_create_symptom
.return_value
= 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804'
621 m_create_alarm_definition
.return_value
= None
623 #Call configure_alarm method under test
624 return_value
= self
.mon_plugin
.configure_alarm(config_dict
)
626 #Verify that mocked methods are called with correct parameters
627 self
.assertEqual(m_get_default_Params
.call_count
, 2)
628 m_get_alarm_defination_by_name
.assert_called_with(vrops_alarm_name
)
629 m_create_symptom
.assert_called_with(symptom_params
)
630 m_create_alarm_definition
.assert_called_with(alarm_params
)
631 m_get_vm_moref_id
.assert_not_called()
632 m_get_vm_resource_id
.assert_not_called()
633 m_create_alarm_notification_rule
.assert_not_called()
635 #Verify return value with expected value of alarm_def_uuid
636 self
.assertEqual(return_value
, alarm_def_uuid
)
639 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_notification_rule')
640 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
641 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
642 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_definition')
643 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_symptom')
644 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_by_name')
645 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
646 def test_configure_alarm_failed_to_get_vm_moref_id(self
, m_get_default_Params
,\
647 m_get_alarm_defination_by_name
,\
649 m_create_alarm_definition
,\
651 m_get_vm_resource_id
,\
652 m_create_alarm_notification_rule
):
653 """Test configure alarm: failed to get vm_moref_id"""
655 #Mock input configuration dictionary
656 config_dict
= {'threshold_value': 0, 'severity': 'CRITICAL',
657 'alarm_name': 'CPU_Utilization_Above_Threshold',
658 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
659 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
660 'statistic': 'AVERAGE', 'metric_name': 'CPU_UTILIZATION',
661 'operation': 'GT', 'unit': '%',
662 'description': 'CPU_Utilization_Above_Threshold'}
664 #symptom parameters to be passed for symptom creation
665 symptom_params
= {'threshold_value': 0,
667 'adapter_kind_key': 'VMWARE',
668 'resource_kind_key': 'VirtualMachine',
669 'severity': 'CRITICAL',
670 'symptom_name':'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
673 'metric_key': 'cpu|usage_average'}
675 #alarm parameters to be passed for alarm creation
676 alarm_params
= {'description': 'CPU_Utilization_Above_Threshold',
677 'cancelCycles': 1, 'subType': 19,
678 'waitCycles': 1, 'severity': 'CRITICAL',
679 'impact': 'risk', 'adapterKindKey': 'VMWARE',
680 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
681 'resourceKindKey': 'VirtualMachine',
682 'symptomDefinitionId': 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804',
685 vrops_alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
686 alarm_def_uuid
= None
688 #Mock default Parameters for alarm & metric configuration
689 m_get_default_Params
.side_effect
= [{'impact': 'risk', 'cancel_cycles': 1,
690 'adapter_kind': 'VMWARE', 'repeat': False,
691 'cancel_period': 300, 'alarm_type': 16,
692 'vrops_alarm': 'CPU_Utilization_Above_Thr',
693 'enabled': True, 'period': 300,
694 'resource_kind': 'VirtualMachine',
695 'alarm_subType': 19, 'action': 'acknowledge',
696 'evaluation': 1, 'unit': 'msec'},
697 {'metric_key': 'cpu|usage_average', 'unit': '%'}
699 #set mocked function return values
700 m_get_alarm_defination_by_name
.return_value
= []
701 m_create_symptom
.return_value
= 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804'
702 m_create_alarm_definition
.return_value
= 'AlertDefinition-0f3cdcb3-4e1b-4a0b-86d0-66d4b3f65220'
703 m_get_vm_moref_id
.return_value
= None
705 #Call configure_alarm method under test
706 return_value
= self
.mon_plugin
.configure_alarm(config_dict
)
708 #Verify that mocked methods are called with correct parameters
709 self
.assertEqual(m_get_default_Params
.call_count
, 2)
710 m_get_alarm_defination_by_name
.assert_called_with(vrops_alarm_name
)
711 m_create_symptom
.assert_called_with(symptom_params
)
712 m_create_alarm_definition
.assert_called_with(alarm_params
)
713 m_get_vm_moref_id
.assert_called_with(config_dict
['resource_uuid'])
714 m_get_vm_resource_id
.assert_not_called()
715 m_create_alarm_notification_rule
.assert_not_called()
717 #Verify return value with expected value of alarm_def_uuid
718 self
.assertEqual(return_value
, alarm_def_uuid
)
721 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_notification_rule')
722 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
723 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
724 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_definition')
725 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_symptom')
726 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_by_name')
727 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
728 def test_configure_alarm_failed_to_get_vm_resource_id(self
, m_get_default_Params
,\
729 m_get_alarm_defination_by_name
,\
731 m_create_alarm_definition
,\
733 m_get_vm_resource_id
,\
734 m_create_alarm_notification_rule
):
735 """Test configure alarm: failed to get vm resource_id"""
737 #Mock input configuration dictionary
738 config_dict
= {'threshold_value': 0, 'severity': 'CRITICAL',
739 'alarm_name': 'CPU_Utilization_Above_Threshold',
740 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
741 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
742 'statistic': 'AVERAGE', 'metric_name': 'CPU_UTILIZATION',
743 'operation': 'GT', 'unit': '%',
744 'description': 'CPU_Utilization_Above_Threshold'}
746 #symptom parameters to be passed for symptom creation
747 symptom_params
= {'threshold_value': 0,
749 'adapter_kind_key': 'VMWARE',
750 'resource_kind_key': 'VirtualMachine',
751 'severity': 'CRITICAL',
752 'symptom_name':'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
755 'metric_key': 'cpu|usage_average'}
757 #alarm parameters to be passed for alarm creation
758 alarm_params
= {'description': 'CPU_Utilization_Above_Threshold',
759 'cancelCycles': 1, 'subType': 19,
760 'waitCycles': 1, 'severity': 'CRITICAL',
761 'impact': 'risk', 'adapterKindKey': 'VMWARE',
762 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
763 'resourceKindKey': 'VirtualMachine',
764 'symptomDefinitionId': 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804',
767 vrops_alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
768 vm_moref_id
= 'vm-6626'
769 alarm_def_uuid
= None
771 #Mock default Parameters for alarm & metric configuration
772 m_get_default_Params
.side_effect
= [{'impact': 'risk', 'cancel_cycles': 1,
773 'adapter_kind': 'VMWARE', 'repeat': False,
774 'cancel_period': 300, 'alarm_type': 16,
775 'vrops_alarm': 'CPU_Utilization_Above_Thr',
776 'enabled': True, 'period': 300,
777 'resource_kind': 'VirtualMachine',
778 'alarm_subType': 19, 'action': 'acknowledge',
779 'evaluation': 1, 'unit': 'msec'},
780 {'metric_key': 'cpu|usage_average', 'unit': '%'}
782 #set mocked function return values
783 m_get_alarm_defination_by_name
.return_value
= []
784 m_create_symptom
.return_value
= 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804'
785 m_create_alarm_definition
.return_value
= 'AlertDefinition-0f3cdcb3-4e1b-4a0b-86d0-66d4b3f65220'
786 m_get_vm_moref_id
.return_value
= vm_moref_id
787 m_get_vm_resource_id
.return_value
= None
789 #Call configure_alarm method under test
790 return_value
= self
.mon_plugin
.configure_alarm(config_dict
)
792 #Verify that mocked methods are called with correct parameters
793 self
.assertEqual(m_get_default_Params
.call_count
, 2)
794 m_get_alarm_defination_by_name
.assert_called_with(vrops_alarm_name
)
795 m_create_symptom
.assert_called_with(symptom_params
)
796 m_create_alarm_definition
.assert_called_with(alarm_params
)
797 m_get_vm_moref_id
.assert_called_with(config_dict
['resource_uuid'])
798 m_get_vm_resource_id
.assert_called_with(vm_moref_id
)
799 m_create_alarm_notification_rule
.assert_not_called()
801 #Verify return value with expected value of alarm_def_uuid
802 self
.assertEqual(return_value
, alarm_def_uuid
)
805 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_notification_rule')
806 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
807 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
808 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_definition')
809 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_symptom')
810 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_by_name')
811 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
812 def test_configure_alarm_failed_to_create_alarm_notification_rule(self
, m_get_default_Params
,\
813 m_get_alarm_defination_by_name
,\
815 m_create_alarm_definition
,\
817 m_get_vm_resource_id
,\
818 m_create_alarm_notification_rule
):
819 """Test configure alarm: failed to create alarm notification rule"""
821 #Mock input configuration dictionary
822 config_dict
= {'threshold_value': 0, 'severity': 'CRITICAL',
823 'alarm_name': 'CPU_Utilization_Above_Threshold',
824 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
825 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
826 'statistic': 'AVERAGE', 'metric_name': 'CPU_UTILIZATION',
827 'operation': 'GT', 'unit': '%',
828 'description': 'CPU_Utilization_Above_Threshold'}
830 #symptom parameters to be passed for symptom creation
831 symptom_params
= {'threshold_value': 0,
833 'adapter_kind_key': 'VMWARE',
834 'resource_kind_key': 'VirtualMachine',
835 'severity': 'CRITICAL',
836 'symptom_name':'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
839 'metric_key': 'cpu|usage_average'}
841 #alarm parameters to be passed for alarm creation
842 alarm_params
= {'description': 'CPU_Utilization_Above_Threshold',
843 'cancelCycles': 1, 'subType': 19,
844 'waitCycles': 1, 'severity': 'CRITICAL',
845 'impact': 'risk', 'adapterKindKey': 'VMWARE',
846 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
847 'resourceKindKey': 'VirtualMachine',
848 'symptomDefinitionId': 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804',
851 vrops_alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
852 vm_moref_id
= 'vm-6626'
853 alarm_def
= 'AlertDefinition-0f3cdcb3-4e1b-4a0b-86d0-66d4b3f65220'
854 resource_id
= 'ac87622f-b761-40a0-b151-00872a2a456e'
855 alarm_def_uuid
= None
857 #Mock default Parameters for alarm & metric configuration
858 m_get_default_Params
.side_effect
= [{'impact': 'risk', 'cancel_cycles': 1,
859 'adapter_kind': 'VMWARE', 'repeat': False,
860 'cancel_period': 300, 'alarm_type': 16,
861 'vrops_alarm': 'CPU_Utilization_Above_Thr',
862 'enabled': True, 'period': 300,
863 'resource_kind': 'VirtualMachine',
864 'alarm_subType': 19, 'action': 'acknowledge',
865 'evaluation': 1, 'unit': 'msec'},
866 {'metric_key': 'cpu|usage_average', 'unit': '%'}
868 #set mocked function return values
869 m_get_alarm_defination_by_name
.return_value
= []
870 m_create_symptom
.return_value
= 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804'
871 m_create_alarm_definition
.return_value
= 'AlertDefinition-0f3cdcb3-4e1b-4a0b-86d0-66d4b3f65220'
872 m_get_vm_moref_id
.return_value
= vm_moref_id
873 m_get_vm_resource_id
.return_value
= 'ac87622f-b761-40a0-b151-00872a2a456e'
874 m_create_alarm_notification_rule
.return_value
= None
876 #Call configure_alarm method under test
877 return_value
= self
.mon_plugin
.configure_alarm(config_dict
)
879 #Verify that mocked methods are called with correct parameters
880 self
.assertEqual(m_get_default_Params
.call_count
, 2)
881 m_get_alarm_defination_by_name
.assert_called_with(vrops_alarm_name
)
882 m_create_symptom
.assert_called_with(symptom_params
)
883 m_create_alarm_definition
.assert_called_with(alarm_params
)
884 m_get_vm_moref_id
.assert_called_with(config_dict
['resource_uuid'])
885 m_get_vm_resource_id
.assert_called_with(vm_moref_id
)
886 m_create_alarm_notification_rule
.assert_called_with(vrops_alarm_name
, alarm_def
, resource_id
)
888 #Verify return value with expected value of alarm_def_uuid
889 self
.assertEqual(return_value
, alarm_def_uuid
)
892 @mock.patch
.object(monPlugin
.requests
, 'get')
893 def test_get_alarm_defination_details_valid_rest_req_response(self
, m_get
):
894 """Test get_alarm_defination_details: For a valid REST request response"""
896 alarm_uuid
= '9a6d8a14-9f25-4d81-bf91-4d773497444d'
898 #Set mocked function's return values
899 m_get
.return_value
.status_code
= 200
900 m_get
.return_value
.content
= '{"id":"AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444d",\
901 "name":"CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
902 "description":"CPU_Utilization_Above_Threshold",\
903 "adapterKindKey":"VMWARE","resourceKindKey":"VirtualMachine",\
904 "waitCycles":1,"cancelCycles":1,"type":16,"subType":19,\
905 "states":[{"severity":"CRITICAL","base-symptom-set":{"type":"SYMPTOM_SET",\
906 "relation":"SELF","aggregation":"ALL","symptomSetOperator":"AND",\
907 "symptomDefinitionIds":["SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278"]},\
908 "impact":{"impactType":"BADGE","detail":"risk"}}]}'
910 expected_alarm_details
= {'adapter_kind': 'VMWARE',
911 'symptom_definition_id': 'SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278',
912 'alarm_name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
913 'alarm_id': 'AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444d',
914 'resource_kind': 'VirtualMachine', 'type': 16, 'sub_type': 19}
916 expected_alarm_details_json
= {'states':
918 {'impactType':'BADGE', 'detail':'risk'},'severity':'CRITICAL',
919 'base-symptom-set': {'symptomDefinitionIds':\
920 ['SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278'],
921 'relation': 'SELF', 'type': 'SYMPTOM_SET',
922 'aggregation':'ALL', 'symptomSetOperator': 'AND'}}],
923 'adapterKindKey': 'VMWARE',
924 'description': 'CPU_Utilization_Above_Threshold',
925 'type': 16, 'cancelCycles': 1, 'resourceKindKey': 'VirtualMachine',
926 'subType': 19, 'waitCycles': 1,
927 'id': 'AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444d',
928 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'}
930 #Call get_alarm_defination_details method under test
931 alarm_details_json
, alarm_details
= self
.mon_plugin
.get_alarm_defination_details(alarm_uuid
)
933 #Verify that mocked method is called
934 m_get
.assert_called()
936 #Verify return value with expected value
937 self
.assertEqual(expected_alarm_details
, alarm_details
)
938 self
.assertEqual(expected_alarm_details_json
, alarm_details_json
)
941 @mock.patch
.object(monPlugin
.requests
, 'get')
942 def test_get_alarm_defination_details_invalid_rest_req_response(self
, m_get
):
943 """Test get_alarm_defination_details: For an invalid REST request response"""
945 alarm_uuid
= '9a6d8a14-9f25-4d81-bf91-4d773497444d'
947 #Set mocked function's return values
948 m_get
.return_value
.status_code
= 404
949 m_get
.return_value
.content
= '{"message": "No such AlertDefinition - \
950 AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444.",\
951 "httpStatusCode": 404,"apiErrorCode": 404}'
953 expected_alarm_details
= None
954 expected_alarm_details_json
= None
956 #Call get_alarm_defination_details method under test
957 alarm_details_json
, alarm_details
= self
.mon_plugin
.get_alarm_defination_details(alarm_uuid
)
959 #verify that mocked method is called
960 m_get
.assert_called()
962 #Verify return value with expected value
963 self
.assertEqual(expected_alarm_details
, alarm_details
)
964 self
.assertEqual(expected_alarm_details_json
, alarm_details_json
)
967 @mock.patch
.object(monPlugin
.requests
, 'get')
968 def test_get_alarm_defination_by_name_valid_rest_req_response(self
, m_get
):
969 """Test get_alarm_defination_by_name: For a valid REST request response"""
971 alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
973 #Set mocked function's return values
974 m_get
.return_value
.status_code
= 200
975 m_get
.return_value
.content
= '{"pageInfo": {"totalCount": 1,"page": 0,"pageSize": 1000},\
977 {"href": "/suite-api/api/alertdefinitions?page=0&pageSize=1000",\
978 "rel": "SELF","name": "current"},\
979 {"href": "/suite-api/api/alertdefinitions?page=0&pageSize=1000",\
980 "rel": "RELATED","name": "first"},\
981 {"href": "/suite-api/api/alertdefinitions?page=0&pageSize=1000",\
982 "rel": "RELATED","name": "last"}],\
983 "alertDefinitions": [{\
984 "id": "AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444d",\
985 "name": "CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
986 "description": "CPU_Utilization_Above_Threshold",\
987 "adapterKindKey": "VMWARE","resourceKindKey": "VirtualMachine",\
988 "waitCycles": 1,"cancelCycles": 1,"type": 16,"subType": 19,\
989 "states": [{"impact": {"impactType": "BADGE","detail": "risk"},\
990 "severity": "CRITICAL",\
991 "base-symptom-set": {"type": "SYMPTOM_SET",\
992 "relation": "SELF","aggregation": "ALL",\
993 "symptomSetOperator": "AND",\
994 "symptomDefinitionIds": [\
995 "SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278"]}}]\
998 #Expected return match list
999 Exp_alert_match_list
= [{'states':
1000 [{'impact': {'impactType': 'BADGE', 'detail': 'risk'},
1001 'severity': 'CRITICAL',
1002 'base-symptom-set': {
1003 'symptomDefinitionIds': \
1004 ['SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278'],
1006 'type': 'SYMPTOM_SET',
1007 'aggregation': 'ALL',
1008 'symptomSetOperator': 'AND'}
1010 'adapterKindKey': 'VMWARE',
1011 'description': 'CPU_Utilization_Above_Threshold',
1014 'resourceKindKey': 'VirtualMachine',
1015 'subType': 19, 'waitCycles': 1,
1016 'id': 'AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444d',
1018 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
1021 #Call get_alarm_defination_by_name method under test
1022 alert_match_list
= self
.mon_plugin
.get_alarm_defination_by_name(alarm_name
)
1024 #Verify that mocked method is called
1025 m_get
.assert_called()
1027 #Verify return value with expected value
1028 self
.assertEqual(Exp_alert_match_list
, alert_match_list
)
1031 @mock.patch
.object(monPlugin
.requests
, 'get')
1032 def test_get_alarm_defination_by_name_no_valid_alarm_found(self
, m_get
):
1033 """Test get_alarm_defination_by_name: With no valid alarm found in returned list"""
1035 alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda5'
1037 #Set mocked function's return values
1038 m_get
.return_value
.status_code
= 200
1039 m_get
.return_value
.content
= '{"pageInfo": {"totalCount": 1,"page": 0,"pageSize": 1000},\
1041 {"href": "/suite-api/api/alertdefinitions?page=0&pageSize=1000",\
1042 "rel": "SELF","name": "current"},\
1043 {"href": "/suite-api/api/alertdefinitions?page=0&pageSize=1000",\
1044 "rel": "RELATED","name": "first"},\
1045 {"href": "/suite-api/api/alertdefinitions?page=0&pageSize=1000",\
1046 "rel": "RELATED","name": "last"}],\
1047 "alertDefinitions": [{\
1048 "id": "AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444d",\
1049 "name": "CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
1050 "description": "CPU_Utilization_Above_Threshold",\
1051 "adapterKindKey": "VMWARE","resourceKindKey": "VirtualMachine",\
1052 "waitCycles": 1,"cancelCycles": 1,"type": 16,"subType": 19,\
1053 "states": [{"impact": {"impactType": "BADGE","detail": "risk"},\
1054 "severity": "CRITICAL",\
1055 "base-symptom-set": {"type": "SYMPTOM_SET",\
1056 "relation": "SELF","aggregation": "ALL",\
1057 "symptomSetOperator": "AND",\
1058 "symptomDefinitionIds": [\
1059 "SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278"]}}]\
1062 #Expected return match list
1063 Exp_alert_match_list
= []
1065 #Call get_alarm_defination_by_name method under test
1066 alert_match_list
= self
.mon_plugin
.get_alarm_defination_by_name(alarm_name
)
1068 #Verify that mocked method is called
1069 m_get
.assert_called()
1071 #Verify return value with expected value
1072 self
.assertEqual(Exp_alert_match_list
, alert_match_list
)
1075 @mock.patch
.object(monPlugin
.requests
, 'put')
1076 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_symptom_defination_details')
1077 def test_update_symptom_defination_valid_symptom_req_response(self
,\
1078 m_get_symptom_defination_details
,\
1080 """Test update_symptom_defination: With valid REST response, update symptom"""
1082 #Expected symptom to be updated
1083 symptom_defination_id
= 'SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278'
1084 new_alarm_config
= {'severity':"CRITICAL",
1086 'threshold_value':5,
1087 'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'
1090 #Set mocked function's return values
1091 m_get_symptom_defination_details
.return_value
= {
1092 "id": "SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278",
1093 "name": "CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",
1094 "adapterKindKey": "VMWARE",
1095 "resourceKindKey": "VirtualMachine",
1098 "state": {"severity": "CRITICAL",
1100 "type": "CONDITION_HT",
1101 "key": "cpu|usage_average","operator": "GT","value": "0.0",
1102 "valueType": "NUMERIC","instanced": False,
1103 "thresholdType": "STATIC"}
1107 m_put
.return_value
.status_code
= 200
1108 m_put
.return_value
.content
= '{\
1109 "id":"SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278",\
1110 "name":"CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
1111 "adapterKindKey":"VMWARE","resourceKindKey":"VirtualMachine","waitCycles":1,\
1114 "severity":"CRITICAL",\
1116 "type":"CONDITION_HT","key":"cpu|usage_average","operator":"GT","value":"5.0",\
1117 "valueType":"NUMERIC","instanced":False,"thresholdType":"STATIC"}}}'
1119 #Call update_symptom_defination method under test
1120 symptom_uuid
= self
.mon_plugin
.update_symptom_defination(symptom_defination_id
,\
1123 #Verify that mocked method is called with required parameters
1124 m_get_symptom_defination_details
.assert_called_with(symptom_defination_id
)
1125 m_put
.assert_called()
1127 #Verify return value with expected value
1128 self
.assertEqual(symptom_defination_id
, symptom_uuid
)
1131 @mock.patch
.object(monPlugin
.requests
, 'put')
1132 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_symptom_defination_details')
1133 def test_update_symptom_defination_invalid_symptom_req_response(self
,\
1134 m_get_symptom_defination_details
,\
1136 """Test update_symptom_defination: If invalid REST response received, return None"""
1138 #Expected symptom to be updated
1139 symptom_defination_id
= 'SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278'
1140 new_alarm_config
= {'severity':"CRITICAL",
1142 'threshold_value':5,
1143 'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'
1146 #Set mocked function's return values
1147 m_get_symptom_defination_details
.return_value
= {
1148 "id": "SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278",
1149 "name": "CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",
1150 "adapterKindKey": "VMWARE",
1151 "resourceKindKey": "VirtualMachine",
1154 "state": {"severity": "CRITICAL",
1156 "type": "CONDITION_HT",
1157 "key": "cpu|usage_average","operator": "GT","value": "0.0",
1158 "valueType": "NUMERIC","instanced": False,
1159 "thresholdType": "STATIC"}
1163 m_put
.return_value
.status_code
= 500
1164 m_put
.return_value
.content
= '{\
1165 "message": "Internal Server error, cause unknown.",\
1166 "moreInformation": [\
1167 {"name": "errorMessage",\
1168 "value": "Symptom Definition CPU_Utilization_Above_Thr-e14b203c-\
1169 6bf2-4e2f-a91c-8c19d240eda4 does not exist and hence cannot be updated."},\
1170 {"name": "localizedMessage",\
1171 "value": "Symptom Definition CPU_Utilization_Above_Thr-e14b203c-\
1172 6bf2-4e2f-a91c-8c19d240eda4 does not exist and hence cannot be updated.;"}],\
1173 "httpStatusCode": 500,"apiErrorCode": 500}'
1175 #Call update_symptom_defination method under test
1176 symptom_uuid
= self
.mon_plugin
.update_symptom_defination(symptom_defination_id
,\
1179 #Verify that mocked method is called with required parameters
1180 m_get_symptom_defination_details
.assert_called_with(symptom_defination_id
)
1181 m_put
.assert_called()
1183 #Verify return value with expected value
1184 self
.assertEqual(symptom_uuid
, None)
1187 @mock.patch
.object(monPlugin
.requests
, 'put')
1188 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_symptom_defination_details')
1189 def test_update_symptom_defination_failed_to_get_symptom_defination(self
,\
1190 m_get_symptom_defination_details
,\
1192 """Test update_symptom_defination: if fails to get symptom_defination returns None"""
1194 #Expected symptom to be updated
1195 symptom_defination_id
= 'SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278'
1196 new_alarm_config
= {'severity':"CRITICAL",
1198 'threshold_value':5,
1199 'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'
1202 #Set mocked function's return values
1203 m_get_symptom_defination_details
.return_value
= None
1205 #Call update_symptom_defination method under test
1206 symptom_uuid
= self
.mon_plugin
.update_symptom_defination(symptom_defination_id
,\
1209 #Verify that mocked method is called with required parameters
1210 m_get_symptom_defination_details
.assert_called_with(symptom_defination_id
)
1211 m_put
.assert_not_called()
1213 #Verify return value with expected value
1214 self
.assertEqual(symptom_uuid
, None)
1217 @mock.patch
.object(monPlugin
.requests
, 'get')
1218 def test_get_symptom_defination_details_valid_req_response(self
,m_get
):
1219 """Test update_symptom_defination: With valid REST response symptom is created"""
1221 #Expected symptom to be updated
1222 symptom_uuid
= 'SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278'
1224 #Set mocked function's return values
1225 m_get
.return_value
.status_code
= 200
1226 m_get
.return_value
.content
= '{\
1227 "id": "SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278",\
1228 "name": "CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
1229 "adapterKindKey": "VMWARE","resourceKindKey": "VirtualMachine","waitCycles": 1,\
1230 "cancelCycles": 1,"state": {"severity": "CRITICAL","condition": {"type": "CONDITION_HT",\
1231 "key": "cpu|usage_average","operator": "GT","value": "6.0","valueType": "NUMERIC",\
1232 "instanced": false,"thresholdType": "STATIC"}}}'
1233 expected_symptom_details
= {\
1234 "id": "SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278",\
1235 "name": "CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
1236 "adapterKindKey": "VMWARE","resourceKindKey": "VirtualMachine","waitCycles": 1,\
1237 "cancelCycles": 1,"state": {"severity": "CRITICAL","condition": {"type": "CONDITION_HT",\
1238 "key": "cpu|usage_average","operator": "GT","value": "6.0","valueType": "NUMERIC",\
1239 "instanced": False,"thresholdType": "STATIC"}}}
1241 #Call update_symptom_defination method under test
1242 symptom_details
= self
.mon_plugin
.get_symptom_defination_details(symptom_uuid
)
1244 #Verify that mocked method is called with required parameters
1245 m_get
.assert_called()
1247 #Verify return value with expected value
1248 self
.assertEqual(expected_symptom_details
, symptom_details
)
1251 @mock.patch
.object(monPlugin
.requests
, 'get')
1252 def test_get_symptom_defination_details_invalid_req_response(self
,m_get
):
1253 """Test update_symptom_defination: if invalid REST response received return None"""
1255 #Expected symptom to be updated
1256 symptom_uuid
= 'SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278'
1258 #Set mocked function's return values
1259 m_get
.return_value
.status_code
= 404
1260 m_get
.return_value
.content
= '{"message": "No such SymptomDefinition\
1261 - SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278.",\
1262 "httpStatusCode": 404,"apiErrorCode": 404}'
1264 expected_symptom_details
= None
1266 #Call update_symptom_defination method under test
1267 symptom_details
= self
.mon_plugin
.get_symptom_defination_details(symptom_uuid
)
1269 #Verify that mocked method is called with required parameters
1270 m_get
.assert_called()
1272 #Verify return value with expected value
1273 self
.assertEqual(expected_symptom_details
, symptom_details
)
1276 @mock.patch
.object(monPlugin
.requests
, 'get')
1277 def test_get_symptom_defination_details_symptom_uuid_not_provided(self
,m_get
):
1278 """Test update_symptom_defination: if required symptom uuid is not provided"""
1280 #Expected symptom to be updated
1282 expected_symptom_details
= None
1284 #Call update_symptom_defination method under test
1285 symptom_details
= self
.mon_plugin
.get_symptom_defination_details(symptom_uuid
)
1287 #Verify that mocked method is called with required parameters
1288 m_get
.assert_not_called()
1290 #Verify return value with expected value
1291 self
.assertEqual(expected_symptom_details
, symptom_details
)
1294 @mock.patch
.object(monPlugin
.requests
, 'put')
1295 def test_reconfigure_alarm_valid_req_response(self
, m_put
):
1296 """Test reconfigure_alarm: for valid REST response"""
1298 #Set input parameters to reconfigure_alarm
1299 alarm_details_json
= {
1300 'id': 'AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444d',
1301 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
1302 'description': 'CPU_Utilization_Above_Threshold', 'adapterKindKey': 'VMWARE',
1303 'states':[{'impact':{'impactType':'BADGE', 'detail':'risk'}, 'severity':'CRITICAL',
1304 'base-symptom-set':{
1305 'symptomDefinitionIds':['SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278'],
1306 'relation': 'SELF','type': 'SYMPTOM_SET', 'aggregation':'ALL',
1307 'symptomSetOperator': 'AND'}}],
1308 'type': 16, 'cancelCycles': 1, 'resourceKindKey': 'VirtualMachine','subType': 19,
1311 new_alarm_config
= {'severity':'WARNING',
1312 'description': 'CPU_Utilization_Above_Threshold_Warning'}
1314 #Set mocked function's return values
1315 m_put
.return_value
.status_code
= 200
1316 m_put
.return_value
.content
= '{"id":"AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444d",\
1317 "name":"CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
1318 "description":"CPU_Utilization_Above_Threshold_Warning","adapterKindKey":"VMWARE",\
1319 "resourceKindKey":"VirtualMachine","waitCycles":1,"cancelCycles":1,"type":16,\
1320 "subType":19,"states":[{"severity":"WARNING","base-symptom-set":{"type":"SYMPTOM_SET",\
1321 "relation":"SELF","aggregation":"ALL","symptomSetOperator":"AND",\
1322 "symptomDefinitionIds":["SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278"]},\
1323 "impact":{"impactType":"BADGE","detail":"risk"}}]}'
1325 #Expected alarm_def_uuid to be returned
1326 expected_alarm_def_uuid
= '9a6d8a14-9f25-4d81-bf91-4d773497444d'
1328 #Call reconfigure_alarm method under test
1329 alarm_def_uuid
= self
.mon_plugin
.reconfigure_alarm(alarm_details_json
, new_alarm_config
)
1331 #Verify that mocked method is called with required parameters
1332 m_put
.assert_called()
1334 #Verify return value with expected value
1335 self
.assertEqual(expected_alarm_def_uuid
, alarm_def_uuid
)
1338 @mock.patch
.object(monPlugin
.requests
, 'put')
1339 def test_reconfigure_alarm_invalid_req_response(self
, m_put
):
1340 """Test reconfigure_alarm: for invalid REST response, return None"""
1342 #Set input parameters to reconfigure_alarm
1343 alarm_details_json
= {
1344 'id': 'AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444d',
1345 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
1346 'description': 'CPU_Utilization_Above_Threshold', 'adapterKindKey': 'VMWARE',
1347 'states':[{'impact':{'impactType':'BADGE', 'detail':'risk'}, 'severity':'CRITICAL',
1348 'base-symptom-set':{
1349 'symptomDefinitionIds':['SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278'],
1350 'relation': 'SELF','type': 'SYMPTOM_SET', 'aggregation':'ALL',
1351 'symptomSetOperator': 'AND'}}],
1352 'type': 16, 'cancelCycles': 1, 'resourceKindKey': 'VirtualMachine','subType': 19,
1355 new_alarm_config
= {'severity':'WARNING',
1356 'description': 'CPU_Utilization_Above_Threshold_Warning'}
1358 #Set mocked function's return values
1359 m_put
.return_value
.status_code
= 500
1360 m_put
.return_value
.content
= '{"message": "Internal Server error, cause unknown.",\
1361 "moreInformation": [{"name": "errorMessage",\
1362 "value": "Cannot update Alert Definition CPU_Utilization_Above_Thr-\
1363 e14b203c-6bf2-4e2f-a91c-8c19d240eda4 since it does not exist"},\
1364 {"name": "localizedMessage",\
1365 "value": "Cannot update Alert Definition CPU_Utilization_Above_Thr-\
1366 e14b203c-6bf2-4e2f-a91c-8c19d240eda4 since it does not exist;"}],\
1367 "httpStatusCode": 500,"apiErrorCode": 500}'
1369 #Expected alarm_def_uuid to be returned
1370 expected_alarm_def_uuid
= None
1372 #Call reconfigure_alarm method under test
1373 alarm_def_uuid
= self
.mon_plugin
.reconfigure_alarm(alarm_details_json
, new_alarm_config
)
1375 #Verify that mocked method is called with required parameters
1376 m_put
.assert_called()
1378 #Verify return value with expected value
1379 self
.assertEqual(expected_alarm_def_uuid
, alarm_def_uuid
)
1382 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_symptom_definition')
1383 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_alarm_defination')
1384 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_notification_rule')
1385 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_details')
1386 def test_delete_alarm_configuration_successful_alarm_deletion(self
,\
1387 m_get_alarm_defination_details
,\
1388 m_delete_notification_rule
,\
1389 m_delete_alarm_defination
,\
1390 m_delete_symptom_definition
):
1391 """Test delete_alarm_configuration: for successful alarm deletion, return alarm uuid"""
1393 #Set input parameters to delete_alarm_configuration
1394 delete_alarm_req_dict
= {'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'}
1396 #Set mocked function's return values
1397 alarm_details_json
= {
1398 'id': 'AlertDefinition-9a6d8a14-9f25-4d81-4d773497444d',
1399 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4',
1400 'symptomDefinitionIds':['SymptomDefinition-bcc2cb36-a67b-4deb-9b5884973278']}
1402 'alarm_name':'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4',
1403 'alarm_id':'AlertDefinition-9a6d8a14-9f25-4d81-4d773497444d',
1404 'symptom_definition_id':'SymptomDefinition-bcc2cb36-a67b-4deb-9b5884973278'}
1406 m_get_alarm_defination_details
.return_value
= (alarm_details_json
, alarm_details
)
1407 m_delete_notification_rule
.return_value
= '989e7293-d78d-4405-92e30ec4f247'
1408 m_delete_alarm_defination
.return_value
= alarm_details
['alarm_id']
1409 m_delete_symptom_definition
.return_value
= alarm_details
['symptom_definition_id']
1411 #Call reconfigure_alarm method under test
1412 alarm_uuid
= self
.mon_plugin
.delete_alarm_configuration(delete_alarm_req_dict
)
1414 #Verify that mocked method is called with required parameters
1415 m_get_alarm_defination_details
.assert_called_with(delete_alarm_req_dict
['alarm_uuid'])
1416 m_delete_notification_rule
.assert_called_with(alarm_details
['alarm_name'])
1417 m_delete_alarm_defination
.assert_called_with(alarm_details
['alarm_id'])
1418 m_delete_symptom_definition
.assert_called_with(alarm_details
['symptom_definition_id'])
1420 #Verify return value with expected value
1421 self
.assertEqual(alarm_uuid
, delete_alarm_req_dict
['alarm_uuid'])
1424 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_symptom_definition')
1425 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_alarm_defination')
1426 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_notification_rule')
1427 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_details')
1428 def test_delete_alarm_configuration_failed_to_get_alarm_defination(self
,\
1429 m_get_alarm_defination_details
,\
1430 m_delete_notification_rule
,\
1431 m_delete_alarm_defination
,\
1432 m_delete_symptom_definition
):
1433 """Test delete_alarm_configuration: if failed to get alarm definition, return None"""
1435 #Set input parameters to delete_alarm_configuration
1436 delete_alarm_req_dict
= {'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'}
1438 #Set mocked function's return values
1439 alarm_details_json
= None
1440 alarm_details
= None
1442 m_get_alarm_defination_details
.return_value
= (alarm_details_json
, alarm_details
)
1444 #Call reconfigure_alarm method under test
1445 alarm_uuid
= self
.mon_plugin
.delete_alarm_configuration(delete_alarm_req_dict
)
1447 #Verify that mocked method is called with required parameters
1448 m_get_alarm_defination_details
.assert_called_with(delete_alarm_req_dict
['alarm_uuid'])
1449 m_delete_notification_rule
.assert_not_called()
1450 m_delete_alarm_defination
.assert_not_called()
1451 m_delete_symptom_definition
.assert_not_called()
1453 #Verify return value with expected value
1454 self
.assertEqual(alarm_uuid
, None)
1457 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_symptom_definition')
1458 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_alarm_defination')
1459 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_notification_rule')
1460 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_details')
1461 def test_delete_alarm_configuration_failed_to_delete_notification_rule(self
,\
1462 m_get_alarm_defination_details
,\
1463 m_delete_notification_rule
,\
1464 m_delete_alarm_defination
,\
1465 m_delete_symptom_definition
):
1466 """Test delete_alarm_configuration: if failed to delete notification rule, return None"""
1468 #Set input parameters to delete_alarm_configuration
1469 delete_alarm_req_dict
= {'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'}
1471 #Set mocked function's return values
1472 alarm_details_json
= {
1473 'id': 'AlertDefinition-9a6d8a14-9f25-4d81-4d773497444d',
1474 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4',
1475 'symptomDefinitionIds':['SymptomDefinition-bcc2cb36-a67b-4deb-9b5884973278']}
1477 'alarm_name':'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4',
1478 'alarm_id':'AlertDefinition-9a6d8a14-9f25-4d81-4d773497444d',
1479 'symptom_definition_id':'SymptomDefinition-bcc2cb36-a67b-4deb-9b5884973278'}
1481 m_get_alarm_defination_details
.return_value
= (alarm_details_json
, alarm_details
)
1482 m_delete_notification_rule
.return_value
= None
1484 #Call reconfigure_alarm method under test
1485 alarm_uuid
= self
.mon_plugin
.delete_alarm_configuration(delete_alarm_req_dict
)
1487 #Verify that mocked method is called with required parameters
1488 m_get_alarm_defination_details
.assert_called_with(delete_alarm_req_dict
['alarm_uuid'])
1489 m_delete_notification_rule
.assert_called_with(alarm_details
['alarm_name'])
1490 m_delete_alarm_defination
.assert_not_called()
1491 m_delete_symptom_definition
.assert_not_called()
1493 #Verify return value with expected value
1494 self
.assertEqual(alarm_uuid
, None)
1497 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_symptom_definition')
1498 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_alarm_defination')
1499 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_notification_rule')
1500 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_details')
1501 def test_delete_alarm_configuration_failed_to_delete_alarm_defination(self
,\
1502 m_get_alarm_defination_details
,\
1503 m_delete_notification_rule
,\
1504 m_delete_alarm_defination
,\
1505 m_delete_symptom_definition
):
1506 """Test delete_alarm_configuration: if failed to delete alarm definition, return None"""
1508 #Set input parameters to delete_alarm_configuration
1509 delete_alarm_req_dict
= {'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'}
1511 #Set mocked function's return values
1512 alarm_details_json
= {
1513 'id': 'AlertDefinition-9a6d8a14-9f25-4d81-4d773497444d',
1514 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4',
1515 'symptomDefinitionIds':['SymptomDefinition-bcc2cb36-a67b-4deb-9b5884973278']}
1517 'alarm_name':'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4',
1518 'alarm_id':'AlertDefinition-9a6d8a14-9f25-4d81-4d773497444d',
1519 'symptom_definition_id':'SymptomDefinition-bcc2cb36-a67b-4deb-9b5884973278'}
1521 m_get_alarm_defination_details
.return_value
= (alarm_details_json
, alarm_details
)
1522 m_delete_notification_rule
.return_value
= '989e7293-d78d-4405-92e30ec4f247'
1523 m_delete_alarm_defination
.return_value
= None
1525 #Call reconfigure_alarm method under test
1526 alarm_uuid
= self
.mon_plugin
.delete_alarm_configuration(delete_alarm_req_dict
)
1528 #Verify that mocked method is called with required parameters
1529 m_get_alarm_defination_details
.assert_called_with(delete_alarm_req_dict
['alarm_uuid'])
1530 m_delete_notification_rule
.assert_called_with(alarm_details
['alarm_name'])
1531 m_delete_alarm_defination
.assert_called_with(alarm_details
['alarm_id'])
1532 m_delete_symptom_definition
.assert_not_called()
1534 #Verify return value with expected value
1535 self
.assertEqual(alarm_uuid
, None)
1538 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_symptom_definition')
1539 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_alarm_defination')
1540 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_notification_rule')
1541 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_details')
1542 def test_delete_alarm_configuration_failed_to_delete_symptom_definition(self
,\
1543 m_get_alarm_defination_details
,\
1544 m_delete_notification_rule
,\
1545 m_delete_alarm_defination
,\
1546 m_delete_symptom_definition
):
1547 """Test delete_alarm_configuration: if failed to delete symptom definition, return None"""
1549 #Set input parameters to delete_alarm_configuration
1550 delete_alarm_req_dict
= {'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'}
1552 #Set mocked function's return values
1553 alarm_details_json
= {
1554 'id': 'AlertDefinition-9a6d8a14-9f25-4d81-4d773497444d',
1555 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4',
1556 'symptomDefinitionIds':['SymptomDefinition-bcc2cb36-a67b-4deb-9b5884973278']}
1558 'alarm_name':'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4',
1559 'alarm_id':'AlertDefinition-9a6d8a14-9f25-4d81-4d773497444d',
1560 'symptom_definition_id':'SymptomDefinition-bcc2cb36-a67b-4deb-9b5884973278'}
1562 m_get_alarm_defination_details
.return_value
= (alarm_details_json
, alarm_details
)
1563 m_delete_notification_rule
.return_value
= '989e7293-d78d-4405-92e30ec4f247'
1564 m_delete_alarm_defination
.return_value
= alarm_details
['alarm_id']
1565 m_delete_symptom_definition
.return_value
= None
1567 #Call reconfigure_alarm method under test
1568 alarm_uuid
= self
.mon_plugin
.delete_alarm_configuration(delete_alarm_req_dict
)
1570 #Verify that mocked method is called with required parameters
1571 m_get_alarm_defination_details
.assert_called_with(delete_alarm_req_dict
['alarm_uuid'])
1572 m_delete_notification_rule
.assert_called_with(alarm_details
['alarm_name'])
1573 m_delete_alarm_defination
.assert_called_with(alarm_details
['alarm_id'])
1574 m_delete_symptom_definition
.assert_called_with(alarm_details
['symptom_definition_id'])
1576 #Verify return value with expected value
1577 self
.assertEqual(alarm_uuid
, None)
1580 @mock.patch
.object(monPlugin
.requests
, 'delete')
1581 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_notification_rule_id_by_alarm_name')
1582 def test_delete_notification_rule_successful_deletion_req_response(self
,\
1583 m_get_notification_rule_id_by_alarm_name
,\
1585 """Test delete_notification_rule: Valid notification rule is deleted & returns rule_id"""
1587 #Set input parameters to delete_notification_rule
1588 alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4'
1590 #Set mocked function's return values
1591 m_get_notification_rule_id_by_alarm_name
.return_value
= '8db86441-71d8-4830-9e1a-a90be3776d12'
1592 m_delete
.return_value
.status_code
= 204
1594 #Call delete_notification_rule method under test
1595 rule_id
= self
.mon_plugin
.delete_notification_rule(alarm_name
)
1597 #Verify that mocked method is called with required parameters
1598 m_get_notification_rule_id_by_alarm_name
.assert_called_with(alarm_name
)
1599 m_delete
.assert_called()
1601 #Verify return value with expected value
1602 self
.assertEqual(rule_id
, '8db86441-71d8-4830-9e1a-a90be3776d12')
1605 @mock.patch
.object(monPlugin
.requests
, 'delete')
1606 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_notification_rule_id_by_alarm_name')
1607 def test_delete_notification_rule_failed_to_get_notification_rule_id(self
,\
1608 m_get_notification_rule_id_by_alarm_name
,\
1610 """Test delete_notification_rule: if notification rule is not found, returns None"""
1612 #Set input parameters to delete_notification_rule
1613 alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4'
1615 #Set mocked function's return values
1616 m_get_notification_rule_id_by_alarm_name
.return_value
= None
1618 #Call delete_notification_rule method under test
1619 rule_id
= self
.mon_plugin
.delete_notification_rule(alarm_name
)
1621 #Verify that mocked method is called with required parameters
1622 m_get_notification_rule_id_by_alarm_name
.assert_called_with(alarm_name
)
1623 m_delete
.assert_not_called()
1625 # verify return value with expected value
1626 self
.assertEqual(rule_id
, None)
1629 @mock.patch
.object(monPlugin
.requests
, 'delete')
1630 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_notification_rule_id_by_alarm_name')
1631 def test_delete_notification_rule_invalid_deletion_req_response(self
,\
1632 m_get_notification_rule_id_by_alarm_name
,\
1634 """Test delete_notification_rule: If an invalid response is received, returns None"""
1636 #Set input parameters to delete_notification_rule
1637 alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4'
1639 #Set mocked function's return values
1640 m_get_notification_rule_id_by_alarm_name
.return_value
= '8db86441-71d8-4830-9e1a-a90be3776d12'
1641 m_delete
.return_value
.status_code
= 404
1643 #Call delete_notification_rule method under test
1644 rule_id
= self
.mon_plugin
.delete_notification_rule(alarm_name
)
1646 #Verify that mocked method is called with required parameters
1647 m_get_notification_rule_id_by_alarm_name
.assert_called_with(alarm_name
)
1648 m_delete
.assert_called()
1650 #Verify return value with expected value
1651 self
.assertEqual(rule_id
, None)
1654 @mock.patch
.object(monPlugin
.requests
, 'get')
1655 def test_get_notification_rule_id_by_alarm_name_valid_req_response(self
,m_get
):
1656 """Test get_notification_rule_id_by_alarm_name: A valid request response received,
1657 returns notification_id
1660 #Set input parameters to get_notification_rule_id_by_alarm_name
1661 alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
1663 #Set mocked function's return values
1664 m_get
.return_value
.status_code
= 200
1665 m_get
.return_value
.content
= '{\
1666 "pageInfo": {"totalCount": 0,"page": 0,"pageSize": 1000},\
1668 {"href": "/suite-api/api/notifications/rules?page=0&pageSize=1000",\
1669 "rel": "SELF","name": "current"},\
1670 {"href": "/suite-api/api/notifications/rules?page=0&pageSize=1000",\
1671 "rel": "RELATED","name": "first"},\
1672 {"href": "/suite-api/api/notifications/rules?page=0&pageSize=1000",\
1673 "rel": "RELATED","name": "last"}],\
1674 "notification-rule": [{\
1675 "id": "2b86fa23-0c15-445c-a2b1-7bd725c46f59",\
1676 "name": "notify_CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
1677 "pluginId": "03053f51-f829-438d-993d-cc33a435d76a",\
1678 "links": [{"href": "/suite-api/api/notifications/rules/2b86fa23-0c15-445c-a2b1-7bd725c46f59",\
1679 "rel": "SELF","name": "linkToSelf"}]}]}'
1681 #Call get_notification_rule_id_by_alarm_name method under test
1682 notification_id
= self
.mon_plugin
.get_notification_rule_id_by_alarm_name(alarm_name
)
1684 #Verify that mocked method is called with required parameters
1685 m_get
.assert_called()
1687 #Verify return value with expected value
1688 self
.assertEqual(notification_id
, '2b86fa23-0c15-445c-a2b1-7bd725c46f59')
1691 @mock.patch
.object(monPlugin
.requests
, 'get')
1692 def test_get_notification_rule_id_by_alarm_name_invalid_req_response(self
,m_get
):
1693 """Test get_notification_rule_id_by_alarm_name: If an invalid response received,\
1697 #Set input parameters to delete_alarm_configuration
1698 alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
1700 #Set mocked function's return values
1701 m_get
.return_value
.status_code
= 404
1703 #Call get_notification_rule_id_by_alarm_name method under test
1704 notification_id
= self
.mon_plugin
.get_notification_rule_id_by_alarm_name(alarm_name
)
1706 #Verify that mocked method is called with required parameters
1707 m_get
.assert_called()
1709 #Verify return value with expected value
1710 self
.assertEqual(notification_id
, None)
1713 @mock.patch
.object(monPlugin
.requests
, 'get')
1714 def est_get_notification_rule_id_by_alarm_name_rule_not_found(self
,m_get
):
1715 """Test get_notification_rule_id_by_alarm_name: If a notification rule is not found,
1719 #Set input parameters to delete_alarm_configuration
1720 alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda'
1722 #Set mocked function's return values
1723 m_get
.return_value
.status_code
= 200
1724 m_get
.return_value
.content
= '{\
1725 "pageInfo": {"totalCount": 0,"page": 0,"pageSize": 1000},\
1727 {"href": "/suite-api/api/notifications/rules?page=0&pageSize=1000",\
1728 "rel": "SELF","name": "current"},\
1729 {"href": "/suite-api/api/notifications/rules?page=0&pageSize=1000",\
1730 "rel": "RELATED","name": "first"},\
1731 {"href": "/suite-api/api/notifications/rules?page=0&pageSize=1000",\
1732 "rel": "RELATED","name": "last"}],\
1733 "notification-rule": [{\
1734 "id": "2b86fa23-0c15-445c-a2b1-7bd725c46f59",\
1735 "name": "notify_CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
1736 "pluginId": "03053f51-f829-438d-993d-cc33a435d76a",\
1737 "links": [{"href": "/suite-api/api/notifications/rules/2b86fa23-0c15-445c-a2b1-7bd725c46f59",\
1738 "rel": "SELF","name": "linkToSelf"}]}]}'
1740 #Call get_notification_rule_id_by_alarm_name method under test
1741 notification_id
= self
.mon_plugin
.get_notification_rule_id_by_alarm_name(alarm_name
)
1743 #Verify that mocked method is called with required parameters
1744 m_get
.assert_called()
1746 #Verify return value with expected value
1747 self
.assertEqual(notification_id
, None)
1750 @mock.patch
.object(monPlugin
.requests
, 'delete')
1751 def test_delete_alarm_defination_valid_req_response(self
,m_delete
):
1752 """Test delete_alarm_defination: A valid request response received,
1756 #Set input parameters to delete_alarm_definition
1757 alarm_definition_id
= 'AlertDefinition-9a6d8a14-9f25-4d81-4d773497444d'
1759 #Set mocked function's return values
1760 m_delete
.return_value
.status_code
= 204
1762 #Call delete_alarm_defination method under test
1763 actual_alarm_id
= self
.mon_plugin
.delete_alarm_defination(alarm_definition_id
)
1765 #Verify that mocked method is called with required parameters
1766 m_delete
.assert_called()
1768 #Verify return value with expected value
1769 self
.assertEqual(actual_alarm_id
, alarm_definition_id
)
1772 @mock.patch
.object(monPlugin
.requests
, 'delete')
1773 def test_delete_alarm_defination_invalid_req_response(self
,m_delete
):
1774 """Test delete_alarm_defination: If an invalid request response received,
1778 #Set input parameters to delete_alarm_definition
1779 alarm_definition_id
= 'AlertDefinition-9a6d8a14-9f25-4d81-4d773497444d'
1781 #Set mocked function's return values
1782 m_delete
.return_value
.status_code
= 404
1784 #Call delete_alarm_defination method under test
1785 actual_alarm_id
= self
.mon_plugin
.delete_alarm_defination(alarm_definition_id
)
1787 #Verify that mocked method is called with required parameters
1788 m_delete
.assert_called()
1790 #Verify return value with expected value
1791 self
.assertEqual(actual_alarm_id
, None)
1794 @mock.patch
.object(monPlugin
.requests
, 'delete')
1795 def test_delete_symptom_definition_valid_req_response(self
,m_delete
):
1796 """Test delete_symptom_definition: A valid request response received,
1800 #Set input parameters to delete_symptom_definition
1801 symptom_definition_id
= 'SymptomDefinition-bcc2cb36-a67b-4deb-9b5884973278'
1803 #Set mocked function's return values
1804 m_delete
.return_value
.status_code
= 204
1806 #Call delete_symptom_definition method under test
1807 actual_symptom_id
= self
.mon_plugin
.delete_symptom_definition(symptom_definition_id
)
1809 #Verify that mocked method is called with required parameters
1810 m_delete
.assert_called()
1812 #Verify return value with expected value
1813 self
.assertEqual(actual_symptom_id
, symptom_definition_id
)
1816 @mock.patch
.object(monPlugin
.requests
, 'delete')
1817 def test_delete_symptom_definition_invalid_req_response(self
,m_delete
):
1818 """Test delete_symptom_definition: If an invalid request response received,
1822 #Set input parameters to delete_symptom_definition
1823 symptom_definition_id
= 'SymptomDefinition-bcc2cb36-a67b-4deb-9b5884973278'
1825 #Set mocked function's return values
1826 m_delete
.return_value
.status_code
= 404
1828 #Call delete_symptom_definition method under test
1829 actual_symptom_id
= self
.mon_plugin
.delete_symptom_definition(symptom_definition_id
)
1831 #Verify that mocked method is called with required parameters
1832 m_delete
.assert_called()
1834 #Verify return value with expected value
1835 self
.assertEqual(actual_symptom_id
, None)
1838 # For testing purpose
1839 #if __name__ == '__main__':