Merge "Additional mock tests for vROPs plugin"
[osm/MON.git] / osm_mon / test / VMware / test_mon_plugin_vrops.py
1 # -*- coding: utf-8 -*-
2
3 ##
4 # Copyright 2017-2018 VMware Inc.
5 # This file is part of ETSI OSM
6 # All Rights Reserved.
7 #
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
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
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
18 # under the License.
19 #
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact: osslegalrouting@vmware.com
22 ##
23
24 """ Mock tests for VMware vROPs Mon plugin """
25
26 import sys
27
28 import json
29
30 import logging
31
32 import unittest
33
34 import mock
35
36 import requests
37
38 import os
39
40 log = logging.getLogger(__name__)
41
42 sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)),"..","..",".."))
43
44 from osm_mon.plugins.vRealiseOps import mon_plugin_vrops as monPlugin
45
46
47 class TestMonPlugin(unittest.TestCase):
48 """Test class for vROPs Mon Plugin class methods"""
49
50 def setUp(self):
51 """Setup the tests for plugin_receiver class methods"""
52 super(TestMonPlugin, self).setUp()
53 self.mon_plugin = monPlugin.MonPlugin()
54
55
56 def test_get_default_Params_valid_metric_alarm_name(self):
57 """Test get default params method"""
58
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': '%'}
65
66 # call get default param function under test
67 actual_return = self.mon_plugin.get_default_Params(metric_alarm_name)
68
69 #Verify return value with expected value
70 self.assertEqual(exepcted_return, actual_return)
71
72
73 def test_get_default_Params_invalid_metric_alarm_name(self):
74 """Test get default params method-invalid metric alarm"""
75
76 # Mock valid metric_alarm_name and response
77 metric_alarm_name = "Invalid_Alarm"
78 exepcted_return = {}
79
80 # call get default param function under test
81 actual_return = self.mon_plugin.get_default_Params(metric_alarm_name)
82
83 #Verify return value with expected value
84 self.assertEqual(exepcted_return, actual_return)
85
86
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"""
90
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'}
96
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"}}}'
104
105 exepcted_return = "SymptomDefinition-351c23b4-bc3c-4c7b-b4af-1ad90a673c5d"
106
107 # call create symptom method under test
108 actual_return = self.mon_plugin.create_symptom(symptom_param)
109
110 #Verify that mocked method is called
111 m_post.assert_called()
112
113 #Verify return value with expected value
114 self.assertEqual(exepcted_return, actual_return)
115
116
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"""
120
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'}
126
127 m_post.return_value.status_code = 404
128 m_post.return_value.content = '404 Not Found'
129
130 exepcted_return = None
131
132 # call create symptom method under test
133 actual_return = self.mon_plugin.create_symptom(symptom_param)
134
135 #Verify that mocked method is called
136 m_post.assert_called()
137
138 #Verify return value with expected value
139 self.assertEqual(exepcted_return, actual_return)
140
141
142 @mock.patch.object(monPlugin.requests, 'post')
143 def test_create_symptom_incorrect_data(self, m_post):
144 """Test create symptom method-incorrect data"""
145
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'}
151
152 exepcted_return = None
153
154 # call create symptom method under test
155 actual_return = self.mon_plugin.create_symptom(symptom_param)
156
157 #Verify that mocked method is not called
158 m_post.assert_not_called()
159
160 #Verify return value with expected value
161 self.assertEqual(exepcted_return, actual_return)
162
163
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"""
167
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}
173
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"}}]}'
183
184 exepcted_return = "AlertDefinition-d4f21e4b-770a-45d6-b298-022eaf489115"
185
186 # call create alarm definition method under test
187 actual_return = self.mon_plugin.create_alarm_definition(alarm_param)
188
189 # verify that mocked method is called
190 m_post.assert_called()
191
192 # verify return value with expected value
193 self.assertEqual(exepcted_return, actual_return)
194
195
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"""
199
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}
205
206 m_post.return_value.status_code = 404
207 m_post.return_value.content = '404 Not Found'
208
209 exepcted_return = None
210
211 # call create alarm definition method under test
212 actual_return = self.mon_plugin.create_alarm_definition(alarm_param)
213
214 # verify that mocked method is called
215 m_post.assert_called()
216
217 # verify return value with expected value
218 self.assertEqual(exepcted_return, actual_return)
219
220
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"""
224
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}
229
230 exepcted_return = None
231
232 # call create symptom method under test
233 actual_return = self.mon_plugin.create_alarm_definition(alarm_param)
234
235 # verify that mocked method is not called
236 m_post.assert_not_called()
237
238 # verify return value with expected value
239 self.assertEqual(exepcted_return, actual_return)
240
241
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,\
251 m_create_symptom,\
252 m_create_alarm_definition,\
253 m_get_vm_moref_id,\
254 m_get_vm_resource_id,\
255 m_create_alarm_notification_rule):
256 """Test configure alarm valid request creating alarm"""
257
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'}
266
267 #symptom parameters to be passed for symptom creation
268 symptom_params = {'threshold_value': 0,
269 'cancel_cycles': 1,
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',
274 'operation': 'GT',
275 'wait_cycles': 1,
276 'metric_key': 'cpu|usage_average'}
277
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',
286 'type': 16}
287
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'
293
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': '%'}
304 ]
305
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'
313
314 #Call configure_alarm method under test
315 return_value = self.mon_plugin.configure_alarm(config_dict)
316
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)
325
326 #Verify return value with expected value of alarm_def_uuid
327 self.assertEqual(return_value, alarm_def_uuid)
328
329
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,\
339 m_create_symptom,\
340 m_create_alarm_definition,\
341 m_get_vm_moref_id,\
342 m_get_vm_resource_id,\
343 m_create_alarm_notification_rule):
344 """Test configure alarm invalid test: for invalid alarm name"""
345
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'}
354
355 alarm_def_uuid = None
356
357 #Mock default Parameters return value to None
358 m_get_default_Params.return_value = {}
359
360 #Call configure_alarm method under test
361 return_value = self.mon_plugin.configure_alarm(config_dict)
362
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()
371
372 #Verify return value with expected value i.e. None
373 self.assertEqual(return_value, alarm_def_uuid)
374
375
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,\
385 m_create_symptom,\
386 m_create_alarm_definition,\
387 m_get_vm_moref_id,\
388 m_get_vm_resource_id,\
389 m_create_alarm_notification_rule):
390 """Test configure alarm invalid test: for invalid metric name"""
391
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'}
400
401 alarm_def_uuid = None
402
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'},
412 {}
413 ]
414
415 #Call configure_alarm method under test
416 return_value = self.mon_plugin.configure_alarm(config_dict)
417
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()
426
427 #Verify return value with expected value i.e. None
428 self.assertEqual(return_value, alarm_def_uuid)
429
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,\
439 m_create_symptom,\
440 m_create_alarm_definition,\
441 m_get_vm_moref_id,\
442 m_get_vm_resource_id,\
443 m_create_alarm_notification_rule):
444 """Test configure alarm invalid test: for alarm that already exists"""
445
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'}
454
455 vrops_alarm_name = 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
456 alarm_def_uuid = None
457
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': '%'}
468 ]
469 #set mocked function return value
470 m_get_alarm_defination_by_name.return_value = ['mocked_alarm_CPU_Utilization_Above_Thr']
471
472
473 #Call configure_alarm method under test
474 return_value = self.mon_plugin.configure_alarm(config_dict)
475
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()
484
485 #Verify return value with expected value of alarm_def_uuid
486 self.assertEqual(return_value, alarm_def_uuid)
487
488
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,\
498 m_create_symptom,\
499 m_create_alarm_definition,\
500 m_get_vm_moref_id,\
501 m_get_vm_resource_id,\
502 m_create_alarm_notification_rule):
503 """Test configure alarm: failed to create symptom"""
504
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'}
513
514 #symptom parameters to be passed for symptom creation
515 symptom_params = {'threshold_value': 0,
516 'cancel_cycles': 1,
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',
521 'operation': 'GT',
522 'wait_cycles': 1,
523 'metric_key': 'cpu|usage_average'}
524 vrops_alarm_name = 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
525 alarm_def_uuid = None
526
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': '%'}
537 ]
538 #set mocked function return values
539 m_get_alarm_defination_by_name.return_value = []
540 m_create_symptom.return_value = None
541
542 #Call configure_alarm method under test
543 return_value = self.mon_plugin.configure_alarm(config_dict)
544
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()
553
554 #Verify return value with expected value of alarm_def_uuid
555 self.assertEqual(return_value, alarm_def_uuid)
556
557
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,\
567 m_create_symptom,\
568 m_create_alarm_definition,\
569 m_get_vm_moref_id,\
570 m_get_vm_resource_id,\
571 m_create_alarm_notification_rule):
572 """Test configure alarm: failed to create alert in vROPs"""
573
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'}
582
583 #symptom parameters to be passed for symptom creation
584 symptom_params = {'threshold_value': 0,
585 'cancel_cycles': 1,
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',
590 'operation': 'GT',
591 'wait_cycles': 1,
592 'metric_key': 'cpu|usage_average'}
593
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',
602 'type': 16}
603
604 vrops_alarm_name = 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
605 alarm_def_uuid = None
606
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': '%'}
617 ]
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
622
623 #Call configure_alarm method under test
624 return_value = self.mon_plugin.configure_alarm(config_dict)
625
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()
634
635 #Verify return value with expected value of alarm_def_uuid
636 self.assertEqual(return_value, alarm_def_uuid)
637
638
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,\
648 m_create_symptom,\
649 m_create_alarm_definition,\
650 m_get_vm_moref_id,\
651 m_get_vm_resource_id,\
652 m_create_alarm_notification_rule):
653 """Test configure alarm: failed to get vm_moref_id"""
654
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'}
663
664 #symptom parameters to be passed for symptom creation
665 symptom_params = {'threshold_value': 0,
666 'cancel_cycles': 1,
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',
671 'operation': 'GT',
672 'wait_cycles': 1,
673 'metric_key': 'cpu|usage_average'}
674
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',
683 'type': 16}
684
685 vrops_alarm_name = 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
686 alarm_def_uuid = None
687
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': '%'}
698 ]
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
704
705 #Call configure_alarm method under test
706 return_value = self.mon_plugin.configure_alarm(config_dict)
707
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()
716
717 #Verify return value with expected value of alarm_def_uuid
718 self.assertEqual(return_value, alarm_def_uuid)
719
720
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,\
730 m_create_symptom,\
731 m_create_alarm_definition,\
732 m_get_vm_moref_id,\
733 m_get_vm_resource_id,\
734 m_create_alarm_notification_rule):
735 """Test configure alarm: failed to get vm resource_id"""
736
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'}
745
746 #symptom parameters to be passed for symptom creation
747 symptom_params = {'threshold_value': 0,
748 'cancel_cycles': 1,
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',
753 'operation': 'GT',
754 'wait_cycles': 1,
755 'metric_key': 'cpu|usage_average'}
756
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',
765 'type': 16}
766
767 vrops_alarm_name = 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
768 vm_moref_id = 'vm-6626'
769 alarm_def_uuid = None
770
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': '%'}
781 ]
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
788
789 #Call configure_alarm method under test
790 return_value = self.mon_plugin.configure_alarm(config_dict)
791
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()
800
801 #Verify return value with expected value of alarm_def_uuid
802 self.assertEqual(return_value, alarm_def_uuid)
803
804
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,\
814 m_create_symptom,\
815 m_create_alarm_definition,\
816 m_get_vm_moref_id,\
817 m_get_vm_resource_id,\
818 m_create_alarm_notification_rule):
819 """Test configure alarm: failed to create alarm notification rule"""
820
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'}
829
830 #symptom parameters to be passed for symptom creation
831 symptom_params = {'threshold_value': 0,
832 'cancel_cycles': 1,
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',
837 'operation': 'GT',
838 'wait_cycles': 1,
839 'metric_key': 'cpu|usage_average'}
840
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',
849 'type': 16}
850
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
856
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': '%'}
867 ]
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
875
876 #Call configure_alarm method under test
877 return_value = self.mon_plugin.configure_alarm(config_dict)
878
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)
887
888 #Verify return value with expected value of alarm_def_uuid
889 self.assertEqual(return_value, alarm_def_uuid)
890
891
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"""
895
896 alarm_uuid = '9a6d8a14-9f25-4d81-bf91-4d773497444d'
897
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"}}]}'
909
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}
915
916 expected_alarm_details_json = {'states':
917 [{'impact':
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'}
929
930 #Call get_alarm_defination_details method under test
931 alarm_details_json, alarm_details = self.mon_plugin.get_alarm_defination_details(alarm_uuid)
932
933 #Verify that mocked method is called
934 m_get.assert_called()
935
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)
939
940
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"""
944
945 alarm_uuid = '9a6d8a14-9f25-4d81-bf91-4d773497444d'
946
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}'
952
953 expected_alarm_details = None
954 expected_alarm_details_json = None
955
956 #Call get_alarm_defination_details method under test
957 alarm_details_json, alarm_details = self.mon_plugin.get_alarm_defination_details(alarm_uuid)
958
959 #verify that mocked method is called
960 m_get.assert_called()
961
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)
965
966
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"""
970
971 alarm_name = 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
972
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},\
976 "links": [\
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"]}}]\
996 }]}'
997
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'],
1005 'relation': 'SELF',
1006 'type': 'SYMPTOM_SET',
1007 'aggregation': 'ALL',
1008 'symptomSetOperator': 'AND'}
1009 }],
1010 'adapterKindKey': 'VMWARE',
1011 'description': 'CPU_Utilization_Above_Threshold',
1012 'type': 16,
1013 'cancelCycles': 1,
1014 'resourceKindKey': 'VirtualMachine',
1015 'subType': 19, 'waitCycles': 1,
1016 'id': 'AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444d',
1017 'name': \
1018 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
1019 }]
1020
1021 #Call get_alarm_defination_by_name method under test
1022 alert_match_list = self.mon_plugin.get_alarm_defination_by_name(alarm_name)
1023
1024 #Verify that mocked method is called
1025 m_get.assert_called()
1026
1027 #Verify return value with expected value
1028 self.assertEqual(Exp_alert_match_list, alert_match_list)
1029
1030
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"""
1034
1035 alarm_name = 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda5'
1036
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},\
1040 "links": [\
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"]}}]\
1060 }]}'
1061
1062 #Expected return match list
1063 Exp_alert_match_list = []
1064
1065 #Call get_alarm_defination_by_name method under test
1066 alert_match_list = self.mon_plugin.get_alarm_defination_by_name(alarm_name)
1067
1068 #Verify that mocked method is called
1069 m_get.assert_called()
1070
1071 #Verify return value with expected value
1072 self.assertEqual(Exp_alert_match_list, alert_match_list)
1073
1074
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,\
1079 m_put):
1080 """Test update_symptom_defination: With valid REST response, update symptom"""
1081
1082 #Expected symptom to be updated
1083 symptom_defination_id = 'SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278'
1084 new_alarm_config = {'severity':"CRITICAL",
1085 'operation': 'GT',
1086 'threshold_value':5,
1087 'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'
1088 }
1089
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",
1096 "waitCycles": 1,
1097 "cancelCycles": 1,
1098 "state": {"severity": "CRITICAL",
1099 "condition": {
1100 "type": "CONDITION_HT",
1101 "key": "cpu|usage_average","operator": "GT","value": "0.0",
1102 "valueType": "NUMERIC","instanced": False,
1103 "thresholdType": "STATIC"}
1104 }
1105 }
1106
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,\
1112 "cancelCycles":1,\
1113 "state":{\
1114 "severity":"CRITICAL",\
1115 "condition":{\
1116 "type":"CONDITION_HT","key":"cpu|usage_average","operator":"GT","value":"5.0",\
1117 "valueType":"NUMERIC","instanced":False,"thresholdType":"STATIC"}}}'
1118
1119 #Call update_symptom_defination method under test
1120 symptom_uuid = self.mon_plugin.update_symptom_defination(symptom_defination_id,\
1121 new_alarm_config)
1122
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()
1126
1127 #Verify return value with expected value
1128 self.assertEqual(symptom_defination_id, symptom_uuid)
1129
1130
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,\
1135 m_put):
1136 """Test update_symptom_defination: If invalid REST response received, return None"""
1137
1138 #Expected symptom to be updated
1139 symptom_defination_id = 'SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278'
1140 new_alarm_config = {'severity':"CRITICAL",
1141 'operation': 'GT',
1142 'threshold_value':5,
1143 'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'
1144 }
1145
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",
1152 "waitCycles": 1,
1153 "cancelCycles": 1,
1154 "state": {"severity": "CRITICAL",
1155 "condition": {
1156 "type": "CONDITION_HT",
1157 "key": "cpu|usage_average","operator": "GT","value": "0.0",
1158 "valueType": "NUMERIC","instanced": False,
1159 "thresholdType": "STATIC"}
1160 }
1161 }
1162
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}'
1174
1175 #Call update_symptom_defination method under test
1176 symptom_uuid = self.mon_plugin.update_symptom_defination(symptom_defination_id,\
1177 new_alarm_config)
1178
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()
1182
1183 #Verify return value with expected value
1184 self.assertEqual(symptom_uuid, None)
1185
1186
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,\
1191 m_put):
1192 """Test update_symptom_defination: if fails to get symptom_defination returns None"""
1193
1194 #Expected symptom to be updated
1195 symptom_defination_id = 'SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278'
1196 new_alarm_config = {'severity':"CRITICAL",
1197 'operation': 'GT',
1198 'threshold_value':5,
1199 'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'
1200 }
1201
1202 #Set mocked function's return values
1203 m_get_symptom_defination_details.return_value = None
1204
1205 #Call update_symptom_defination method under test
1206 symptom_uuid = self.mon_plugin.update_symptom_defination(symptom_defination_id,\
1207 new_alarm_config)
1208
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()
1212
1213 #Verify return value with expected value
1214 self.assertEqual(symptom_uuid, None)
1215
1216
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"""
1220
1221 #Expected symptom to be updated
1222 symptom_uuid = 'SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278'
1223
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"}}}
1240
1241 #Call update_symptom_defination method under test
1242 symptom_details = self.mon_plugin.get_symptom_defination_details(symptom_uuid)
1243
1244 #Verify that mocked method is called with required parameters
1245 m_get.assert_called()
1246
1247 #Verify return value with expected value
1248 self.assertEqual(expected_symptom_details, symptom_details)
1249
1250
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"""
1254
1255 #Expected symptom to be updated
1256 symptom_uuid = 'SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278'
1257
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}'
1263
1264 expected_symptom_details = None
1265
1266 #Call update_symptom_defination method under test
1267 symptom_details = self.mon_plugin.get_symptom_defination_details(symptom_uuid)
1268
1269 #Verify that mocked method is called with required parameters
1270 m_get.assert_called()
1271
1272 #Verify return value with expected value
1273 self.assertEqual(expected_symptom_details, symptom_details)
1274
1275
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"""
1279
1280 #Expected symptom to be updated
1281 symptom_uuid = None
1282 expected_symptom_details = None
1283
1284 #Call update_symptom_defination method under test
1285 symptom_details = self.mon_plugin.get_symptom_defination_details(symptom_uuid)
1286
1287 #Verify that mocked method is called with required parameters
1288 m_get.assert_not_called()
1289
1290 #Verify return value with expected value
1291 self.assertEqual(expected_symptom_details, symptom_details)
1292
1293
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"""
1297
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,
1309 'waitCycles': 1}
1310
1311 new_alarm_config = {'severity':'WARNING',
1312 'description': 'CPU_Utilization_Above_Threshold_Warning'}
1313
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"}}]}'
1324
1325 #Expected alarm_def_uuid to be returned
1326 expected_alarm_def_uuid = '9a6d8a14-9f25-4d81-bf91-4d773497444d'
1327
1328 #Call reconfigure_alarm method under test
1329 alarm_def_uuid = self.mon_plugin.reconfigure_alarm(alarm_details_json, new_alarm_config)
1330
1331 #Verify that mocked method is called with required parameters
1332 m_put.assert_called()
1333
1334 #Verify return value with expected value
1335 self.assertEqual(expected_alarm_def_uuid, alarm_def_uuid)
1336
1337
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"""
1341
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,
1353 'waitCycles': 1}
1354
1355 new_alarm_config = {'severity':'WARNING',
1356 'description': 'CPU_Utilization_Above_Threshold_Warning'}
1357
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}'
1368
1369 #Expected alarm_def_uuid to be returned
1370 expected_alarm_def_uuid = None
1371
1372 #Call reconfigure_alarm method under test
1373 alarm_def_uuid = self.mon_plugin.reconfigure_alarm(alarm_details_json, new_alarm_config)
1374
1375 #Verify that mocked method is called with required parameters
1376 m_put.assert_called()
1377
1378 #Verify return value with expected value
1379 self.assertEqual(expected_alarm_def_uuid, alarm_def_uuid)
1380
1381
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"""
1392
1393 #Set input parameters to delete_alarm_configuration
1394 delete_alarm_req_dict = {'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'}
1395
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']}
1401 alarm_details = {
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'}
1405
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']
1410
1411 #Call reconfigure_alarm method under test
1412 alarm_uuid = self.mon_plugin.delete_alarm_configuration(delete_alarm_req_dict)
1413
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'])
1419
1420 #Verify return value with expected value
1421 self.assertEqual(alarm_uuid, delete_alarm_req_dict['alarm_uuid'])
1422
1423
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"""
1434
1435 #Set input parameters to delete_alarm_configuration
1436 delete_alarm_req_dict = {'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'}
1437
1438 #Set mocked function's return values
1439 alarm_details_json = None
1440 alarm_details = None
1441
1442 m_get_alarm_defination_details.return_value = (alarm_details_json, alarm_details)
1443
1444 #Call reconfigure_alarm method under test
1445 alarm_uuid = self.mon_plugin.delete_alarm_configuration(delete_alarm_req_dict)
1446
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()
1452
1453 #Verify return value with expected value
1454 self.assertEqual(alarm_uuid, None)
1455
1456
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"""
1467
1468 #Set input parameters to delete_alarm_configuration
1469 delete_alarm_req_dict = {'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'}
1470
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']}
1476 alarm_details = {
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'}
1480
1481 m_get_alarm_defination_details.return_value = (alarm_details_json, alarm_details)
1482 m_delete_notification_rule.return_value = None
1483
1484 #Call reconfigure_alarm method under test
1485 alarm_uuid = self.mon_plugin.delete_alarm_configuration(delete_alarm_req_dict)
1486
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()
1492
1493 #Verify return value with expected value
1494 self.assertEqual(alarm_uuid, None)
1495
1496
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"""
1507
1508 #Set input parameters to delete_alarm_configuration
1509 delete_alarm_req_dict = {'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'}
1510
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']}
1516 alarm_details = {
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'}
1520
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
1524
1525 #Call reconfigure_alarm method under test
1526 alarm_uuid = self.mon_plugin.delete_alarm_configuration(delete_alarm_req_dict)
1527
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()
1533
1534 #Verify return value with expected value
1535 self.assertEqual(alarm_uuid, None)
1536
1537
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"""
1548
1549 #Set input parameters to delete_alarm_configuration
1550 delete_alarm_req_dict = {'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'}
1551
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']}
1557 alarm_details = {
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'}
1561
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
1566
1567 #Call reconfigure_alarm method under test
1568 alarm_uuid = self.mon_plugin.delete_alarm_configuration(delete_alarm_req_dict)
1569
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'])
1575
1576 #Verify return value with expected value
1577 self.assertEqual(alarm_uuid, None)
1578
1579
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,\
1584 m_delete):
1585 """Test delete_notification_rule: Valid notification rule is deleted & returns rule_id"""
1586
1587 #Set input parameters to delete_notification_rule
1588 alarm_name = 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4'
1589
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
1593
1594 #Call delete_notification_rule method under test
1595 rule_id = self.mon_plugin.delete_notification_rule(alarm_name)
1596
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()
1600
1601 #Verify return value with expected value
1602 self.assertEqual(rule_id, '8db86441-71d8-4830-9e1a-a90be3776d12')
1603
1604
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,\
1609 m_delete):
1610 """Test delete_notification_rule: if notification rule is not found, returns None"""
1611
1612 #Set input parameters to delete_notification_rule
1613 alarm_name = 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4'
1614
1615 #Set mocked function's return values
1616 m_get_notification_rule_id_by_alarm_name.return_value = None
1617
1618 #Call delete_notification_rule method under test
1619 rule_id = self.mon_plugin.delete_notification_rule(alarm_name)
1620
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()
1624
1625 # verify return value with expected value
1626 self.assertEqual(rule_id, None)
1627
1628
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,\
1633 m_delete):
1634 """Test delete_notification_rule: If an invalid response is received, returns None"""
1635
1636 #Set input parameters to delete_notification_rule
1637 alarm_name = 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4'
1638
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
1642
1643 #Call delete_notification_rule method under test
1644 rule_id = self.mon_plugin.delete_notification_rule(alarm_name)
1645
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()
1649
1650 #Verify return value with expected value
1651 self.assertEqual(rule_id, None)
1652
1653
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
1658 """
1659
1660 #Set input parameters to get_notification_rule_id_by_alarm_name
1661 alarm_name = 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
1662
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},\
1667 "links": [\
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"}]}]}'
1680
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)
1683
1684 #Verify that mocked method is called with required parameters
1685 m_get.assert_called()
1686
1687 #Verify return value with expected value
1688 self.assertEqual(notification_id, '2b86fa23-0c15-445c-a2b1-7bd725c46f59')
1689
1690
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,\
1694 returns None
1695 """
1696
1697 #Set input parameters to delete_alarm_configuration
1698 alarm_name = 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
1699
1700 #Set mocked function's return values
1701 m_get.return_value.status_code = 404
1702
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)
1705
1706 #Verify that mocked method is called with required parameters
1707 m_get.assert_called()
1708
1709 #Verify return value with expected value
1710 self.assertEqual(notification_id, None)
1711
1712
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,
1716 returns None
1717 """
1718
1719 #Set input parameters to delete_alarm_configuration
1720 alarm_name = 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda'
1721
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},\
1726 "links": [\
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"}]}]}'
1739
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)
1742
1743 #Verify that mocked method is called with required parameters
1744 m_get.assert_called()
1745
1746 #Verify return value with expected value
1747 self.assertEqual(notification_id, None)
1748
1749
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,
1753 returns symptom_id
1754 """
1755
1756 #Set input parameters to delete_alarm_definition
1757 alarm_definition_id = 'AlertDefinition-9a6d8a14-9f25-4d81-4d773497444d'
1758
1759 #Set mocked function's return values
1760 m_delete.return_value.status_code = 204
1761
1762 #Call delete_alarm_defination method under test
1763 actual_alarm_id = self.mon_plugin.delete_alarm_defination(alarm_definition_id)
1764
1765 #Verify that mocked method is called with required parameters
1766 m_delete.assert_called()
1767
1768 #Verify return value with expected value
1769 self.assertEqual(actual_alarm_id, alarm_definition_id)
1770
1771
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,
1775 returns None
1776 """
1777
1778 #Set input parameters to delete_alarm_definition
1779 alarm_definition_id = 'AlertDefinition-9a6d8a14-9f25-4d81-4d773497444d'
1780
1781 #Set mocked function's return values
1782 m_delete.return_value.status_code = 404
1783
1784 #Call delete_alarm_defination method under test
1785 actual_alarm_id = self.mon_plugin.delete_alarm_defination(alarm_definition_id)
1786
1787 #Verify that mocked method is called with required parameters
1788 m_delete.assert_called()
1789
1790 #Verify return value with expected value
1791 self.assertEqual(actual_alarm_id, None)
1792
1793
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,
1797 returns symptom_id
1798 """
1799
1800 #Set input parameters to delete_symptom_definition
1801 symptom_definition_id = 'SymptomDefinition-bcc2cb36-a67b-4deb-9b5884973278'
1802
1803 #Set mocked function's return values
1804 m_delete.return_value.status_code = 204
1805
1806 #Call delete_symptom_definition method under test
1807 actual_symptom_id = self.mon_plugin.delete_symptom_definition(symptom_definition_id)
1808
1809 #Verify that mocked method is called with required parameters
1810 m_delete.assert_called()
1811
1812 #Verify return value with expected value
1813 self.assertEqual(actual_symptom_id, symptom_definition_id)
1814
1815
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,
1819 returns None
1820 """
1821
1822 #Set input parameters to delete_symptom_definition
1823 symptom_definition_id = 'SymptomDefinition-bcc2cb36-a67b-4deb-9b5884973278'
1824
1825 #Set mocked function's return values
1826 m_delete.return_value.status_code = 404
1827
1828 #Call delete_symptom_definition method under test
1829 actual_symptom_id = self.mon_plugin.delete_symptom_definition(symptom_definition_id)
1830
1831 #Verify that mocked method is called with required parameters
1832 m_delete.assert_called()
1833
1834 #Verify return value with expected value
1835 self.assertEqual(actual_symptom_id, None)
1836
1837
1838 # For testing purpose
1839 #if __name__ == '__main__':
1840 # unittest.main()
1841
1842