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 sys
.path
.append(os
.path
.join(os
.path
.dirname(os
.path
.abspath(__file__
)),"..","..",".."))
42 from osm_mon
.plugins
.vRealiseOps
import mon_plugin_vrops
as monPlugin
44 from pyvcloud
.vcd
.client
import Client
,BasicLoginCredentials
47 class TestMonPlugin(unittest
.TestCase
):
48 """Test class for vROPs Mon Plugin class methods"""
51 """Setup the tests for Mon Plugin class methods"""
52 super(TestMonPlugin
, self
).setUp()
54 self
.m_vim_access_config
= {'vrops_site':'abc',
56 'vrops_password':'passwd',
58 'admin_username':'admin',
59 'admin_password':'admin_passwd',
61 'tenant_id':'org_vdc_1'}
62 self
.mon_plugin
= monPlugin
.MonPlugin(self
.m_vim_access_config
)
63 # create client object
64 self
.vca
= Client('test', verify_ssl_certs
=False)
66 self
.session
= requests
.Session()
69 def test_get_default_Params_valid_metric_alarm_name(self
):
70 """Test get default params method"""
72 # Mock valid metric_alarm_name and response
73 metric_alarm_name
= "Average_Memory_Usage_Above_Threshold"
74 expected_return
= {'impact': 'risk', 'cancel_cycles': 2, 'adapter_kind': 'VMWARE',
75 'repeat': False,'cancel_period': 300, 'alarm_type': 16,
76 'vrops_alarm': 'Avg_Mem_Usage_Above_Thr','enabled': True, 'period': 300,
77 'resource_kind': 'VirtualMachine', 'alarm_subType': 19,
78 'action': 'acknowledge', 'evaluation': 2, 'unit': '%'}
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(expected_return
, actual_return
)
87 def test_get_default_Params_invalid_metric_alarm_name(self
):
88 """Test get default params method invalid metric alarm"""
90 # Mock valid metric_alarm_name and response
91 metric_alarm_name
= "Invalid_Alarm"
94 # call get default param function under test
95 actual_return
= self
.mon_plugin
.get_default_Params(metric_alarm_name
)
97 # verify return value with expected value
98 self
.assertEqual(expected_return
, actual_return
)
101 @mock.patch
.object(monPlugin
.requests
, 'post')
102 def test_create_symptom_valid_req_response(self
, m_post
):
103 """Test create symptom method-valid request"""
105 # Mock valid symptom params and mock responses
106 symptom_param
= {'threshold_value': 0, 'cancel_cycles': 1, 'adapter_kind_key': 'VMWARE',
107 'resource_kind_key': 'VirtualMachine', 'severity': 'CRITICAL',
109 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
110 'operation': 'GT', 'wait_cycles': 1, 'metric_key': 'cpu|usage_average'}
112 m_post
.return_value
.status_code
= 201
113 m_post
.return_value
.content
= \
114 '{"id":"SymptomDefinition-351c23b4-bc3c-4c7b-b4af-1ad90a673c5d",\
115 "name":"CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
116 "adapterKindKey":"VMWARE","resourceKindKey":"VirtualMachine",\
117 "waitCycles":1,"cancelCycles":1,\
118 "state":{"severity":"CRITICAL","condition":{"type":"CONDITION_HT",\
119 "key":"cpu|usage_average","operator":"GT","value":"0.0",\
120 "valueType":"NUMERIC",\
121 "instanced":false,"thresholdType":"STATIC"}}}'
123 expected_return
= "SymptomDefinition-351c23b4-bc3c-4c7b-b4af-1ad90a673c5d"
125 # call create symptom method under test
126 actual_return
= self
.mon_plugin
.create_symptom(symptom_param
)
128 # verify that mocked method is called
129 m_post
.assert_called()
131 # verify return value with expected value
132 self
.assertEqual(expected_return
, actual_return
)
135 @mock.patch
.object(monPlugin
.requests
, 'post')
136 def test_create_symptom_invalid_req_response(self
, m_post
):
137 """Test create symptom method-invalid response"""
139 # Mock valid symptom params and invalid mock responses
140 symptom_param
= {'threshold_value': 0, 'cancel_cycles': 1, 'adapter_kind_key': 'VMWARE',
141 'resource_kind_key': 'VirtualMachine', 'severity': 'CRITICAL',
143 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
144 'operation': 'GT', 'wait_cycles': 1, 'metric_key': 'cpu|usage_average'}
146 m_post
.return_value
.status_code
= 404
147 m_post
.return_value
.content
= '404 Not Found'
149 expected_return
= None
151 # call create symptom method under test
152 actual_return
= self
.mon_plugin
.create_symptom(symptom_param
)
154 # verify that mocked method is called
155 m_post
.assert_called()
157 # verify return value with expected value
158 self
.assertEqual(expected_return
, actual_return
)
161 @mock.patch
.object(monPlugin
.requests
, 'post')
162 def test_create_symptom_incorrect_data(self
, m_post
):
163 """Test create symptom method-incorrect data"""
165 # Mock valid symptom params and invalid mock responses
166 symptom_param
= {'threshold_value': 0, 'cancel_cycles': 1, 'adapter_kind_key': 'VMWARE',
167 'resource_kind_key': 'VirtualMachine', 'severity': 'CRITICAL',
169 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
170 'operation': 'GT', 'metric_key': 'cpu|usage_average'}
172 expected_return
= None
174 # call create symptom method under test
175 actual_return
= self
.mon_plugin
.create_symptom(symptom_param
)
177 # verify that mocked method is not called
178 m_post
.assert_not_called()
180 # verify return value with expected value
181 self
.assertEqual(expected_return
, actual_return
)
184 @mock.patch
.object(monPlugin
.requests
, 'post')
185 def test_create_alarm_definition_valid_req_response(self
, m_post
):
186 """Test create alarm definition method-valid response"""
188 # Mock valid alarm params and mock responses
189 alarm_param
= {'description': 'CPU_Utilization_Above_Threshold', 'cancelCycles': 1,
190 'subType': 19, 'waitCycles': 1,
191 'severity': 'CRITICAL', 'impact': 'risk', 'adapterKindKey': 'VMWARE',
192 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
193 'resourceKindKey': 'VirtualMachine', 'type': 16,
194 'symptomDefinitionId':\
195 'SymptomDefinition-25278b06-bff8-4409-a141-9b4e064235df'}
197 m_post
.return_value
.status_code
= 201
198 m_post
.return_value
.content
= \
199 '{"id":"AlertDefinition-d4f21e4b-770a-45d6-b298-022eaf489115",\
200 "name":"CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
201 "description":"CPU_Utilization_Above_Threshold","adapterKindKey":"VMWARE",\
202 "resourceKindKey":"VirtualMachine","waitCycles":1,"cancelCycles":1,\
203 "type":16,"subType":19,\
204 "states":[{"severity":"CRITICAL","base-symptom-set":{"type":"SYMPTOM_SET",\
205 "relation":"SELF","aggregation":"ALL","symptomSetOperator":"AND",\
206 "symptomDefinitionIds":\
207 ["SymptomDefinition-25278b06-bff8-4409-a141-9b4e064235df"]},\
208 "impact":{"impactType":"BADGE","detail":"risk"}}]}'
210 expected_return
= "AlertDefinition-d4f21e4b-770a-45d6-b298-022eaf489115"
212 # call create alarm definition method under test
213 actual_return
= self
.mon_plugin
.create_alarm_definition(alarm_param
)
215 # verify that mocked method is called
216 m_post
.assert_called()
218 # verify return value with expected value
219 self
.assertEqual(expected_return
, actual_return
)
222 @mock.patch
.object(monPlugin
.requests
, 'post')
223 def test_create_alarm_definition_invalid_req_response(self
, m_post
):
224 """Test create alarm definition method-invalid response"""
226 # Mock valid alarm params and mock responses
227 alarm_param
= {'description': 'CPU_Utilization_Above_Threshold', 'cancelCycles': 1,
228 'subType': 19, 'waitCycles': 1,
229 'severity': 'CRITICAL', 'impact': 'risk', 'adapterKindKey': 'VMWARE',
230 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
231 'resourceKindKey': 'VirtualMachine', 'type': 16,
232 'symptomDefinitionId':\
233 'SymptomDefinition-25278b06-bff8-4409-a141-9b4e064235df'}
235 m_post
.return_value
.status_code
= 404
236 m_post
.return_value
.content
= '404 Not Found'
238 expected_return
= None
240 # call create alarm definition method under test
241 actual_return
= self
.mon_plugin
.create_alarm_definition(alarm_param
)
243 # verify that mocked method is called
244 m_post
.assert_called()
246 # verify return value with expected value
247 self
.assertEqual(expected_return
, actual_return
)
250 @mock.patch
.object(monPlugin
.requests
, 'post')
251 def test_create_alarm_definition_incorrect_data(self
, m_post
):
252 """Test create alarm definition method-incorrect data"""
254 # Mock incorrect alarm param
255 alarm_param
= {'description': 'CPU_Utilization_Above_Threshold', 'cancelCycles': 1,
256 'subType': 19, 'waitCycles': 1, 'type': 16,
257 'severity': 'CRITICAL', 'impact': 'risk', 'adapterKindKey': 'VMWARE',
258 'symptomDefinitionId':\
259 'SymptomDefinition-25278b06-bff8-4409-a141-9b4e064235df'}
260 expected_return
= None
262 # call create symptom method under test
263 actual_return
= self
.mon_plugin
.create_alarm_definition(alarm_param
)
265 # verify that mocked method is not called
266 m_post
.assert_not_called()
268 # verify return value with expected value
269 self
.assertEqual(expected_return
, actual_return
)
272 @mock.patch
.object(monPlugin
.DatabaseManager
, 'save_alarm')
273 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_notification_rule')
274 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
275 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
276 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_definition')
277 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_symptom')
278 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_by_name')
279 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
280 def test_configure_alarm_valid_req(self
, m_get_default_Params
,\
281 m_get_alarm_defination_by_name
,\
283 m_create_alarm_definition
,\
285 m_get_vm_resource_id
,\
286 m_create_alarm_notification_rule
,\
289 """Test configure alarm valid request creating alarm"""
291 #Mock input configuration dictionary
292 config_dict
= {'threshold_value': 0, 'severity': 'CRITICAL',
293 'alarm_name': 'CPU_Utilization_Above_Threshold',
294 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
295 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
296 'statistic': 'AVERAGE', 'metric_name': 'cpu_utilization',
297 'vdu_name':'vdu1','vnf_member_index':'index1','ns_id':'nsd1',
298 'operation': 'GT', 'unit': '%',
299 'description': 'CPU_Utilization_Above_Threshold'}
301 #symptom parameters to be passed for symptom creation
302 symptom_params
= {'threshold_value': 0,
304 'adapter_kind_key': 'VMWARE',
305 'resource_kind_key': 'VirtualMachine',
306 'severity': 'CRITICAL',
308 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
311 'metric_key': 'cpu|usage_average'}
313 #alarm parameters to be passed for alarm creation
314 alarm_params
= {'description': 'CPU_Utilization_Above_Threshold',
315 'cancelCycles': 1, 'subType': 19,
316 'waitCycles': 1, 'severity': 'CRITICAL',
317 'impact': 'risk', 'adapterKindKey': 'VMWARE',
318 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
319 'resourceKindKey': 'VirtualMachine',
320 'symptomDefinitionId':\
321 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804',
324 vm_moref_id
= 'vm-6626'
325 vrops_alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
326 alarm_def
= 'AlertDefinition-0f3cdcb3-4e1b-4a0b-86d0-66d4b3f65220'
327 resource_id
= 'ac87622f-b761-40a0-b151-00872a2a456e'
328 alarm_def_uuid
= '0f3cdcb3-4e1b-4a0b-86d0-66d4b3f65220'
330 #Mock default Parameters for alarm & metric configuration
331 m_get_default_Params
.side_effect
= [{'impact': 'risk', 'cancel_cycles': 1,
332 'adapter_kind': 'VMWARE', 'repeat': False,
333 'cancel_period': 300, 'alarm_type': 16,
334 'vrops_alarm': 'CPU_Utilization_Above_Thr',
335 'enabled': True, 'period': 300,
336 'resource_kind': 'VirtualMachine',
337 'alarm_subType': 19, 'action': 'acknowledge',
338 'evaluation': 1, 'unit': 'msec'},
339 {'metric_key': 'cpu|usage_average', 'unit': '%'}
342 #set mocked function return values
343 m_get_alarm_defination_by_name
.return_value
= []
344 m_create_symptom
.return_value
= 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804'
345 m_create_alarm_definition
.return_value
=\
346 'AlertDefinition-0f3cdcb3-4e1b-4a0b-86d0-66d4b3f65220'
347 m_get_vm_moref_id
.return_value
= vm_moref_id
348 m_get_vm_resource_id
.return_value
= 'ac87622f-b761-40a0-b151-00872a2a456e'
349 m_create_alarm_notification_rule
.return_value
= 'f37900e7-dd01-4383-b84c-08f519530d71'
351 #Call configure_alarm method under test
352 return_value
= self
.mon_plugin
.configure_alarm(config_dict
)
354 #Verify that mocked methods are called with correct parameters
355 self
.assertEqual(m_get_default_Params
.call_count
, 2)
356 m_get_alarm_defination_by_name
.assert_called_with(vrops_alarm_name
)
357 m_create_symptom
.assert_called_with(symptom_params
)
358 m_create_alarm_definition
.assert_called_with(alarm_params
)
359 m_get_vm_moref_id
.assert_called_with(config_dict
['resource_uuid'])
360 m_get_vm_resource_id
.assert_called_with(vm_moref_id
)
361 m_create_alarm_notification_rule
.assert_called_with(vrops_alarm_name
,\
364 m_save_alarm
.assert_called_with(alarm_def_uuid
,'1',
365 config_dict
['threshold_value'],
366 config_dict
['operation'],
367 config_dict
['metric_name'],
368 config_dict
['vdu_name'],
369 config_dict
['vnf_member_index'],
370 config_dict
['ns_id'])
372 #Verify return value with expected value of alarm_def_uuid
373 self
.assertEqual(return_value
, alarm_def_uuid
)
376 @mock.patch
.object(monPlugin
.DatabaseManager
, 'save_alarm')
377 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_notification_rule')
378 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
379 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
380 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_definition')
381 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_symptom')
382 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_by_name')
383 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
384 def test_configure_alarm_invalid_alarm_name_req(self
, m_get_default_Params
,\
385 m_get_alarm_defination_by_name
,\
387 m_create_alarm_definition
,\
389 m_get_vm_resource_id
,\
390 m_create_alarm_notification_rule
,\
392 """Test configure alarm invalid test: for invalid alarm name"""
394 #Mock input configuration dictionary
395 config_dict
= {'threshold_value': 0, 'severity': 'CRITICAL',
396 'alarm_name': 'CPU_Utilization_Above_Threshold',
397 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
398 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
399 'statistic': 'AVERAGE', 'metric_name': 'CPU_UTILIZATION',
400 'operation': 'GT', 'unit': '%',
401 'description': 'CPU_Utilization_Above_Threshold'}
403 alarm_def_uuid
= None
405 #Mock default Parameters return value to None
406 m_get_default_Params
.return_value
= {}
408 #Call configure_alarm method under test
409 return_value
= self
.mon_plugin
.configure_alarm(config_dict
)
411 #Verify that mocked methods are called with correct parameters
412 m_get_default_Params
.assert_called_with(config_dict
['alarm_name'])
413 m_get_alarm_defination_by_name
.assert_not_called()
414 m_create_symptom
.assert_not_called()
415 m_create_alarm_definition
.assert_not_called()
416 m_get_vm_moref_id
.assert_not_called()
417 m_get_vm_resource_id
.assert_not_called()
418 m_create_alarm_notification_rule
.assert_not_called()
419 m_save_alarm
.assert_not_called()
421 #Verify return value with expected value i.e. None
422 self
.assertEqual(return_value
, alarm_def_uuid
)
425 @mock.patch
.object(monPlugin
.DatabaseManager
, 'save_alarm')
426 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_notification_rule')
427 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
428 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
429 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_definition')
430 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_symptom')
431 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_by_name')
432 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
433 def test_configure_alarm_invalid_metric_name_req(self
, m_get_default_Params
,\
434 m_get_alarm_defination_by_name
,\
436 m_create_alarm_definition
,\
438 m_get_vm_resource_id
,\
439 m_create_alarm_notification_rule
,\
441 """Test configure alarm invalid test: for invalid metric name"""
443 #Mock input configuration dictionary
444 config_dict
= {'threshold_value': 0, 'severity': 'CRITICAL',
445 'alarm_name': 'CPU_Utilization_Above_Threshold',
446 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
447 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
448 'statistic': 'AVERAGE', 'metric_name': 'CPU_UTILIZATION',
449 'operation': 'GT', 'unit': '%',
450 'description': 'CPU_Utilization_Above_Threshold'}
452 alarm_def_uuid
= None
454 #Mock default Parameters return values for metrics to None
455 m_get_default_Params
.side_effect
= [{'impact': 'risk', 'cancel_cycles': 1,
456 'adapter_kind': 'VMWARE', 'repeat': False,
457 'cancel_period': 300, 'alarm_type': 16,
458 'vrops_alarm': 'CPU_Utilization_Above_Thr',
459 'enabled': True, 'period': 300,
460 'resource_kind': 'VirtualMachine',
461 'alarm_subType': 19, 'action': 'acknowledge',
462 'evaluation': 1, 'unit': 'msec'},
466 #Call configure_alarm method under test
467 return_value
= self
.mon_plugin
.configure_alarm(config_dict
)
469 #Verify that mocked methods are called with correct parameters
470 self
.assertEqual(m_get_default_Params
.call_count
, 2)
471 m_get_alarm_defination_by_name
.assert_not_called()
472 m_create_symptom
.assert_not_called()
473 m_create_alarm_definition
.assert_not_called()
474 m_get_vm_moref_id
.assert_not_called()
475 m_get_vm_resource_id
.assert_not_called()
476 m_create_alarm_notification_rule
.assert_not_called()
477 m_save_alarm
.assert_not_called()
479 #Verify return value with expected value i.e. None
480 self
.assertEqual(return_value
, alarm_def_uuid
)
483 @mock.patch
.object(monPlugin
.DatabaseManager
, 'save_alarm')
484 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_notification_rule')
485 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
486 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
487 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_definition')
488 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_symptom')
489 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_by_name')
490 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
491 def test_configure_alarm_invalid_already_exists(self
, m_get_default_Params
,\
492 m_get_alarm_defination_by_name
,\
494 m_create_alarm_definition
,\
496 m_get_vm_resource_id
,\
497 m_create_alarm_notification_rule
,\
499 """Test configure alarm invalid test: for alarm that already exists"""
501 #Mock input configuration dictionary
502 config_dict
= {'threshold_value': 0, 'severity': 'CRITICAL',
503 'alarm_name': 'CPU_Utilization_Above_Threshold',
504 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
505 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
506 'statistic': 'AVERAGE', 'metric_name': 'CPU_UTILIZATION',
507 'operation': 'GT', 'unit': '%',
508 'description': 'CPU_Utilization_Above_Threshold'}
510 vrops_alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
511 alarm_def_uuid
= None
513 #Mock default Parameters for alarm & metric configuration
514 m_get_default_Params
.side_effect
= [{'impact': 'risk', 'cancel_cycles': 1,
515 'adapter_kind': 'VMWARE', 'repeat': False,
516 'cancel_period': 300, 'alarm_type': 16,
517 'vrops_alarm': 'CPU_Utilization_Above_Thr',
518 'enabled': True, 'period': 300,
519 'resource_kind': 'VirtualMachine',
520 'alarm_subType': 19, 'action': 'acknowledge',
521 'evaluation': 1, 'unit': 'msec'},
522 {'metric_key': 'cpu|usage_average', 'unit': '%'}
524 #set mocked function return value
525 m_get_alarm_defination_by_name
.return_value
= ['mocked_alarm_CPU_Utilization_Above_Thr']
528 #Call configure_alarm method under test
529 return_value
= self
.mon_plugin
.configure_alarm(config_dict
)
531 #Verify that mocked methods are called with correct parameters
532 self
.assertEqual(m_get_default_Params
.call_count
, 2)
533 m_get_alarm_defination_by_name
.assert_called_with(vrops_alarm_name
)
534 m_create_symptom
.assert_not_called()
535 m_create_alarm_definition
.assert_not_called()
536 m_get_vm_moref_id
.assert_not_called()
537 m_get_vm_resource_id
.assert_not_called()
538 m_create_alarm_notification_rule
.assert_not_called()
539 m_save_alarm
.assert_not_called()
540 #Verify return value with expected value of alarm_def_uuid
541 self
.assertEqual(return_value
, alarm_def_uuid
)
544 @mock.patch
.object(monPlugin
.DatabaseManager
, 'save_alarm')
545 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_notification_rule')
546 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
547 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
548 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_definition')
549 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_symptom')
550 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_by_name')
551 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
552 def test_configure_alarm_failed_symptom_creation(self
, m_get_default_Params
,\
553 m_get_alarm_defination_by_name
,\
555 m_create_alarm_definition
,\
557 m_get_vm_resource_id
,\
558 m_create_alarm_notification_rule
,\
560 """Test configure alarm: failed to create symptom"""
562 #Mock input configuration dictionary
563 config_dict
= {'threshold_value': 0, 'severity': 'CRITICAL',
564 'alarm_name': 'CPU_Utilization_Above_Threshold',
565 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
566 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
567 'statistic': 'AVERAGE', 'metric_name': 'CPU_UTILIZATION',
568 'operation': 'GT', 'unit': '%',
569 'description': 'CPU_Utilization_Above_Threshold'}
571 #symptom parameters to be passed for symptom creation
572 symptom_params
= {'threshold_value': 0,
574 'adapter_kind_key': 'VMWARE',
575 'resource_kind_key': 'VirtualMachine',
576 'severity': 'CRITICAL',
578 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
581 'metric_key': 'cpu|usage_average'}
582 vrops_alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
583 alarm_def_uuid
= None
585 #Mock default Parameters for alarm & metric configuration
586 m_get_default_Params
.side_effect
= [{'impact': 'risk', 'cancel_cycles': 1,
587 'adapter_kind': 'VMWARE', 'repeat': False,
588 'cancel_period': 300, 'alarm_type': 16,
589 'vrops_alarm': 'CPU_Utilization_Above_Thr',
590 'enabled': True, 'period': 300,
591 'resource_kind': 'VirtualMachine',
592 'alarm_subType': 19, 'action': 'acknowledge',
593 'evaluation': 1, 'unit': 'msec'},
594 {'metric_key': 'cpu|usage_average', 'unit': '%'}
596 #set mocked function return values
597 m_get_alarm_defination_by_name
.return_value
= []
598 m_create_symptom
.return_value
= None
600 #Call configure_alarm method under test
601 return_value
= self
.mon_plugin
.configure_alarm(config_dict
)
603 #Verify that mocked methods are called with correct parameters
604 self
.assertEqual(m_get_default_Params
.call_count
, 2)
605 m_get_alarm_defination_by_name
.assert_called_with(vrops_alarm_name
)
606 m_create_symptom
.assert_called_with(symptom_params
)
607 m_create_alarm_definition
.assert_not_called()
608 m_get_vm_moref_id
.assert_not_called()
609 m_get_vm_resource_id
.assert_not_called()
610 m_create_alarm_notification_rule
.assert_not_called()
611 m_save_alarm
.assert_not_called()
613 #Verify return value with expected value of alarm_def_uuid
614 self
.assertEqual(return_value
, alarm_def_uuid
)
617 @mock.patch
.object(monPlugin
.DatabaseManager
, 'save_alarm')
618 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_notification_rule')
619 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
620 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
621 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_definition')
622 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_symptom')
623 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_by_name')
624 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
625 def test_configure_alarm_failed_alert_creation(self
, m_get_default_Params
,\
626 m_get_alarm_defination_by_name
,\
628 m_create_alarm_definition
,\
630 m_get_vm_resource_id
,\
631 m_create_alarm_notification_rule
,\
633 """Test configure alarm: failed to create alert in vROPs"""
635 #Mock input configuration dictionary
636 config_dict
= {'threshold_value': 0, 'severity': 'CRITICAL',
637 'alarm_name': 'CPU_Utilization_Above_Threshold',
638 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
639 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
640 'statistic': 'AVERAGE', 'metric_name': 'CPU_UTILIZATION',
641 'operation': 'GT', 'unit': '%',
642 'description': 'CPU_Utilization_Above_Threshold'}
644 #symptom parameters to be passed for symptom creation
645 symptom_params
= {'threshold_value': 0,
647 'adapter_kind_key': 'VMWARE',
648 'resource_kind_key': 'VirtualMachine',
649 'severity': 'CRITICAL',
651 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
654 'metric_key': 'cpu|usage_average'}
656 #alarm parameters to be passed for alarm creation
657 alarm_params
= {'description': 'CPU_Utilization_Above_Threshold',
658 'cancelCycles': 1, 'subType': 19,
659 'waitCycles': 1, 'severity': 'CRITICAL',
660 'impact': 'risk', 'adapterKindKey': 'VMWARE',
661 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
662 'resourceKindKey': 'VirtualMachine',
663 'symptomDefinitionId':\
664 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804',
667 vrops_alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
668 alarm_def_uuid
= None
670 #Mock default Parameters for alarm & metric configuration
671 m_get_default_Params
.side_effect
= [{'impact': 'risk', 'cancel_cycles': 1,
672 'adapter_kind': 'VMWARE', 'repeat': False,
673 'cancel_period': 300, 'alarm_type': 16,
674 'vrops_alarm': 'CPU_Utilization_Above_Thr',
675 'enabled': True, 'period': 300,
676 'resource_kind': 'VirtualMachine',
677 'alarm_subType': 19, 'action': 'acknowledge',
678 'evaluation': 1, 'unit': 'msec'},
679 {'metric_key': 'cpu|usage_average', 'unit': '%'}
681 #set mocked function return values
682 m_get_alarm_defination_by_name
.return_value
= []
683 m_create_symptom
.return_value
= 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804'
684 m_create_alarm_definition
.return_value
= None
686 #Call configure_alarm method under test
687 return_value
= self
.mon_plugin
.configure_alarm(config_dict
)
689 #Verify that mocked methods are called with correct parameters
690 self
.assertEqual(m_get_default_Params
.call_count
, 2)
691 m_get_alarm_defination_by_name
.assert_called_with(vrops_alarm_name
)
692 m_create_symptom
.assert_called_with(symptom_params
)
693 m_create_alarm_definition
.assert_called_with(alarm_params
)
694 m_get_vm_moref_id
.assert_not_called()
695 m_get_vm_resource_id
.assert_not_called()
696 m_create_alarm_notification_rule
.assert_not_called()
697 m_save_alarm
.assert_not_called()
699 #Verify return value with expected value of alarm_def_uuid
700 self
.assertEqual(return_value
, alarm_def_uuid
)
703 @mock.patch
.object(monPlugin
.DatabaseManager
, 'save_alarm')
704 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_notification_rule')
705 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
706 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
707 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_definition')
708 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_symptom')
709 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_by_name')
710 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
711 def test_configure_alarm_failed_to_get_vm_moref_id(self
, m_get_default_Params
,\
712 m_get_alarm_defination_by_name
,\
714 m_create_alarm_definition
,\
716 m_get_vm_resource_id
,\
717 m_create_alarm_notification_rule
,\
719 """Test configure alarm: failed to get vm_moref_id"""
721 #Mock input configuration dictionary
722 config_dict
= {'threshold_value': 0, 'severity': 'CRITICAL',
723 'alarm_name': 'CPU_Utilization_Above_Threshold',
724 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
725 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
726 'statistic': 'AVERAGE', 'metric_name': 'CPU_UTILIZATION',
727 'operation': 'GT', 'unit': '%',
728 'description': 'CPU_Utilization_Above_Threshold'}
730 #symptom parameters to be passed for symptom creation
731 symptom_params
= {'threshold_value': 0,
733 'adapter_kind_key': 'VMWARE',
734 'resource_kind_key': 'VirtualMachine',
735 'severity': 'CRITICAL',
737 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
740 'metric_key': 'cpu|usage_average'}
742 #alarm parameters to be passed for alarm creation
743 alarm_params
= {'description': 'CPU_Utilization_Above_Threshold',
744 'cancelCycles': 1, 'subType': 19,
745 'waitCycles': 1, 'severity': 'CRITICAL',
746 'impact': 'risk', 'adapterKindKey': 'VMWARE',
747 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
748 'resourceKindKey': 'VirtualMachine',
749 'symptomDefinitionId':\
750 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804',
753 vrops_alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
754 alarm_def_uuid
= None
756 #Mock default Parameters for alarm & metric configuration
757 m_get_default_Params
.side_effect
= [{'impact': 'risk', 'cancel_cycles': 1,
758 'adapter_kind': 'VMWARE', 'repeat': False,
759 'cancel_period': 300, 'alarm_type': 16,
760 'vrops_alarm': 'CPU_Utilization_Above_Thr',
761 'enabled': True, 'period': 300,
762 'resource_kind': 'VirtualMachine',
763 'alarm_subType': 19, 'action': 'acknowledge',
764 'evaluation': 1, 'unit': 'msec'},
765 {'metric_key': 'cpu|usage_average', 'unit': '%'}
767 #set mocked function return values
768 m_get_alarm_defination_by_name
.return_value
= []
769 m_create_symptom
.return_value
= 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804'
770 m_create_alarm_definition
.return_value
=\
771 'AlertDefinition-0f3cdcb3-4e1b-4a0b-86d0-66d4b3f65220'
772 m_get_vm_moref_id
.return_value
= None
774 #Call configure_alarm method under test
775 return_value
= self
.mon_plugin
.configure_alarm(config_dict
)
777 #Verify that mocked methods are called with correct parameters
778 self
.assertEqual(m_get_default_Params
.call_count
, 2)
779 m_get_alarm_defination_by_name
.assert_called_with(vrops_alarm_name
)
780 m_create_symptom
.assert_called_with(symptom_params
)
781 m_create_alarm_definition
.assert_called_with(alarm_params
)
782 m_get_vm_moref_id
.assert_called_with(config_dict
['resource_uuid'])
783 m_get_vm_resource_id
.assert_not_called()
784 m_create_alarm_notification_rule
.assert_not_called()
785 m_save_alarm
.assert_not_called()
787 #Verify return value with expected value of alarm_def_uuid
788 self
.assertEqual(return_value
, alarm_def_uuid
)
791 @mock.patch
.object(monPlugin
.DatabaseManager
, 'save_alarm')
792 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_notification_rule')
793 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
794 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
795 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_definition')
796 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_symptom')
797 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_by_name')
798 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
799 def test_configure_alarm_failed_to_get_vm_resource_id(self
, m_get_default_Params
,\
800 m_get_alarm_defination_by_name
,\
802 m_create_alarm_definition
,\
804 m_get_vm_resource_id
,\
805 m_create_alarm_notification_rule
,\
807 """Test configure alarm: failed to get vm resource_id"""
809 #Mock input configuration dictionary
810 config_dict
= {'threshold_value': 0, 'severity': 'CRITICAL',
811 'alarm_name': 'CPU_Utilization_Above_Threshold',
812 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
813 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
814 'statistic': 'AVERAGE', 'metric_name': 'CPU_UTILIZATION',
815 'operation': 'GT', 'unit': '%',
816 'description': 'CPU_Utilization_Above_Threshold'}
818 #symptom parameters to be passed for symptom creation
819 symptom_params
= {'threshold_value': 0,
821 'adapter_kind_key': 'VMWARE',
822 'resource_kind_key': 'VirtualMachine',
823 'severity': 'CRITICAL',
825 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
828 'metric_key': 'cpu|usage_average'}
830 #alarm parameters to be passed for alarm creation
831 alarm_params
= {'description': 'CPU_Utilization_Above_Threshold',
832 'cancelCycles': 1, 'subType': 19,
833 'waitCycles': 1, 'severity': 'CRITICAL',
834 'impact': 'risk', 'adapterKindKey': 'VMWARE',
835 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
836 'resourceKindKey': 'VirtualMachine',
837 'symptomDefinitionId':\
838 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804',
841 vrops_alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
842 vm_moref_id
= 'vm-6626'
843 alarm_def_uuid
= None
845 #Mock default Parameters for alarm & metric configuration
846 m_get_default_Params
.side_effect
= [{'impact': 'risk', 'cancel_cycles': 1,
847 'adapter_kind': 'VMWARE', 'repeat': False,
848 'cancel_period': 300, 'alarm_type': 16,
849 'vrops_alarm': 'CPU_Utilization_Above_Thr',
850 'enabled': True, 'period': 300,
851 'resource_kind': 'VirtualMachine',
852 'alarm_subType': 19, 'action': 'acknowledge',
853 'evaluation': 1, 'unit': 'msec'},
854 {'metric_key': 'cpu|usage_average', 'unit': '%'}
856 #set mocked function return values
857 m_get_alarm_defination_by_name
.return_value
= []
858 m_create_symptom
.return_value
= 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804'
859 m_create_alarm_definition
.return_value
=\
860 'AlertDefinition-0f3cdcb3-4e1b-4a0b-86d0-66d4b3f65220'
861 m_get_vm_moref_id
.return_value
= vm_moref_id
862 m_get_vm_resource_id
.return_value
= None
863 m_save_alarm
.assert_not_called()
865 #Call configure_alarm method under test
866 return_value
= self
.mon_plugin
.configure_alarm(config_dict
)
868 #Verify that mocked methods are called with correct parameters
869 self
.assertEqual(m_get_default_Params
.call_count
, 2)
870 m_get_alarm_defination_by_name
.assert_called_with(vrops_alarm_name
)
871 m_create_symptom
.assert_called_with(symptom_params
)
872 m_create_alarm_definition
.assert_called_with(alarm_params
)
873 m_get_vm_moref_id
.assert_called_with(config_dict
['resource_uuid'])
874 m_get_vm_resource_id
.assert_called_with(vm_moref_id
)
875 m_create_alarm_notification_rule
.assert_not_called()
877 #Verify return value with expected value of alarm_def_uuid
878 self
.assertEqual(return_value
, alarm_def_uuid
)
881 @mock.patch
.object(monPlugin
.DatabaseManager
, 'save_alarm')
882 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_notification_rule')
883 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
884 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
885 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_alarm_definition')
886 @mock.patch
.object(monPlugin
.MonPlugin
, 'create_symptom')
887 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_by_name')
888 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
889 def test_configure_alarm_failed_to_create_alarm_notification_rule(self
, m_get_default_Params
,\
890 m_get_alarm_defination_by_name
,\
892 m_create_alarm_definition
,\
894 m_get_vm_resource_id
,\
895 m_create_alarm_notification_rule
,\
897 """Test configure alarm: failed to create alarm notification rule"""
899 #Mock input configuration dictionary
900 config_dict
= {'threshold_value': 0, 'severity': 'CRITICAL',
901 'alarm_name': 'CPU_Utilization_Above_Threshold',
902 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
903 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
904 'statistic': 'AVERAGE', 'metric_name': 'CPU_UTILIZATION',
905 'operation': 'GT', 'unit': '%',
906 'description': 'CPU_Utilization_Above_Threshold'}
908 #symptom parameters to be passed for symptom creation
909 symptom_params
= {'threshold_value': 0,
911 'adapter_kind_key': 'VMWARE',
912 'resource_kind_key': 'VirtualMachine',
913 'severity': 'CRITICAL',
915 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
918 'metric_key': 'cpu|usage_average'}
920 #alarm parameters to be passed for alarm creation
921 alarm_params
= {'description': 'CPU_Utilization_Above_Threshold',
922 'cancelCycles': 1, 'subType': 19,
923 'waitCycles': 1, 'severity': 'CRITICAL',
924 'impact': 'risk', 'adapterKindKey': 'VMWARE',
925 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
926 'resourceKindKey': 'VirtualMachine',
927 'symptomDefinitionId':\
928 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804',
931 vrops_alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
932 vm_moref_id
= 'vm-6626'
933 alarm_def
= 'AlertDefinition-0f3cdcb3-4e1b-4a0b-86d0-66d4b3f65220'
934 resource_id
= 'ac87622f-b761-40a0-b151-00872a2a456e'
935 alarm_def_uuid
= None
937 #Mock default Parameters for alarm & metric configuration
938 m_get_default_Params
.side_effect
= [{'impact': 'risk', 'cancel_cycles': 1,
939 'adapter_kind': 'VMWARE', 'repeat': False,
940 'cancel_period': 300, 'alarm_type': 16,
941 'vrops_alarm': 'CPU_Utilization_Above_Thr',
942 'enabled': True, 'period': 300,
943 'resource_kind': 'VirtualMachine',
944 'alarm_subType': 19, 'action': 'acknowledge',
945 'evaluation': 1, 'unit': 'msec'},
946 {'metric_key': 'cpu|usage_average', 'unit': '%'}
948 #set mocked function return values
949 m_get_alarm_defination_by_name
.return_value
= []
950 m_create_symptom
.return_value
= 'SymptomDefinition-2e8f9ddc-9f7b-4cd6-b85d-7d7fe3a8a804'
951 m_create_alarm_definition
.return_value
=\
952 'AlertDefinition-0f3cdcb3-4e1b-4a0b-86d0-66d4b3f65220'
953 m_get_vm_moref_id
.return_value
= vm_moref_id
954 m_get_vm_resource_id
.return_value
= 'ac87622f-b761-40a0-b151-00872a2a456e'
955 m_create_alarm_notification_rule
.return_value
= None
957 #Call configure_alarm method under test
958 return_value
= self
.mon_plugin
.configure_alarm(config_dict
)
960 #Verify that mocked methods are called with correct parameters
961 self
.assertEqual(m_get_default_Params
.call_count
, 2)
962 m_get_alarm_defination_by_name
.assert_called_with(vrops_alarm_name
)
963 m_create_symptom
.assert_called_with(symptom_params
)
964 m_create_alarm_definition
.assert_called_with(alarm_params
)
965 m_get_vm_moref_id
.assert_called_with(config_dict
['resource_uuid'])
966 m_get_vm_resource_id
.assert_called_with(vm_moref_id
)
967 m_create_alarm_notification_rule
.assert_called_with(vrops_alarm_name
, alarm_def
, resource_id
)
968 m_save_alarm
.assert_not_called()
970 #Verify return value with expected value of alarm_def_uuid
971 self
.assertEqual(return_value
, alarm_def_uuid
)
974 @mock.patch
.object(monPlugin
.requests
, 'get')
975 def test_get_alarm_defination_details_valid_rest_req_response(self
, m_get
):
976 """Test get_alarm_defination_details: For a valid REST request response"""
978 alarm_uuid
= '9a6d8a14-9f25-4d81-bf91-4d773497444d'
980 #Set mocked function's return values
981 m_get
.return_value
.status_code
= 200
982 m_get
.return_value
.content
= '{"id":"AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444d",\
983 "name":"CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
984 "description":"CPU_Utilization_Above_Threshold",\
985 "adapterKindKey":"VMWARE","resourceKindKey":"VirtualMachine",\
986 "waitCycles":1,"cancelCycles":1,"type":16,"subType":19,\
987 "states":[{"severity":"CRITICAL","base-symptom-set":\
988 {"type":"SYMPTOM_SET","relation":"SELF",\
989 "aggregation":"ALL","symptomSetOperator":"AND","symptomDefinitionIds":\
990 ["SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278"]},\
991 "impact":{"impactType":"BADGE","detail":"risk"}}]}'
993 expected_alarm_details
= {'adapter_kind': 'VMWARE','symptom_definition_id':\
994 'SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278',
996 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
997 'alarm_id': 'AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444d',
998 'resource_kind': 'VirtualMachine', 'type': 16, 'sub_type': 19}
1000 expected_alarm_details_json
= {'states':
1002 {'impactType':'BADGE', 'detail':'risk'},'severity':'CRITICAL',
1003 'base-symptom-set': {'symptomDefinitionIds':\
1004 ['SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278'],
1005 'relation': 'SELF', 'type': 'SYMPTOM_SET',
1006 'aggregation':'ALL', 'symptomSetOperator': 'AND'}}],
1007 'adapterKindKey': 'VMWARE',
1008 'description': 'CPU_Utilization_Above_Threshold',
1009 'type': 16, 'cancelCycles': 1,
1010 'resourceKindKey': 'VirtualMachine',
1011 'subType': 19, 'waitCycles': 1,
1012 'id': 'AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444d',
1014 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'}
1016 #Call get_alarm_defination_details method under test
1017 alarm_details_json
, alarm_details
= self
.mon_plugin
.get_alarm_defination_details(alarm_uuid
)
1019 #Verify that mocked method is called
1020 m_get
.assert_called()
1022 #Verify return value with expected value
1023 self
.assertEqual(expected_alarm_details
, alarm_details
)
1024 self
.assertEqual(expected_alarm_details_json
, alarm_details_json
)
1027 @mock.patch
.object(monPlugin
.requests
, 'get')
1028 def test_get_alarm_defination_details_invalid_rest_req_response(self
, m_get
):
1029 """Test get_alarm_defination_details: For an invalid REST request response"""
1031 alarm_uuid
= '9a6d8a14-9f25-4d81-bf91-4d773497444d'
1033 #Set mocked function's return values
1034 m_get
.return_value
.status_code
= 404
1035 m_get
.return_value
.content
= '{"message": "No such AlertDefinition - \
1036 AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444.",\
1037 "httpStatusCode": 404,"apiErrorCode": 404}'
1039 expected_alarm_details
= None
1040 expected_alarm_details_json
= None
1042 #Call get_alarm_defination_details method under test
1043 alarm_details_json
, alarm_details
= self
.mon_plugin
.get_alarm_defination_details(alarm_uuid
)
1045 #verify that mocked method is called
1046 m_get
.assert_called()
1048 #Verify return value with expected value
1049 self
.assertEqual(expected_alarm_details
, alarm_details
)
1050 self
.assertEqual(expected_alarm_details_json
, alarm_details_json
)
1053 @mock.patch
.object(monPlugin
.requests
, 'get')
1054 def test_get_alarm_defination_by_name_valid_rest_req_response(self
, m_get
):
1055 """Test get_alarm_defination_by_name: For a valid REST request response"""
1057 alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
1059 #Set mocked function's return values
1060 m_get
.return_value
.status_code
= 200
1061 m_get
.return_value
.content
= '{"pageInfo": {"totalCount": 1,"page": 0,"pageSize": 1000},\
1063 {"href": "/suite-api/api/alertdefinitions?page=0&pageSize=1000",\
1064 "rel": "SELF","name": "current"},\
1065 {"href": "/suite-api/api/alertdefinitions?page=0&pageSize=1000",\
1066 "rel": "RELATED","name": "first"},\
1067 {"href": "/suite-api/api/alertdefinitions?page=0&pageSize=1000",\
1068 "rel": "RELATED","name": "last"}],\
1069 "alertDefinitions": [{\
1070 "id": "AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444d",\
1071 "name": "CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
1072 "description": "CPU_Utilization_Above_Threshold",\
1073 "adapterKindKey": "VMWARE","resourceKindKey": "VirtualMachine",\
1074 "waitCycles": 1,"cancelCycles": 1,"type": 16,"subType": 19,\
1075 "states": [{"impact": {"impactType": "BADGE","detail": "risk"},\
1076 "severity": "CRITICAL",\
1077 "base-symptom-set": {"type": "SYMPTOM_SET",\
1078 "relation": "SELF","aggregation": "ALL",\
1079 "symptomSetOperator": "AND",\
1080 "symptomDefinitionIds": [\
1081 "SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278"]}}]\
1084 #Expected return match list
1085 Exp_alert_match_list
= [{'states':
1086 [{'impact': {'impactType': 'BADGE', 'detail': 'risk'},
1087 'severity': 'CRITICAL',
1088 'base-symptom-set': {
1089 'symptomDefinitionIds': \
1090 ['SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278'],
1092 'type': 'SYMPTOM_SET',
1093 'aggregation': 'ALL',
1094 'symptomSetOperator': 'AND'}
1096 'adapterKindKey': 'VMWARE',
1097 'description': 'CPU_Utilization_Above_Threshold',
1100 'resourceKindKey': 'VirtualMachine',
1101 'subType': 19, 'waitCycles': 1,
1102 'id': 'AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444d',
1104 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
1107 #Call get_alarm_defination_by_name method under test
1108 alert_match_list
= self
.mon_plugin
.get_alarm_defination_by_name(alarm_name
)
1110 #Verify that mocked method is called
1111 m_get
.assert_called()
1113 #Verify return value with expected value
1114 self
.assertEqual(Exp_alert_match_list
, alert_match_list
)
1117 @mock.patch
.object(monPlugin
.requests
, 'get')
1118 def test_get_alarm_defination_by_name_no_valid_alarm_found(self
, m_get
):
1119 """Test get_alarm_defination_by_name: With no valid alarm found in returned list"""
1121 alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda5'
1123 #Set mocked function's return values
1124 m_get
.return_value
.status_code
= 200
1125 m_get
.return_value
.content
= '{"pageInfo": {"totalCount": 1,"page": 0,"pageSize": 1000},\
1127 {"href": "/suite-api/api/alertdefinitions?page=0&pageSize=1000",\
1128 "rel": "SELF","name": "current"},\
1129 {"href": "/suite-api/api/alertdefinitions?page=0&pageSize=1000",\
1130 "rel": "RELATED","name": "first"},\
1131 {"href": "/suite-api/api/alertdefinitions?page=0&pageSize=1000",\
1132 "rel": "RELATED","name": "last"}],\
1133 "alertDefinitions": [{\
1134 "id": "AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444d",\
1135 "name": "CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
1136 "description": "CPU_Utilization_Above_Threshold",\
1137 "adapterKindKey": "VMWARE","resourceKindKey": "VirtualMachine",\
1138 "waitCycles": 1,"cancelCycles": 1,"type": 16,"subType": 19,\
1139 "states": [{"impact": {"impactType": "BADGE","detail": "risk"},\
1140 "severity": "CRITICAL",\
1141 "base-symptom-set": {"type": "SYMPTOM_SET",\
1142 "relation": "SELF","aggregation": "ALL",\
1143 "symptomSetOperator": "AND",\
1144 "symptomDefinitionIds": [\
1145 "SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278"]}}]\
1148 #Expected return match list
1149 Exp_alert_match_list
= []
1151 #Call get_alarm_defination_by_name method under test
1152 alert_match_list
= self
.mon_plugin
.get_alarm_defination_by_name(alarm_name
)
1154 #Verify that mocked method is called
1155 m_get
.assert_called()
1157 #Verify return value with expected value
1158 self
.assertEqual(Exp_alert_match_list
, alert_match_list
)
1161 @mock.patch
.object(monPlugin
.requests
, 'put')
1162 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_symptom_defination_details')
1163 def test_update_symptom_defination_valid_symptom_req_response(self
,\
1164 m_get_symptom_defination_details
,\
1166 """Test update_symptom_defination: With valid REST response, update symptom"""
1168 #Expected symptom to be updated
1169 symptom_defination_id
= 'SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278'
1170 new_alarm_config
= {'severity':"CRITICAL",
1172 'threshold_value':5,
1173 'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'
1176 #Set mocked function's return values
1177 m_get_symptom_defination_details
.return_value
= {
1178 "id": "SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278",
1179 "name": "CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",
1180 "adapterKindKey": "VMWARE",
1181 "resourceKindKey": "VirtualMachine",
1184 "state": {"severity": "CRITICAL",
1186 "type": "CONDITION_HT",
1187 "key": "cpu|usage_average","operator": "GT","value": "0.0",
1188 "valueType": "NUMERIC","instanced": False,
1189 "thresholdType": "STATIC"}
1193 m_put
.return_value
.status_code
= 200
1194 m_put
.return_value
.content
= '{\
1195 "id":"SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278",\
1196 "name":"CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
1197 "adapterKindKey":"VMWARE","resourceKindKey":"VirtualMachine","waitCycles":1,\
1200 "severity":"CRITICAL",\
1202 "type":"CONDITION_HT","key":"cpu|usage_average","operator":"GT","value":"5.0",\
1203 "valueType":"NUMERIC","instanced":False,"thresholdType":"STATIC"}}}'
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_called_with(symptom_defination_id,new_alarm_config)
1213 #Verify return value with expected value
1214 self
.assertEqual(symptom_defination_id
, symptom_uuid
)
1217 @mock.patch
.object(monPlugin
.requests
, 'put')
1218 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_symptom_defination_details')
1219 def test_update_symptom_defination_invalid_symptom_req_response(self
,\
1220 m_get_symptom_defination_details
,\
1222 """Test update_symptom_defination: If invalid REST response received, return None"""
1224 #Expected symptom to be updated
1225 symptom_defination_id
= 'SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278'
1226 new_alarm_config
= {'severity':"CRITICAL",
1228 'threshold_value':5,
1229 'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'
1232 #Set mocked function's return values
1233 m_get_symptom_defination_details
.return_value
= {
1234 "id": "SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278",
1235 "name": "CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",
1236 "adapterKindKey": "VMWARE",
1237 "resourceKindKey": "VirtualMachine",
1240 "state": {"severity": "CRITICAL",
1242 "type": "CONDITION_HT",
1243 "key": "cpu|usage_average","operator": "GT","value": "0.0",
1244 "valueType": "NUMERIC","instanced": False,
1245 "thresholdType": "STATIC"}
1249 m_put
.return_value
.status_code
= 500
1250 m_put
.return_value
.content
= '{\
1251 "message": "Internal Server error, cause unknown.",\
1252 "moreInformation": [\
1253 {"name": "errorMessage",\
1254 "value": "Symptom Definition CPU_Utilization_Above_Thr-e14b203c-\
1255 6bf2-4e2f-a91c-8c19d240eda4 does not exist and hence cannot be updated."},\
1256 {"name": "localizedMessage",\
1257 "value": "Symptom Definition CPU_Utilization_Above_Thr-e14b203c-\
1258 6bf2-4e2f-a91c-8c19d240eda4 does not exist and hence cannot be updated.;"}],\
1259 "httpStatusCode": 500,"apiErrorCode": 500}'
1261 #Call update_symptom_defination method under test
1262 symptom_uuid
= self
.mon_plugin
.update_symptom_defination(symptom_defination_id
,\
1265 #Verify that mocked method is called with required parameters
1266 m_get_symptom_defination_details
.assert_called_with(symptom_defination_id
)
1267 m_put
.assert_called()
1269 #Verify return value with expected value
1270 self
.assertEqual(symptom_uuid
, None)
1273 @mock.patch
.object(monPlugin
.requests
, 'put')
1274 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_symptom_defination_details')
1275 def test_update_symptom_defination_failed_to_get_symptom_defination(self
,\
1276 m_get_symptom_defination_details
,\
1278 """Test update_symptom_defination: if fails to get symptom_defination returns None"""
1280 #Expected symptom to be updated
1281 symptom_defination_id
= 'SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278'
1282 new_alarm_config
= {'severity':"CRITICAL",
1284 'threshold_value':5,
1285 'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'
1288 #Set mocked function's return values
1289 m_get_symptom_defination_details
.return_value
= None
1291 #Call update_symptom_defination method under test
1292 symptom_uuid
= self
.mon_plugin
.update_symptom_defination(symptom_defination_id
,\
1295 #Verify that mocked method is called with required parameters
1296 m_get_symptom_defination_details
.assert_called_with(symptom_defination_id
)
1297 m_put
.assert_not_called()
1299 #Verify return value with expected value
1300 self
.assertEqual(symptom_uuid
, None)
1303 @mock.patch
.object(monPlugin
.requests
, 'get')
1304 def test_get_symptom_defination_details_valid_req_response(self
,m_get
):
1305 """Test update_symptom_defination: With valid REST response symptom is created"""
1307 #Expected symptom to be updated
1308 symptom_uuid
= 'SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278'
1310 #Set mocked function's return values
1311 m_get
.return_value
.status_code
= 200
1312 m_get
.return_value
.content
= '{\
1313 "id": "SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278",\
1314 "name": "CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
1315 "adapterKindKey": "VMWARE","resourceKindKey": "VirtualMachine","waitCycles": 1,\
1316 "cancelCycles": 1,"state": {"severity": "CRITICAL","condition": {"type": "CONDITION_HT",\
1317 "key": "cpu|usage_average","operator": "GT","value": "6.0","valueType": "NUMERIC",\
1318 "instanced": false,"thresholdType": "STATIC"}}}'
1319 expected_symptom_details
= {\
1320 "id": "SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278",\
1321 "name": "CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
1322 "adapterKindKey": "VMWARE","resourceKindKey": "VirtualMachine","waitCycles": 1,\
1323 "cancelCycles": 1,"state": {"severity": "CRITICAL","condition": {"type": "CONDITION_HT",\
1324 "key": "cpu|usage_average","operator": "GT","value": "6.0","valueType": "NUMERIC",\
1325 "instanced": False,"thresholdType": "STATIC"}}}
1327 #Call update_symptom_defination method under test
1328 symptom_details
= self
.mon_plugin
.get_symptom_defination_details(symptom_uuid
)
1330 #Verify that mocked method is called with required parameters
1331 m_get
.assert_called()
1333 #Verify return value with expected value
1334 self
.assertEqual(expected_symptom_details
, symptom_details
)
1337 @mock.patch
.object(monPlugin
.requests
, 'get')
1338 def test_get_symptom_defination_details_invalid_req_response(self
,m_get
):
1339 """Test update_symptom_defination: if invalid REST response received return None"""
1341 #Expected symptom to be updated
1342 symptom_uuid
= 'SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278'
1344 #Set mocked function's return values
1345 m_get
.return_value
.status_code
= 404
1346 m_get
.return_value
.content
= '{"message": "No such SymptomDefinition\
1347 - SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278.",\
1348 "httpStatusCode": 404,"apiErrorCode": 404}'
1350 expected_symptom_details
= None
1352 #Call update_symptom_defination method under test
1353 symptom_details
= self
.mon_plugin
.get_symptom_defination_details(symptom_uuid
)
1355 #Verify that mocked method is called with required parameters
1356 m_get
.assert_called()
1358 #Verify return value with expected value
1359 self
.assertEqual(expected_symptom_details
, symptom_details
)
1362 @mock.patch
.object(monPlugin
.requests
, 'get')
1363 def test_get_symptom_defination_details_symptom_uuid_not_provided(self
,m_get
):
1364 """Test update_symptom_defination: if required symptom uuid is not provided"""
1366 #Expected symptom to be updated
1368 expected_symptom_details
= None
1370 #Call update_symptom_defination method under test
1371 symptom_details
= self
.mon_plugin
.get_symptom_defination_details(symptom_uuid
)
1373 #Verify that mocked method is called with required parameters
1374 m_get
.assert_not_called()
1376 #Verify return value with expected value
1377 self
.assertEqual(expected_symptom_details
, symptom_details
)
1380 @mock.patch
.object(monPlugin
.requests
, 'put')
1381 def test_reconfigure_alarm_valid_req_response(self
, m_put
):
1382 """Test reconfigure_alarm: for valid REST response"""
1384 #Set input parameters to reconfigure_alarm
1385 alarm_details_json
= {
1386 'id': 'AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444d',
1387 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
1388 'description': 'CPU_Utilization_Above_Threshold', 'adapterKindKey': 'VMWARE',
1389 'states':[{'impact':{'impactType':'BADGE', 'detail':'risk'}, 'severity':'CRITICAL',
1390 'base-symptom-set':{
1391 'symptomDefinitionIds':['SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278'],
1392 'relation': 'SELF','type': 'SYMPTOM_SET', 'aggregation':'ALL',
1393 'symptomSetOperator': 'AND'}}],
1394 'type': 16, 'cancelCycles': 1, 'resourceKindKey': 'VirtualMachine','subType': 19,
1397 new_alarm_config
= {'severity':'WARNING',
1398 'description': 'CPU_Utilization_Above_Threshold_Warning'}
1400 #Set mocked function's return values
1401 m_put
.return_value
.status_code
= 200
1402 m_put
.return_value
.content
= '{"id":"AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444d",\
1403 "name":"CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
1404 "description":"CPU_Utilization_Above_Threshold_Warning","adapterKindKey":"VMWARE",\
1405 "resourceKindKey":"VirtualMachine","waitCycles":1,"cancelCycles":1,"type":16,\
1406 "subType":19,"states":[{"severity":"WARNING","base-symptom-set":{"type":"SYMPTOM_SET",\
1407 "relation":"SELF","aggregation":"ALL","symptomSetOperator":"AND",\
1408 "symptomDefinitionIds":["SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278"]},\
1409 "impact":{"impactType":"BADGE","detail":"risk"}}]}'
1411 #Expected alarm_def_uuid to be returned
1412 expected_alarm_def_uuid
= '9a6d8a14-9f25-4d81-bf91-4d773497444d'
1414 #Call reconfigure_alarm method under test
1415 alarm_def_uuid
= self
.mon_plugin
.reconfigure_alarm(alarm_details_json
, new_alarm_config
)
1417 #Verify that mocked method is called with required parameters
1418 m_put
.assert_called()
1420 #Verify return value with expected value
1421 self
.assertEqual(expected_alarm_def_uuid
, alarm_def_uuid
)
1424 @mock.patch
.object(monPlugin
.requests
, 'put')
1425 def test_reconfigure_alarm_invalid_req_response(self
, m_put
):
1426 """Test reconfigure_alarm: for invalid REST response, return None"""
1428 #Set input parameters to reconfigure_alarm
1429 alarm_details_json
= {
1430 'id': 'AlertDefinition-9a6d8a14-9f25-4d81-bf91-4d773497444d',
1431 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
1432 'description': 'CPU_Utilization_Above_Threshold', 'adapterKindKey': 'VMWARE',
1433 'states':[{'impact':{'impactType':'BADGE', 'detail':'risk'}, 'severity':'CRITICAL',
1434 'base-symptom-set':{
1435 'symptomDefinitionIds':['SymptomDefinition-bcc2cb36-a67b-4deb-bcd3-9b5884973278'],
1436 'relation': 'SELF','type': 'SYMPTOM_SET', 'aggregation':'ALL',
1437 'symptomSetOperator': 'AND'}}],
1438 'type': 16, 'cancelCycles': 1, 'resourceKindKey': 'VirtualMachine','subType': 19,
1441 new_alarm_config
= {'severity':'WARNING',
1442 'description': 'CPU_Utilization_Above_Threshold_Warning'}
1444 #Set mocked function's return values
1445 m_put
.return_value
.status_code
= 500
1446 m_put
.return_value
.content
= '{"message": "Internal Server error, cause unknown.",\
1447 "moreInformation": [{"name": "errorMessage",\
1448 "value": "Cannot update Alert Definition CPU_Utilization_Above_Thr-\
1449 e14b203c-6bf2-4e2f-a91c-8c19d240eda4 since it does not exist"},\
1450 {"name": "localizedMessage",\
1451 "value": "Cannot update Alert Definition CPU_Utilization_Above_Thr-\
1452 e14b203c-6bf2-4e2f-a91c-8c19d240eda4 since it does not exist;"}],\
1453 "httpStatusCode": 500,"apiErrorCode": 500}'
1455 #Expected alarm_def_uuid to be returned
1456 expected_alarm_def_uuid
= None
1458 #Call reconfigure_alarm method under test
1459 alarm_def_uuid
= self
.mon_plugin
.reconfigure_alarm(alarm_details_json
, new_alarm_config
)
1461 #Verify that mocked method is called with required parameters
1462 m_put
.assert_called()
1464 #Verify return value with expected value
1465 self
.assertEqual(expected_alarm_def_uuid
, alarm_def_uuid
)
1468 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_symptom_definition')
1469 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_alarm_defination')
1470 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_notification_rule')
1471 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_details')
1472 def test_delete_alarm_configuration_successful_alarm_deletion(self
,\
1473 m_get_alarm_defination_details
,\
1474 m_delete_notification_rule
,\
1475 m_delete_alarm_defination
,\
1476 m_delete_symptom_definition
):
1477 """Test delete_alarm_configuration: for successful alarm deletion, return alarm uuid"""
1479 #Set input parameters to delete_alarm_configuration
1480 delete_alarm_req_dict
= {'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'}
1482 #Set mocked function's return values
1483 alarm_details_json
= {
1484 'id': 'AlertDefinition-9a6d8a14-9f25-4d81-4d773497444d',
1485 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4',
1486 'symptomDefinitionIds':['SymptomDefinition-bcc2cb36-a67b-4deb-9b5884973278']}
1488 'alarm_name':'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4',
1489 'alarm_id':'AlertDefinition-9a6d8a14-9f25-4d81-4d773497444d',
1490 'symptom_definition_id':'SymptomDefinition-bcc2cb36-a67b-4deb-9b5884973278'}
1492 m_get_alarm_defination_details
.return_value
= (alarm_details_json
, alarm_details
)
1493 m_delete_notification_rule
.return_value
= '989e7293-d78d-4405-92e30ec4f247'
1494 m_delete_alarm_defination
.return_value
= alarm_details
['alarm_id']
1495 m_delete_symptom_definition
.return_value
= alarm_details
['symptom_definition_id']
1497 #Call reconfigure_alarm method under test
1498 alarm_uuid
= self
.mon_plugin
.delete_alarm_configuration(delete_alarm_req_dict
)
1500 #Verify that mocked method is called with required parameters
1501 m_get_alarm_defination_details
.assert_called_with(delete_alarm_req_dict
['alarm_uuid'])
1502 m_delete_notification_rule
.assert_called_with(alarm_details
['alarm_name'])
1503 m_delete_alarm_defination
.assert_called_with(alarm_details
['alarm_id'])
1504 m_delete_symptom_definition
.assert_called_with(alarm_details
['symptom_definition_id'])
1506 #Verify return value with expected value
1507 self
.assertEqual(alarm_uuid
, delete_alarm_req_dict
['alarm_uuid'])
1510 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_symptom_definition')
1511 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_alarm_defination')
1512 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_notification_rule')
1513 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_details')
1514 def test_delete_alarm_configuration_failed_to_get_alarm_defination(self
,\
1515 m_get_alarm_defination_details
,\
1516 m_delete_notification_rule
,\
1517 m_delete_alarm_defination
,\
1518 m_delete_symptom_definition
):
1519 """Test delete_alarm_configuration: if failed to get alarm definition, return None"""
1521 #Set input parameters to delete_alarm_configuration
1522 delete_alarm_req_dict
= {'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'}
1524 #Set mocked function's return values
1525 alarm_details_json
= None
1526 alarm_details
= None
1528 m_get_alarm_defination_details
.return_value
= (alarm_details_json
, alarm_details
)
1530 #Call reconfigure_alarm method under test
1531 alarm_uuid
= self
.mon_plugin
.delete_alarm_configuration(delete_alarm_req_dict
)
1533 #Verify that mocked method is called with required parameters
1534 m_get_alarm_defination_details
.assert_called_with(delete_alarm_req_dict
['alarm_uuid'])
1535 m_delete_notification_rule
.assert_not_called()
1536 m_delete_alarm_defination
.assert_not_called()
1537 m_delete_symptom_definition
.assert_not_called()
1539 #Verify return value with expected value
1540 self
.assertEqual(alarm_uuid
, None)
1543 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_symptom_definition')
1544 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_alarm_defination')
1545 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_notification_rule')
1546 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_details')
1547 def test_delete_alarm_configuration_failed_to_delete_notification_rule(self
,\
1548 m_get_alarm_defination_details
,\
1549 m_delete_notification_rule
,\
1550 m_delete_alarm_defination
,\
1551 m_delete_symptom_definition
):
1552 """Test delete_alarm_configuration: if failed to delete notification rule, return None"""
1554 #Set input parameters to delete_alarm_configuration
1555 delete_alarm_req_dict
= {'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'}
1557 #Set mocked function's return values
1558 alarm_details_json
= {
1559 'id': 'AlertDefinition-9a6d8a14-9f25-4d81-4d773497444d',
1560 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4',
1561 'symptomDefinitionIds':['SymptomDefinition-bcc2cb36-a67b-4deb-9b5884973278']}
1563 'alarm_name':'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4',
1564 'alarm_id':'AlertDefinition-9a6d8a14-9f25-4d81-4d773497444d',
1565 'symptom_definition_id':'SymptomDefinition-bcc2cb36-a67b-4deb-9b5884973278'}
1567 m_get_alarm_defination_details
.return_value
= (alarm_details_json
, alarm_details
)
1568 m_delete_notification_rule
.return_value
= None
1570 #Call reconfigure_alarm method under test
1571 alarm_uuid
= self
.mon_plugin
.delete_alarm_configuration(delete_alarm_req_dict
)
1573 #Verify that mocked method is called with required parameters
1574 m_get_alarm_defination_details
.assert_called_with(delete_alarm_req_dict
['alarm_uuid'])
1575 m_delete_notification_rule
.assert_called_with(alarm_details
['alarm_name'])
1576 m_delete_alarm_defination
.assert_not_called()
1577 m_delete_symptom_definition
.assert_not_called()
1579 #Verify return value with expected value
1580 self
.assertEqual(alarm_uuid
, None)
1583 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_symptom_definition')
1584 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_alarm_defination')
1585 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_notification_rule')
1586 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_details')
1587 def test_delete_alarm_configuration_failed_to_delete_alarm_defination(self
,\
1588 m_get_alarm_defination_details
,\
1589 m_delete_notification_rule
,\
1590 m_delete_alarm_defination
,\
1591 m_delete_symptom_definition
):
1592 """Test delete_alarm_configuration: if failed to delete alarm definition, return None"""
1594 #Set input parameters to delete_alarm_configuration
1595 delete_alarm_req_dict
= {'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'}
1597 #Set mocked function's return values
1598 alarm_details_json
= {
1599 'id': 'AlertDefinition-9a6d8a14-9f25-4d81-4d773497444d',
1600 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4',
1601 'symptomDefinitionIds':['SymptomDefinition-bcc2cb36-a67b-4deb-9b5884973278']}
1603 'alarm_name':'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4',
1604 'alarm_id':'AlertDefinition-9a6d8a14-9f25-4d81-4d773497444d',
1605 'symptom_definition_id':'SymptomDefinition-bcc2cb36-a67b-4deb-9b5884973278'}
1607 m_get_alarm_defination_details
.return_value
= (alarm_details_json
, alarm_details
)
1608 m_delete_notification_rule
.return_value
= '989e7293-d78d-4405-92e30ec4f247'
1609 m_delete_alarm_defination
.return_value
= None
1611 #Call reconfigure_alarm method under test
1612 alarm_uuid
= self
.mon_plugin
.delete_alarm_configuration(delete_alarm_req_dict
)
1614 #Verify that mocked method is called with required parameters
1615 m_get_alarm_defination_details
.assert_called_with(delete_alarm_req_dict
['alarm_uuid'])
1616 m_delete_notification_rule
.assert_called_with(alarm_details
['alarm_name'])
1617 m_delete_alarm_defination
.assert_called_with(alarm_details
['alarm_id'])
1618 m_delete_symptom_definition
.assert_not_called()
1620 #Verify return value with expected value
1621 self
.assertEqual(alarm_uuid
, None)
1624 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_symptom_definition')
1625 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_alarm_defination')
1626 @mock.patch
.object(monPlugin
.MonPlugin
, 'delete_notification_rule')
1627 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_details')
1628 def test_delete_alarm_configuration_failed_to_delete_symptom_definition(self
,\
1629 m_get_alarm_defination_details
,\
1630 m_delete_notification_rule
,\
1631 m_delete_alarm_defination
,\
1632 m_delete_symptom_definition
):
1633 """Test delete_alarm_configuration: if failed to delete symptom definition, return None"""
1635 #Set input parameters to delete_alarm_configuration
1636 delete_alarm_req_dict
= {'alarm_uuid':'9a6d8a14-9f25-4d81-bf91-4d773497444d'}
1638 #Set mocked function's return values
1639 alarm_details_json
= {
1640 'id': 'AlertDefinition-9a6d8a14-9f25-4d81-4d773497444d',
1641 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4',
1642 'symptomDefinitionIds':['SymptomDefinition-bcc2cb36-a67b-4deb-9b5884973278']}
1644 'alarm_name':'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4',
1645 'alarm_id':'AlertDefinition-9a6d8a14-9f25-4d81-4d773497444d',
1646 'symptom_definition_id':'SymptomDefinition-bcc2cb36-a67b-4deb-9b5884973278'}
1648 m_get_alarm_defination_details
.return_value
= (alarm_details_json
, alarm_details
)
1649 m_delete_notification_rule
.return_value
= '989e7293-d78d-4405-92e30ec4f247'
1650 m_delete_alarm_defination
.return_value
= alarm_details
['alarm_id']
1651 m_delete_symptom_definition
.return_value
= None
1653 #Call reconfigure_alarm method under test
1654 alarm_uuid
= self
.mon_plugin
.delete_alarm_configuration(delete_alarm_req_dict
)
1656 #Verify that mocked method is called with required parameters
1657 m_get_alarm_defination_details
.assert_called_with(delete_alarm_req_dict
['alarm_uuid'])
1658 m_delete_notification_rule
.assert_called_with(alarm_details
['alarm_name'])
1659 m_delete_alarm_defination
.assert_called_with(alarm_details
['alarm_id'])
1660 m_delete_symptom_definition
.assert_called_with(alarm_details
['symptom_definition_id'])
1662 #Verify return value with expected value
1663 self
.assertEqual(alarm_uuid
, None)
1666 @mock.patch
.object(monPlugin
.requests
, 'delete')
1667 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_notification_rule_id_by_alarm_name')
1668 def test_delete_notification_rule_successful_deletion_req_response(self
,\
1669 m_get_notification_rule_id_by_alarm_name
,\
1671 """Test delete_notification_rule: Valid notification rule is deleted & returns rule_id"""
1673 #Set input parameters to delete_notification_rule
1674 alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4'
1676 #Set mocked function's return values
1677 m_get_notification_rule_id_by_alarm_name
.return_value
= '8db86441-71d8-4830-9e1a-a90be3776d12'
1678 m_delete
.return_value
.status_code
= 204
1680 #Call delete_notification_rule method under test
1681 rule_id
= self
.mon_plugin
.delete_notification_rule(alarm_name
)
1683 #Verify that mocked method is called with required parameters
1684 m_get_notification_rule_id_by_alarm_name
.assert_called_with(alarm_name
)
1685 m_delete
.assert_called()
1687 #Verify return value with expected value
1688 self
.assertEqual(rule_id
, '8db86441-71d8-4830-9e1a-a90be3776d12')
1691 @mock.patch
.object(monPlugin
.requests
, 'delete')
1692 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_notification_rule_id_by_alarm_name')
1693 def test_delete_notification_rule_failed_to_get_notification_rule_id(self
,\
1694 m_get_notification_rule_id_by_alarm_name
,\
1696 """Test delete_notification_rule: if notification rule is not found, returns None"""
1698 #Set input parameters to delete_notification_rule
1699 alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4'
1701 #Set mocked function's return values
1702 m_get_notification_rule_id_by_alarm_name
.return_value
= None
1704 #Call delete_notification_rule method under test
1705 rule_id
= self
.mon_plugin
.delete_notification_rule(alarm_name
)
1707 #Verify that mocked method is called with required parameters
1708 m_get_notification_rule_id_by_alarm_name
.assert_called_with(alarm_name
)
1709 m_delete
.assert_not_called()
1711 # verify return value with expected value
1712 self
.assertEqual(rule_id
, None)
1715 @mock.patch
.object(monPlugin
.requests
, 'delete')
1716 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_notification_rule_id_by_alarm_name')
1717 def test_delete_notification_rule_invalid_deletion_req_response(self
,\
1718 m_get_notification_rule_id_by_alarm_name
,\
1720 """Test delete_notification_rule: If an invalid response is received, returns None"""
1722 #Set input parameters to delete_notification_rule
1723 alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-8c19d240eda4'
1725 #Set mocked function's return values
1726 m_get_notification_rule_id_by_alarm_name
.return_value
= '8db86441-71d8-4830-9e1a-a90be3776d12'
1727 m_delete
.return_value
.status_code
= 404
1729 #Call delete_notification_rule method under test
1730 rule_id
= self
.mon_plugin
.delete_notification_rule(alarm_name
)
1732 #Verify that mocked method is called with required parameters
1733 m_get_notification_rule_id_by_alarm_name
.assert_called_with(alarm_name
)
1734 m_delete
.assert_called()
1736 #Verify return value with expected value
1737 self
.assertEqual(rule_id
, None)
1740 @mock.patch
.object(monPlugin
.requests
, 'get')
1741 def test_get_notification_rule_id_by_alarm_name_valid_req_response(self
,m_get
):
1742 """Test get_notification_rule_id_by_alarm_name: A valid request response received,
1743 returns notification_id
1746 #Set input parameters to get_notification_rule_id_by_alarm_name
1747 alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
1749 #Set mocked function's return values
1750 m_get
.return_value
.status_code
= 200
1751 m_get
.return_value
.content
= '{\
1752 "pageInfo": {"totalCount": 0,"page": 0,"pageSize": 1000},\
1754 {"href": "/suite-api/api/notifications/rules?page=0&pageSize=1000",\
1755 "rel": "SELF","name": "current"},\
1756 {"href": "/suite-api/api/notifications/rules?page=0&pageSize=1000",\
1757 "rel": "RELATED","name": "first"},\
1758 {"href": "/suite-api/api/notifications/rules?page=0&pageSize=1000",\
1759 "rel": "RELATED","name": "last"}],\
1760 "notification-rule": [{\
1761 "id": "2b86fa23-0c15-445c-a2b1-7bd725c46f59",\
1762 "name": "notify_CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
1763 "pluginId": "03053f51-f829-438d-993d-cc33a435d76a",\
1764 "links": [{"href": "/suite-api/api/notifications/rules/2b86fa23-0c15-445c-a2b1-7bd725c46f59",\
1765 "rel": "SELF","name": "linkToSelf"}]}]}'
1767 #Call get_notification_rule_id_by_alarm_name method under test
1768 notification_id
= self
.mon_plugin
.get_notification_rule_id_by_alarm_name(alarm_name
)
1770 #Verify that mocked method is called with required parameters
1771 m_get
.assert_called()
1773 #Verify return value with expected value
1774 self
.assertEqual(notification_id
, '2b86fa23-0c15-445c-a2b1-7bd725c46f59')
1777 @mock.patch
.object(monPlugin
.requests
, 'get')
1778 def test_get_notification_rule_id_by_alarm_name_invalid_req_response(self
,m_get
):
1779 """Test get_notification_rule_id_by_alarm_name: If an invalid response received,\
1783 #Set input parameters to delete_alarm_configuration
1784 alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
1786 #Set mocked function's return values
1787 m_get
.return_value
.status_code
= 404
1789 #Call get_notification_rule_id_by_alarm_name method under test
1790 notification_id
= self
.mon_plugin
.get_notification_rule_id_by_alarm_name(alarm_name
)
1792 #Verify that mocked method is called with required parameters
1793 m_get
.assert_called()
1795 #Verify return value with expected value
1796 self
.assertEqual(notification_id
, None)
1799 @mock.patch
.object(monPlugin
.requests
, 'get')
1800 def test_get_notification_rule_id_by_alarm_name_rule_not_found(self
,m_get
):
1801 """Test get_notification_rule_id_by_alarm_name: If a notification rule is not found,
1805 #Set input parameters to delete_alarm_configuration
1806 alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda'
1808 #Set mocked function's return values
1809 m_get
.return_value
.status_code
= 200
1810 m_get
.return_value
.content
= '{\
1811 "pageInfo": {"totalCount": 0,"page": 0,"pageSize": 1000},\
1813 {"href": "/suite-api/api/notifications/rules?page=0&pageSize=1000",\
1814 "rel": "SELF","name": "current"},\
1815 {"href": "/suite-api/api/notifications/rules?page=0&pageSize=1000",\
1816 "rel": "RELATED","name": "first"},\
1817 {"href": "/suite-api/api/notifications/rules?page=0&pageSize=1000",\
1818 "rel": "RELATED","name": "last"}],\
1819 "notification-rule": [{\
1820 "id": "2b86fa23-0c15-445c-a2b1-7bd725c46f59",\
1821 "name": "notify_CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4",\
1822 "pluginId": "03053f51-f829-438d-993d-cc33a435d76a",\
1823 "links": [{"href": "/suite-api/api/notifications/rules/2b86fa23-0c15-445c-a2b1-7bd725c46f59",\
1824 "rel": "SELF","name": "linkToSelf"}]}]}'
1826 #Call get_notification_rule_id_by_alarm_name method under test
1827 notification_id
= self
.mon_plugin
.get_notification_rule_id_by_alarm_name(alarm_name
)
1829 #Verify that mocked method is called with required parameters
1830 m_get
.assert_called()
1832 #Verify return value with expected value
1833 self
.assertEqual(notification_id
, None)
1836 @mock.patch
.object(monPlugin
.requests
, 'delete')
1837 def test_delete_alarm_defination_valid_req_response(self
,m_delete
):
1838 """Test delete_alarm_defination: A valid request response received,
1842 #Set input parameters to delete_alarm_definition
1843 alarm_definition_id
= 'AlertDefinition-9a6d8a14-9f25-4d81-4d773497444d'
1845 #Set mocked function's return values
1846 m_delete
.return_value
.status_code
= 204
1848 #Call delete_alarm_defination method under test
1849 actual_alarm_id
= self
.mon_plugin
.delete_alarm_defination(alarm_definition_id
)
1851 #Verify that mocked method is called with required parameters
1852 m_delete
.assert_called()
1854 #Verify return value with expected value
1855 self
.assertEqual(actual_alarm_id
, alarm_definition_id
)
1858 @mock.patch
.object(monPlugin
.requests
, 'delete')
1859 def test_delete_alarm_defination_invalid_req_response(self
,m_delete
):
1860 """Test delete_alarm_defination: If an invalid request response received,
1864 #Set input parameters to delete_alarm_definition
1865 alarm_definition_id
= 'AlertDefinition-9a6d8a14-9f25-4d81-4d773497444d'
1867 #Set mocked function's return values
1868 m_delete
.return_value
.status_code
= 404
1870 #Call delete_alarm_defination method under test
1871 actual_alarm_id
= self
.mon_plugin
.delete_alarm_defination(alarm_definition_id
)
1873 #Verify that mocked method is called with required parameters
1874 m_delete
.assert_called()
1876 #Verify return value with expected value
1877 self
.assertEqual(actual_alarm_id
, None)
1880 @mock.patch
.object(monPlugin
.requests
, 'delete')
1881 def test_delete_symptom_definition_valid_req_response(self
,m_delete
):
1882 """Test delete_symptom_definition: A valid request response received,
1886 #Set input parameters to delete_symptom_definition
1887 symptom_definition_id
= 'SymptomDefinition-bcc2cb36-a67b-4deb-9b5884973278'
1889 #Set mocked function's return values
1890 m_delete
.return_value
.status_code
= 204
1892 #Call delete_symptom_definition method under test
1893 actual_symptom_id
= self
.mon_plugin
.delete_symptom_definition(symptom_definition_id
)
1895 #Verify that mocked method is called with required parameters
1896 m_delete
.assert_called()
1898 #Verify return value with expected value
1899 self
.assertEqual(actual_symptom_id
, symptom_definition_id
)
1902 @mock.patch
.object(monPlugin
.requests
, 'delete')
1903 def test_delete_symptom_definition_invalid_req_response(self
,m_delete
):
1904 """Test delete_symptom_definition: If an invalid request response received,
1908 #Set input parameters to delete_symptom_definition
1909 symptom_definition_id
= 'SymptomDefinition-bcc2cb36-a67b-4deb-9b5884973278'
1911 #Set mocked function's return values
1912 m_delete
.return_value
.status_code
= 404
1914 #Call delete_symptom_definition method under test
1915 actual_symptom_id
= self
.mon_plugin
.delete_symptom_definition(symptom_definition_id
)
1917 #Verify that mocked method is called with required parameters
1918 m_delete
.assert_called()
1920 #Verify return value with expected value
1921 self
.assertEqual(actual_symptom_id
, None)
1924 @mock.patch
.object(monPlugin
.requests
, 'post')
1925 @mock.patch
.object(monPlugin
.MonPlugin
, 'check_if_plugin_configured')
1926 def test_configure_rest_plugin_valid_plugin_id(self
, m_check_if_plugin_configured
, m_post
):
1927 """Test configure rest plugin method-valid plugin id"""
1929 # mock return values
1930 expected_return
= m_check_if_plugin_configured
.return_value
= "mock_pluginid"
1932 # call configure rest plugin method under test
1933 actual_return
= self
.mon_plugin
.configure_rest_plugin()
1935 # verify that mocked method is called
1936 m_check_if_plugin_configured
.assert_called()
1937 m_post
.assert_not_called()
1939 # verify return value with expected value
1940 self
.assertEqual(expected_return
, actual_return
)
1943 @mock.patch
.object(monPlugin
.MonPlugin
,'enable_rest_plugin')
1944 @mock.patch
.object(monPlugin
.requests
, 'post')
1945 @mock.patch
.object(monPlugin
.MonPlugin
, 'check_if_plugin_configured')
1946 def est_configure_rest_plugin_invalid_plugin_id(self
, m_check_if_plugin_configured
, m_post
, m_enable_rest_plugin
):
1947 """Test configure rest plugin method-invalid plugin id"""
1949 # mock return values
1950 m_check_if_plugin_configured
.return_value
= None # not configured
1951 m_post
.return_value
.status_code
= 201 #success
1952 m_post
.return_value
.content
= '{"pluginTypeId":"RestPlugin","pluginId":"1ef15663-9739-49fe-8c41-022bcc9f690c",\
1953 "name":"MON_module_REST_Plugin","version":1518693747871,"enabled":false,\
1954 "configValues":[{"name":"Url","value":"https://MON.lxd:8080/notify/"},\
1955 {"name":"Content-type","value":"application/json"},{"name":"Certificate",\
1956 "value":"AA:E7:3E:A5:34:E0:25:FB:28:84:3B:74:B2:18:74:C0:C3:E8:26:50"},\
1957 {"name":"ConnectionCount","value":"20"}]}'
1959 m_enable_rest_plugin
.return_value
= True #success
1960 expected_return
= '1ef15663-9739-49fe-8c41-022bcc9f690c'
1962 # call configure rest plugin method under test
1963 actual_return
= self
.mon_plugin
.configure_rest_plugin()
1965 # verify that mocked method is called
1966 m_check_if_plugin_configured
.assert_called()
1967 m_post
.assert_called()
1968 m_enable_rest_plugin
.assert_called_with('1ef15663-9739-49fe-8c41-022bcc9f690c','MON_module_REST_Plugin')
1970 # verify return value with expected value
1971 self
.assertEqual(expected_return
, actual_return
)
1974 @mock.patch
.object(monPlugin
.MonPlugin
,'enable_rest_plugin')
1975 @mock.patch
.object(monPlugin
.requests
, 'post')
1976 @mock.patch
.object(monPlugin
.MonPlugin
, 'check_if_plugin_configured')
1977 def est_configure_rest_plugin_failed_to_enable_plugin(self
, m_check_if_plugin_configured
, m_post
, m_enable_rest_plugin
):
1978 """Test configure rest plugin method-failed to enable plugin case"""
1980 # mock return values
1981 m_check_if_plugin_configured
.return_value
= None # not configured
1982 m_post
.return_value
.status_code
= 201 #success
1983 m_post
.return_value
.content
= '{"pluginTypeId":"RestPlugin","pluginId":"1ef15663-9739-49fe-8c41-022bcc9f690c",\
1984 "name":"MON_module_REST_Plugin","version":1518693747871,"enabled":false,\
1985 "configValues":[{"name":"Url","value":"https://MON.lxd:8080/notify/"},\
1986 {"name":"Content-type","value":"application/json"},{"name":"Certificate",\
1987 "value":"AA:E7:3E:A5:34:E0:25:FB:28:84:3B:74:B2:18:74:C0:C3:E8:26:50"},\
1988 {"name":"ConnectionCount","value":"20"}]}'
1990 m_enable_rest_plugin
.return_value
= False #return failure
1991 expected_return
= None
1993 # call configure rest plugin method under test
1994 actual_return
= self
.mon_plugin
.configure_rest_plugin()
1996 # verify that mocked method is called
1997 m_check_if_plugin_configured
.assert_called()
1998 m_post
.assert_called()
1999 m_enable_rest_plugin
.assert_called_with('1ef15663-9739-49fe-8c41-022bcc9f690c','MON_module_REST_Plugin')
2001 # verify return value with expected value
2002 self
.assertEqual(expected_return
, actual_return
)
2005 @mock.patch
.object(monPlugin
.requests
, 'get')
2006 def test_check_if_plugin_configured_valid_req_response(self
, m_get
):
2007 """Test check if plugin configured method-valid request response"""
2009 plugin_name
= 'MON_module_REST_Plugin'
2010 # mock return values
2011 m_get
.return_value
.status_code
= 200
2012 expected_return
= '1ef15663-9739-49fe-8c41-022bcc9f690c'
2013 m_get
.return_value
.content
= '{"notificationPluginInstances":\
2014 [{"pluginTypeId":"RestPlugin",\
2015 "pluginId":"1ef15663-9739-49fe-8c41-022bcc9f690c",\
2016 "name":"MON_module_REST_Plugin","version":1518694966987,\
2017 "enabled":true,"configValues":[{"name":"Url",\
2018 "value":"https://MON.lxd:8080/notify/"},\
2019 {"name":"Content-type","value":"application/json"},\
2020 {"name":"Certificate",\
2021 "value":"AA:E7:3E:A5:34:E0:25:FB:28:84:3B:74:B2:18:74:C0"},\
2022 {"name":"ConnectionCount","value":"20"}]}]}'
2024 # call check if plugin configured method under test
2025 actual_return
= self
.mon_plugin
.check_if_plugin_configured(plugin_name
)
2027 # verify that mocked method is called
2028 m_get
.assert_called()
2030 # verify return value with expected value
2031 self
.assertEqual(expected_return
, actual_return
)
2034 @mock.patch
.object(monPlugin
.requests
, 'get')
2035 def test_check_if_plugin_configured_invalid_req_response(self
, m_get
):
2036 """Test check if plugin configured method-invalid request response"""
2038 plugin_name
= 'MON_module_REST_Plugin'
2039 # mock return values
2040 m_get
.return_value
.status_code
= 201
2041 expected_return
= None
2042 m_get
.return_value
.content
= '{"notificationPluginInstances":\
2043 [{"pluginTypeId":"RestPlugin",\
2044 "pluginId":"1ef15663-9739-49fe-8c41-022bcc9f690c",\
2045 "name":"MON_module_REST_Plugin","version":1518694966987,\
2046 "enabled":true,"configValues":[{"name":"Url",\
2047 "value":"https://MON.lxd:8080/notify/"},\
2048 {"name":"Content-type","value":"application/json"},\
2049 {"name":"Certificate",\
2050 "value":"AA:E7:3E:A5:34:E0:25:FB:28:84:3B:74:B2:18:74:C0"},\
2051 {"name":"ConnectionCount","value":"20"}]}]}'
2053 # call check if plugin configured method under test
2054 actual_return
= self
.mon_plugin
.check_if_plugin_configured(plugin_name
)
2056 # verify that mocked method is called
2057 m_get
.assert_called()
2059 # verify return value with expected value
2060 self
.assertEqual(expected_return
, actual_return
)
2063 @mock.patch
.object(monPlugin
.requests
, 'put')
2064 def test_enable_rest_plugin_valid_req_response(self
, m_put
):
2065 """Test enable rest plugin method-valid request response"""
2067 plugin_name
= 'MON_module_REST_Plugin'
2068 plugin_id
= '1ef15663-9739-49fe-8c41-022bcc9f690c'
2069 # mock return values
2070 m_put
.return_value
.status_code
= 204
2071 expected_return
= True
2072 m_put
.return_value
.content
= ''
2074 # call enable rest plugin configured method under test
2075 actual_return
= self
.mon_plugin
.enable_rest_plugin(plugin_id
, plugin_name
)
2077 # verify that mocked method is called
2078 m_put
.assert_called()
2080 # verify return value with expected value
2081 self
.assertEqual(expected_return
, actual_return
)
2084 @mock.patch
.object(monPlugin
.requests
, 'put')
2085 def test_enable_rest_plugin_invalid_req_response(self
, m_put
):
2086 """Test enable rest plugin method-invalid request response"""
2088 plugin_name
= 'MON_module_REST_Plugin'
2089 plugin_id
= '08018c0f-8879-4ca1-9b92-00e22d2ff81b' #invalid plugin id
2090 # mock return values
2091 m_put
.return_value
.status_code
= 404 # api Error code
2092 expected_return
= False
2093 m_put
.return_value
.content
= '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ops:\
2094 error xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \
2095 xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ops=\
2096 "http://webservice.vmware.com/vRealizeOpsMgr/1.0/" \
2097 httpStatusCode="404" apiErrorCode="404"><ops:message>\
2098 No such Notification Plugin - 08018c0f-8879-4ca1-9b92-\
2099 00e22d2ff81b.</ops:message></ops:error>'
2101 # call enable rest plugin configured method under test
2102 actual_return
= self
.mon_plugin
.enable_rest_plugin(plugin_id
, plugin_name
)
2104 # verify that mocked method is called
2105 m_put
.assert_called()
2107 # verify return value with expected value
2108 self
.assertEqual(expected_return
, actual_return
)
2111 @mock.patch
.object(monPlugin
.requests
, 'post')
2112 @mock.patch
.object(monPlugin
.MonPlugin
, 'check_if_plugin_configured')
2113 def test_create_alarm_notification_rule_valid_req(self
, m_check_if_plugin_configured
, m_post
):
2114 """Test create alarm notification rule method valid request response"""
2116 alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
2117 alarm_id
= 'AlertDefinition-f1163767-6eac-438f-8e60-a7a867257e14'
2118 res_id
= 'ac87622f-b761-40a0-b151-00872a2a456e'
2119 expected_return
= "8db86441-71d8-4830-9e1a-a90be3776d12"
2121 # mock return values
2122 m_check_if_plugin_configured
.return_value
= '03053f51-f829-438d-993d-cc33a435d76a'
2123 m_post
.return_value
.status_code
= 201
2124 m_post
.return_value
.content
= '{"id":"8db86441-71d8-4830-9e1a-a90be3776d12",\
2125 "name":"notify_CPU_Utilization_Above_Thr-e14b203c",\
2126 "pluginId":"03053f51-f829-438d-993d-cc33a435d76a",\
2127 "alertControlStates":[],"alertStatuses":[],\
2128 "resourceFilter":{"matchResourceIdOnly":true,\
2129 "childrenResourceKindFilters":[],\
2130 "resourceId":"ac87622f-b761-40a0-b151-00872a2a456e"},\
2131 "alertTypeFilters":[],"alertDefinitionIdFilters":{"values":[\
2132 "AlertDefinition-f1163767-6eac-438f-8e60-a7a867257e14"]}}'
2134 # call enable rest plugin configured method under test
2135 actual_return
= self
.mon_plugin
.create_alarm_notification_rule(alarm_name
, alarm_id
, res_id
)
2137 # verify that mocked method is called
2138 m_check_if_plugin_configured
.assert_called_with('MON_module_REST_Plugin')
2139 m_post
.assert_called()
2141 # verify return value with expected value
2142 self
.assertEqual(expected_return
, actual_return
)
2145 @mock.patch
.object(monPlugin
.requests
, 'post')
2146 @mock.patch
.object(monPlugin
.MonPlugin
, 'check_if_plugin_configured')
2147 def test_create_alarm_notification_rule_invalid_req(self
, m_check_if_plugin_configured
, m_post
):
2148 """Test create alarm notification rule method invalid request response"""
2150 alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
2151 alarm_id
= 'AlertDefinition-f1163767-6eac-438f-8e60-a7a867257e14'
2152 res_id
= 'ac87622f-b761-40a0-b151-00872a2a456e'
2153 expected_return
= None # invalid req should retrun none
2155 # mock return values
2156 m_check_if_plugin_configured
.return_value
= '03053f51-f829-438d-993d-cc33a435d76a'
2157 m_post
.return_value
.status_code
= 500
2158 m_post
.return_value
.content
= '{"message":"Internal Server error, cause unknown.",\
2159 "moreInformation":[{"name":"errorMessage","value":\
2160 "there is already a rule with the same rule name"},\
2161 {"name":"localizedMessage","value":"there is already \
2162 a rule with the same rule name;"}],"httpStatusCode":500,\
2163 "apiErrorCode":500}'
2165 # call enable rest plugin configured method under test
2166 actual_return
= self
.mon_plugin
.create_alarm_notification_rule(alarm_name
, alarm_id
, res_id
)
2168 # verify that mocked method is called
2169 m_check_if_plugin_configured
.assert_called_with('MON_module_REST_Plugin')
2170 m_post
.assert_called()
2172 # verify return value with expected value
2173 self
.assertEqual(expected_return
, actual_return
)
2176 @mock.patch
.object(monPlugin
.requests
, 'post')
2177 @mock.patch
.object(monPlugin
.MonPlugin
, 'check_if_plugin_configured')
2178 def test_create_alarm_notification_rule_failed_to_get_plugin_id(self
, \
2179 m_check_if_plugin_configured
, m_post
):
2180 """Test create alarm notification rule method invalid plugin id"""
2182 alarm_name
= 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
2183 alarm_id
= 'AlertDefinition-f1163767-6eac-438f-8e60-a7a867257e14'
2184 res_id
= 'ac87622f-b761-40a0-b151-00872a2a456e'
2185 expected_return
= None # invalid req should retrun none
2187 # mock return values
2188 m_check_if_plugin_configured
.return_value
= None
2190 # call enable rest plugin configured method under test
2191 actual_return
= self
.mon_plugin
.create_alarm_notification_rule(alarm_name
, alarm_id
, res_id
)
2193 # verify that mocked method is called
2194 m_check_if_plugin_configured
.assert_called_with('MON_module_REST_Plugin')
2195 m_post
.assert_not_called()
2197 # verify return value with expected value
2198 self
.assertEqual(expected_return
, actual_return
)
2201 @mock.patch
.object(monPlugin
.requests
, 'get')
2202 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
2203 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
2204 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
2205 def test_get_metrics_data_valid_rest_req_response(self
, m_get_default_Params
, \
2206 m_get_vm_moref_id
, \
2207 m_get_vm_resource_id
, \
2209 """Test get metrics data of resource method valid request response"""
2211 metrics
= {'collection_period': 1, 'metric_name': 'CPU_UTILIZATION', 'metric_uuid': None, \
2212 'schema_version': 1.0, 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',\
2213 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef', \
2214 'schema_type': 'read_metric_data_request', 'vim_type': 'VMware', \
2215 'collection_unit': 'HR', 'vim_uuid':'1'}
2218 m_get_default_Params
.return_value
= {'metric_key': 'cpu|usage_average', 'unit': '%'}
2219 vm_moref_id
= m_get_vm_moref_id
.return_value
= 'vm-6626'
2220 m_get_vm_resource_id
.return_value
= 'ac87622f-b761-40a0-b151-00872a2a456e'
2221 m_get
.return_value
.status_code
= 200
2222 m_get
.return_value
.content
= '{"values":[{"resourceId":"ac87622f-b761-40a0-b151-\
2223 00872a2a456e","stat-list":{"stat":[{"timestamps":\
2224 [1519716874297,1519717174294,1519717474295,1519717774298,\
2225 1519718074300,1519718374299,1519718674314,1519718974325,\
2226 1519719274304,1519719574298,1519719874298,1519720174301],\
2227 "statKey":{"key":"cpu|usage_average"},"intervalUnit":\
2228 {"quantifier":1},"data":[0.1120000034570694,\
2229 0.11866666376590729,0.11599999666213989,0.11400000005960464,\
2230 0.12066666781902313,0.11533333361148834,0.11800000071525574,\
2231 0.11533333361148834,0.12200000137090683,0.11400000005960464,\
2232 0.1459999978542328,0.12133333086967468]}]}}]}'
2234 # call get matrics data method under test
2235 actual_return
= self
.mon_plugin
.get_metrics_data(metrics
)
2237 # verify that mocked method is called
2238 m_get_default_Params
.assert_called_with(metrics
['metric_name'])
2239 m_get_vm_moref_id
.assert_called_with(metrics
['resource_uuid'])
2240 m_get_vm_resource_id
.assert_called_with(vm_moref_id
)
2241 m_get
.assert_called()
2243 # verify return value with expected value
2244 #self.assertEqual(expected_return, actual_return)
2247 @mock.patch
.object(monPlugin
.requests
, 'get')
2248 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
2249 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
2250 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
2251 def test_get_metrics_data_invalid_rest_req_response(self
, m_get_default_Params
, \
2252 m_get_vm_moref_id
, \
2253 m_get_vm_resource_id
, \
2255 """Test get metrics data of resource method invalid request response"""
2257 metrics
= {'collection_period': 1, 'metric_name': 'CPU_UTILIZATION', 'metric_uuid': None, \
2258 'schema_version': 1.0, 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',\
2259 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef', \
2260 'schema_type': 'read_metric_data_request', 'vim_type': 'VMware', \
2261 'collection_unit': 'HR', 'vim_uuid':'1'}
2264 m_get_default_Params
.return_value
= {'metric_key': 'cpu|usage_average', 'unit': '%'}
2265 vm_moref_id
= m_get_vm_moref_id
.return_value
= 'vm-6626'
2266 m_get_vm_resource_id
.return_value
= 'ac87622f-b761-40a0-b151-00872a2a456e'
2267 m_get
.return_value
.status_code
= 400
2268 expected_return
= {'metric_name': 'CPU_UTILIZATION', 'metric_uuid': '0',
2269 'schema_version': '1.0',
2270 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
2271 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
2272 'metrics_data': {'time_series': [], 'metrics_series': []},
2273 'schema_type': 'read_metric_data_response',
2274 'unit': '%', 'vim_uuid':'1'}
2276 # call get metrics data method under test
2277 actual_return
= self
.mon_plugin
.get_metrics_data(metrics
)
2279 # verify that mocked method is called
2280 m_get_default_Params
.assert_called_with(metrics
['metric_name'])
2281 m_get_vm_moref_id
.assert_called_with(metrics
['resource_uuid'])
2282 m_get_vm_resource_id
.assert_called_with(vm_moref_id
)
2283 m_get
.assert_called()
2285 m_get
.return_value
.content
= '{"message":"Invalid request... #1 violations found.",\
2286 "validationFailures":[{"failureMessage":"Invalid Parameter",\
2287 "violationPath":"end"}],"httpStatusCode":400,\
2288 "apiErrorCode":400}'
2290 # verify return value with expected value
2291 self
.assertEqual(expected_return
, actual_return
)
2294 @mock.patch
.object(monPlugin
.requests
, 'get')
2295 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
2296 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
2297 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
2298 def test_get_metrics_data_metric_not_supported(self
, m_get_default_Params
, \
2299 m_get_vm_moref_id
, \
2300 m_get_vm_resource_id
, \
2302 """Test get metrics data of resource method invalid metric name"""
2304 metrics
= {'collection_period': 1, 'metric_name': 'invalid_metric', 'metric_uuid': None,
2305 'schema_version': 1.0,
2306 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
2307 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
2308 'schema_type': 'read_metric_data_request', 'vim_type': 'VMware',
2309 'collection_unit': 'HR', 'vim_uuid':'1'}
2312 m_get_default_Params
.return_value
= {} # returns empty dict
2314 expected_return
= {'metric_name': 'invalid_metric', 'metric_uuid': '0','vim_uuid': '1',
2315 'schema_version': '1.0','resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
2316 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
2317 'metrics_data': {'time_series': [], 'metrics_series': []},
2318 'schema_type': 'read_metric_data_response','unit': None}
2320 # call get matrics data method under test
2321 actual_return
= self
.mon_plugin
.get_metrics_data(metrics
)
2323 # verify that mocked method is called/not called
2324 m_get_default_Params
.assert_called_with(metrics
['metric_name'])
2325 m_get_vm_moref_id
.assert_not_called()
2326 m_get_vm_resource_id
.assert_not_called()
2327 m_get
.assert_not_called()
2329 # verify return value with expected value
2330 self
.assertEqual(expected_return
, actual_return
)
2333 @mock.patch
.object(monPlugin
.requests
, 'get')
2334 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
2335 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
2336 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
2337 def test_get_metrics_data_failed_to_get_vm_moref_id(self
, m_get_default_Params
, \
2338 m_get_vm_moref_id
, \
2339 m_get_vm_resource_id
, \
2341 """Test get metrics data method negative scenario- invalid resource id"""
2343 metrics
= {'collection_period': 1, 'metric_name': 'cpu_utilization', 'metric_uuid': None, \
2344 'schema_version': 1.0, 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',\
2345 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef', \
2346 'schema_type': 'read_metric_data_request', 'vim_type': 'VMware', \
2347 'collection_unit': 'HR', 'vim_uuid':'1'}
2350 m_get_default_Params
.return_value
= {'metric_key': 'cpu|usage_average', 'unit': '%'}
2351 m_get_vm_moref_id
.return_value
= None
2352 expected_return
= {'metric_name': 'cpu_utilization', 'metric_uuid': '0',
2353 'schema_version': '1.0',
2354 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
2355 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
2356 'metrics_data': {'time_series': [], 'metrics_series': []},
2357 'schema_type': 'read_metric_data_response',
2358 'unit': '%', 'vim_uuid':'1'}
2360 # call get matrics data method under test
2361 actual_return
= self
.mon_plugin
.get_metrics_data(metrics
)
2363 # verify that mocked method is called/not called
2364 m_get_default_Params
.assert_called_with(metrics
['metric_name'])
2365 m_get_vm_moref_id
.assert_called_with(metrics
['resource_uuid'])
2366 m_get_vm_resource_id
.assert_not_called()
2367 m_get
.assert_not_called()
2369 # verify return value with expected value
2370 self
.assertEqual(expected_return
, actual_return
)
2373 @mock.patch
.object(monPlugin
.requests
, 'get')
2374 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
2375 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
2376 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
2377 def test_get_metrics_data_failed_to_get_vm_resource_id(self
, m_get_default_Params
, \
2378 m_get_vm_moref_id
, \
2379 m_get_vm_resource_id
, \
2381 """Test get metrics data method negative scenario- invalid moref id"""
2383 metrics
= {'collection_period': 1, 'metric_name': 'CPU_UTILIZATION', 'metric_uuid': None, \
2384 'schema_version': 1.0, 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',\
2385 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef', \
2386 'schema_type': 'read_metric_data_request', 'vim_type': 'VMware', \
2387 'collection_unit': 'HR', 'vim_uuid':'1'}
2390 m_get_default_Params
.return_value
= {'metric_key': 'cpu|usage_average', 'unit': '%'}
2391 m_get_vm_moref_id
.return_value
= 'Invalid-vm-6626'
2392 m_get_vm_resource_id
.return_value
= None
2393 expected_return
= {'metric_name': 'CPU_UTILIZATION', 'metric_uuid': '0',
2394 'schema_version': '1.0',
2395 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
2396 'correlation_id': 'e14b203c-6bf2-4e2f-a91c-8c19d2abcdef',
2397 'metrics_data': {'time_series': [], 'metrics_series': []},
2398 'schema_type': 'read_metric_data_response',
2399 'unit': '%', 'vim_uuid':'1'}
2401 # call get matrics data method under test
2402 actual_return
= self
.mon_plugin
.get_metrics_data(metrics
)
2404 # verify that mocked method is called/not called
2405 m_get_default_Params
.assert_called_with(metrics
['metric_name'])
2406 m_get_vm_moref_id
.assert_called_with(metrics
['resource_uuid'])
2407 m_get_vm_resource_id
.assert_called()
2408 m_get_vm_resource_id
.assert_called_with('Invalid-vm-6626')
2409 m_get
.assert_not_called()
2411 # verify return value with expected value
2412 self
.assertEqual(expected_return
, actual_return
)
2415 @mock.patch
.object(monPlugin
.MonPlugin
, 'reconfigure_alarm')
2416 @mock.patch
.object(monPlugin
.MonPlugin
, 'update_symptom_defination')
2417 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_details')
2418 def test_update_alarm_configuration_successful_updation(self
, m_get_alarm_defination_details
, \
2419 m_update_symptom_defination
, \
2420 m_reconfigure_alarm
):
2421 """Test update alarm configuration method"""
2423 alarm_config
= {'alarm_uuid': 'f1163767-6eac-438f-8e60-a7a867257e14',
2424 'correlation_id': 14203,
2425 'description': 'CPU_Utilization_Above_Threshold_L', 'operation': 'GT'}
2428 alarm_details_json
= {'states': [{'impact': {'impactType': 'BADGE', 'detail': 'risk'},
2429 'severity': 'CRITICAL', 'base-symptom-set': {'symptomDefinitionIds':
2430 ['SymptomDefinition-47c88675-bea8-436a-bb41-8d2231428f44'],
2431 'relation': 'SELF', 'type': 'SYMPTOM_SET', 'aggregation': 'ALL'}}],
2432 'description': 'CPU_Utilization_Above_Threshold', 'type': 16,
2433 'id': 'AlertDefinition-f1163767-6eac-438f-8e60-a7a867257e14',
2434 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d2'}
2435 alarm_details
= {'symptom_definition_id': 'SymptomDefinition-47c88675-bea8-436a-bb41-\
2436 8d2231428f44', 'alarm_name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-\
2437 a91c-8c19d2', 'alarm_id': 'AlertDefinition-f1163767-6eac-438f-8e60-\
2438 a7a867257e14', 'resource_kind': 'VirtualMachine', 'type': 16}
2439 m_get_alarm_defination_details
.return_value
= (alarm_details_json
, alarm_details
)
2440 m_update_symptom_defination
.return_value
= 'SymptomDefinition-47c88675-bea8-436a-bb41-\
2442 expected_return
= m_reconfigure_alarm
.return_value
= 'f1163767-6eac-438f-8e60-a7a867257e14'
2444 # call update alarm configuration method under test
2445 actual_return
= self
.mon_plugin
.update_alarm_configuration(alarm_config
)
2447 # verify that mocked method is called
2448 m_get_alarm_defination_details
.assert_called_with(alarm_config
['alarm_uuid'])
2449 m_update_symptom_defination
.assert_called_with(alarm_details
['symptom_definition_id'],\
2451 m_reconfigure_alarm
.assert_called_with(alarm_details_json
, alarm_config
)
2453 # verify return value with expected value
2454 self
.assertEqual(expected_return
, actual_return
)
2457 @mock.patch
.object(monPlugin
.MonPlugin
, 'reconfigure_alarm')
2458 @mock.patch
.object(monPlugin
.MonPlugin
, 'update_symptom_defination')
2459 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_details')
2460 def test_update_alarm_configuration_failed_to_reconfigure_alarm(self
, \
2461 m_get_alarm_defination_details
, \
2462 m_update_symptom_defination
, \
2463 m_reconfigure_alarm
):
2464 """Test update alarm configuration method- failed to reconfigure alarm"""
2466 alarm_config
= {'alarm_uuid': 'f1163767-6eac-438f-8e60-a7a867257e14',
2467 'correlation_id': 14203,
2468 'description': 'CPU_Utilization_Above_Threshold_L', 'operation': 'GT'}
2471 alarm_details_json
= {'states': [{'impact': {'impactType': 'BADGE', 'detail': 'risk'},
2472 'severity': 'CRITICAL', 'base-symptom-set': {'symptomDefinitionIds':
2473 ['SymptomDefinition-47c88675-bea8-436a-bb41-8d2231428f44'],
2474 'relation': 'SELF', 'type': 'SYMPTOM_SET', 'aggregation': 'ALL'}}],
2475 'description': 'CPU_Utilization_Above_Threshold', 'type': 16,
2476 'id': 'AlertDefinition-f1163767-6eac-438f-8e60-a7a867257e14',
2477 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d2'}
2478 alarm_details
= {'symptom_definition_id': 'SymptomDefinition-47c88675-bea8-436a-bb41-\
2479 8d2231428f44', 'alarm_name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-\
2480 a91c-8c19d2', 'alarm_id': 'AlertDefinition-f1163767-6eac-438f-8e60-\
2481 a7a867257e14', 'resource_kind': 'VirtualMachine', 'type': 16}
2482 m_get_alarm_defination_details
.return_value
= (alarm_details_json
, alarm_details
)
2483 m_update_symptom_defination
.return_value
= 'SymptomDefinition-47c88675-bea8-436a-bb41-\
2485 expected_return
= m_reconfigure_alarm
.return_value
= None # failed to reconfigure
2487 # call update alarm configuration method under test
2488 actual_return
= self
.mon_plugin
.update_alarm_configuration(alarm_config
)
2490 # verify that mocked method is called
2491 m_get_alarm_defination_details
.assert_called_with(alarm_config
['alarm_uuid'])
2492 m_update_symptom_defination
.assert_called_with(alarm_details
['symptom_definition_id'],\
2494 m_reconfigure_alarm
.assert_called_with(alarm_details_json
, alarm_config
)
2496 # verify return value with expected value
2497 self
.assertEqual(expected_return
, actual_return
)
2500 @mock.patch
.object(monPlugin
.MonPlugin
, 'reconfigure_alarm')
2501 @mock.patch
.object(monPlugin
.MonPlugin
, 'update_symptom_defination')
2502 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_alarm_defination_details')
2503 def test_update_alarm_configuration_failed_to_update_symptom(self
, \
2504 m_get_alarm_defination_details
, \
2505 m_update_symptom_defination
, \
2506 m_reconfigure_alarm
):
2507 """Test update alarm configuration method- failed to update alarm"""
2509 alarm_config
= {'alarm_uuid': 'f1163767-6eac-438f-8e60-a7a867257e14',
2510 'correlation_id': 14203,
2511 'description': 'CPU_Utilization_Above_Threshold_L', 'operation': 'GT'}
2514 alarm_details_json
= {'states': [{'impact': {'impactType': 'BADGE', 'detail': 'risk'},
2515 'severity': 'CRITICAL', 'base-symptom-set': {'symptomDefinitionIds':
2516 ['SymptomDefinition-47c88675-bea8-436a-bb41-8d2231428f44'],
2517 'relation': 'SELF', 'type': 'SYMPTOM_SET', 'aggregation': 'ALL'}}],
2518 'description': 'CPU_Utilization_Above_Threshold', 'type': 16,
2519 'id': 'AlertDefinition-f1163767-6eac-438f-8e60-a7a867257e14',
2520 'name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d2'}
2521 alarm_details
= {'symptom_definition_id': 'Invalid-47c88675-bea8-436a-bb41-\
2522 8d2231428f44', 'alarm_name': 'CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-\
2523 a91c-8c19d2', 'alarm_id': 'AlertDefinition-f1163767-6eac-438f-8e60-\
2524 a7a867257e14', 'resource_kind': 'VirtualMachine', 'type': 16}
2525 m_get_alarm_defination_details
.return_value
= (alarm_details_json
, alarm_details
)
2526 expected_return
= m_update_symptom_defination
.return_value
= None
2528 # call update alarm configuration method under test
2529 actual_return
= self
.mon_plugin
.update_alarm_configuration(alarm_config
)
2531 # verify that mocked method is called
2532 m_get_alarm_defination_details
.assert_called_with(alarm_config
['alarm_uuid'])
2533 m_update_symptom_defination
.assert_called_with(alarm_details
['symptom_definition_id'],\
2535 m_reconfigure_alarm
.assert_not_called()
2537 # verify return value with expected value
2538 self
.assertEqual(expected_return
, actual_return
)
2541 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
2542 def test_verify_metric_support_metric_supported_with_unit(self
,m_get_default_Params
):
2543 """Test verify metric support method for supported metric"""
2546 metric_info
= {'metric_unit': '%', 'metric_name': 'cpu_utilization',
2547 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4'}
2548 m_get_default_Params
.return_value
= {'metric_key': 'cpu|usage_average', 'unit': '%'}
2549 expected_return
= True #supported metric returns True
2551 # call verify metric support method under test
2552 actual_return
= self
.mon_plugin
.verify_metric_support(metric_info
)
2554 # verify that mocked method is called
2555 m_get_default_Params
.assert_called_with(metric_info
['metric_name'])
2556 #m_get_default_Params.assert_called_with(metric_info)
2558 # verify return value with expected value
2559 self
.assertEqual(expected_return
, actual_return
)
2562 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
2563 def test_verify_metric_support_metric_not_supported(self
,m_get_default_Params
):
2564 """Test verify metric support method for un-supported metric"""
2567 metric_info
= {'metric_unit': '%', 'metric_name': 'invalid_metric',
2568 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4'}
2569 m_get_default_Params
.return_value
= {}
2570 expected_return
= False #supported metric returns True
2572 # call verify metric support method under test
2573 actual_return
= self
.mon_plugin
.verify_metric_support(metric_info
)
2575 # verify that mocked method is called
2576 m_get_default_Params
.assert_called_with(metric_info
['metric_name'])
2578 # verify return value with expected value
2579 self
.assertEqual(expected_return
, actual_return
)
2582 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_default_Params')
2583 def test_verify_metric_support_metric_supported_with_mismatched_unit(self
, \
2584 m_get_default_Params
):
2585 """Test verify metric support method for supported metric with mismatched unit"""
2588 metric_info
= {'metric_unit': '', 'metric_name': 'invalid_metric',
2589 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4'}
2590 m_get_default_Params
.return_value
= {'metric_key': 'cpu|usage_average', 'unit': '%'}
2591 expected_return
= True #supported metric returns True
2593 # call verify metric support method under test
2594 actual_return
= self
.mon_plugin
.verify_metric_support(metric_info
)
2596 # verify that mocked method is called
2597 m_get_default_Params
.assert_called_with(metric_info
['metric_name'])
2599 # verify return value with expected value
2600 self
.assertEqual(expected_return
, actual_return
)
2603 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_triggered_alarms_on_resource')
2604 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vrops_resourceid_from_ro_uuid')
2605 def test_get_triggered_alarms_list_returns_triggered_alarms(self
, \
2606 m_get_vrops_resourceid
, \
2607 m_triggered_alarms
):
2608 """Test get triggered alarm list method valid input"""
2610 # Mock list alarm input
2611 list_alarm_input
= {'severity': 'CRITICAL',
2612 'correlation_id': 'e14b203c',
2613 'alarm_name': 'CPU_Utilization_Above_Threshold',
2614 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4'}
2616 resource_id
= m_get_vrops_resourceid
.return_value
= 'ac87622f-b761-40a0-b151-00872a2a456e'
2617 expected_return
= m_triggered_alarms
.return_value
= [{'status': 'ACTIVE',
2618 'update_date': '2018-01-12T08:34:05',
2619 'severity': 'CRITICAL', 'resource_uuid': 'e14b203c',
2620 'cancel_date': '0000-00-00T00:00:00',
2621 'alarm_instance_uuid': 'd9e3bc84',
2622 'alarm_uuid': '5714977d', 'vim_type': 'VMware',
2623 'start_date': '2018-01-12T08:34:05'},
2624 {'status': 'CANCELED','update_date':'2017-12-20T09:37:57',
2625 'severity': 'CRITICAL', 'resource_uuid': 'e14b203c',
2626 'cancel_date': '2018-01-12T06:49:19',
2627 'alarm_instance_uuid': 'd3bbeef6',
2628 'alarm_uuid': '7ba1bf3e', 'vim_type': 'VMware',
2629 'start_date': '2017-12-20T09:37:57'}]
2631 # call get triggered alarms list method under test
2632 actual_return
= self
.mon_plugin
.get_triggered_alarms_list(list_alarm_input
)
2634 # verify that mocked method is called
2635 m_get_vrops_resourceid
.assert_called_with(list_alarm_input
['resource_uuid'])
2636 m_triggered_alarms
.assert_called_with(list_alarm_input
['resource_uuid'] , resource_id
)
2638 # verify return value with expected value
2639 self
.assertEqual(expected_return
, actual_return
)
2642 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_triggered_alarms_on_resource')
2643 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vrops_resourceid_from_ro_uuid')
2644 def test_get_triggered_alarms_list_invalid_resource_uuid(self
, \
2645 m_get_vrops_resourceid
, \
2646 m_triggered_alarms
):
2647 """Test get triggered alarm list method invalid resource uuid"""
2649 # Mock list alarm input
2650 list_alarm_input
= {'severity': 'CRITICAL',
2651 'correlation_id': 'e14b203c',
2652 'alarm_name': 'CPU_Utilization_Above_Threshold',
2653 'resource_uuid': '12345'} #invalid resource uuid
2655 expected_return
= m_get_vrops_resourceid
.return_value
= None #returns empty list
2657 # call get triggered alarms list method under test
2658 actual_return
= self
.mon_plugin
.get_triggered_alarms_list(list_alarm_input
)
2660 # verify that mocked method is called
2661 m_get_vrops_resourceid
.assert_called_with(list_alarm_input
['resource_uuid'])
2662 m_triggered_alarms
.assert_not_called()
2664 # verify return value with expected value
2665 self
.assertEqual([], actual_return
)
2668 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_triggered_alarms_on_resource')
2669 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vrops_resourceid_from_ro_uuid')
2670 def test_get_triggered_alarms_list_resource_uuid_not_present(self
, \
2671 m_get_vrops_resourceid
, \
2672 m_triggered_alarms
):
2673 """Test get triggered alarm list method resource not present"""
2675 # Mock list alarm input
2676 list_alarm_input
= {'severity': 'CRITICAL',
2677 'correlation_id': 'e14b203c',
2678 'alarm_name': 'CPU_Utilization_Above_Threshold'}
2680 # call get triggered alarms list method under test
2681 actual_return
= self
.mon_plugin
.get_triggered_alarms_list(list_alarm_input
)
2683 # verify that mocked method is called
2684 m_get_vrops_resourceid
.assert_not_called()
2685 m_triggered_alarms
.assert_not_called()
2687 # verify return value with expected value
2688 self
.assertEqual([], actual_return
)
2691 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
2692 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
2693 def test_get_vrops_resourceid_from_ro_uuid(self
, m_get_vm_moref_id
, m_get_vm_resource_id
):
2694 """Test get vrops resourceid from ro uuid method"""
2697 ro_resource_uuid
= 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
2698 vm_moref_id
= m_get_vm_moref_id
.return_value
= 'vm-6626'
2699 expected_return
= m_get_vm_resource_id
.return_value
='ac87622f-b761-40a0-b151-00872a2a456e'
2701 # call get_vrops_resourceid_from_ro_uuid method under test
2702 actual_return
= self
.mon_plugin
.get_vrops_resourceid_from_ro_uuid(ro_resource_uuid
)
2704 # verify that mocked method is called
2705 m_get_vm_moref_id
.assert_called_with(ro_resource_uuid
)
2706 m_get_vm_resource_id
.assert_called_with(vm_moref_id
)
2708 # verify return value with expected value
2709 self
.assertEqual(expected_return
, actual_return
)
2712 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
2713 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
2714 def test_get_vrops_resourceid_from_ro_uuid_failed_to_get_vm_resource_id(self
, \
2715 m_get_vm_moref_id
, \
2716 m_get_vm_resource_id
):
2717 """Test get vrops resourceid from ro uuid method negative scenario"""
2720 ro_resource_uuid
= 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
2721 vm_moref_id
= m_get_vm_moref_id
.return_value
= 'vm-6626'
2722 expected_return
= m_get_vm_resource_id
.return_value
= None
2724 # call get_vrops_resourceid_from_ro_uuid method under test
2725 actual_return
= self
.mon_plugin
.get_vrops_resourceid_from_ro_uuid(ro_resource_uuid
)
2727 # verify that mocked method is called
2728 m_get_vm_moref_id
.assert_called_with(ro_resource_uuid
)
2729 m_get_vm_resource_id
.assert_called_with(vm_moref_id
)
2731 # verify return value with expected value
2732 self
.assertEqual(expected_return
, actual_return
)
2735 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_resource_id')
2736 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vm_moref_id')
2737 def test_get_vrops_resourceid_from_ro_uuid_failed_to_get_vm_moref_id(self
, \
2738 m_get_vm_moref_id
, \
2739 m_get_vm_resource_id
):
2740 """Test get vrops resourceid from ro uuid method negative scenario"""
2743 ro_resource_uuid
= 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
2744 expected_return
= vm_moref_id
= m_get_vm_moref_id
.return_value
= None
2746 # call get_vrops_resourceid_from_ro_uuid method under test
2747 actual_return
= self
.mon_plugin
.get_vrops_resourceid_from_ro_uuid(ro_resource_uuid
)
2749 # verify that mocked method is called
2750 m_get_vm_moref_id
.assert_called_with(ro_resource_uuid
)
2751 m_get_vm_resource_id
.assert_not_called()
2753 # verify return value with expected value
2754 self
.assertEqual(expected_return
, actual_return
)
2757 @mock.patch
.object(monPlugin
.requests
, 'get')
2758 def test_get_triggered_alarms_on_resource_valid_req_response(self
, m_get
):
2759 """Test get triggered alarms on resource method for valid request"""
2762 ro_resource_uuid
= 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
2763 vrops_resource_id
= 'ac87622f-b761-40a0-b151-00872a2a456e'
2764 m_get
.return_value
.status_code
= 200
2765 expected_return
= [{'status': 'ACTIVE', 'update_date': '2018-01-12T08:34:05',
2766 'severity': 'CRITICAL', 'start_date': '2018-01-12T08:34:05',
2767 'resource_uuid': 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4',
2768 'cancel_date': '2018-02-12T08:24:48', 'vim_type': 'VMware',
2769 'alarm_instance_uuid': 'd9e3bc84-dcb4-4905-b592-00a55f4cdaf1',
2770 'alarm_uuid': '5714977d-56f6-4222-adc7-43fa6c6e7e39'}]
2772 m_get
.return_value
.content
= '{"alerts": [\
2774 "alertId": "d9e3bc84-dcb4-4905-b592-00a55f4cdaf1",\
2775 "resourceId": "ac87622f-b761-40a0-b151-00872a2a456e",\
2776 "alertLevel": "CRITICAL",\
2777 "status": "ACTIVE",\
2778 "startTimeUTC": 1515746045278,\
2779 "cancelTimeUTC": 1518423888708,\
2780 "updateTimeUTC": 1515746045278,\
2781 "alertDefinitionId": "AlertDefinition-5714977d-56f6-4222-adc7-43fa6c6e7e39",\
2782 "alertDefinitionName": "CPU_Utilization_Above_Thr-e14b203c-6bf2-4e2f-a91c-8c19d240eda4"\
2785 "alertId": "5fb5e940-e161-4253-a729-7255c6d6b1f5",\
2786 "resourceId": "ac87622f-b761-40a0-b151-00872a2a456e",\
2787 "alertLevel": "WARNING",\
2788 "status": "CANCELED",\
2789 "startTimeUTC": 1506684979154,\
2790 "cancelTimeUTC": 0,\
2791 "updateTimeUTC": 1520471975507,\
2792 "alertDefinitionId": "AlertDefinition-9ec5a921-1a54-411d-85ec-4c1c9b26dd02",\
2793 "alertDefinitionName": "VM_CPU_Usage_Alarm"\
2796 # call get_vrops_resourceid_from_ro_uuid method under test
2797 actual_return
= self
.mon_plugin
.get_triggered_alarms_on_resource(ro_resource_uuid
, \
2800 # verify that mocked method is called
2801 m_get
.assert_called()
2803 # verify return value with expected value
2804 self
.assertEqual(expected_return
, actual_return
)
2807 @mock.patch
.object(monPlugin
.requests
, 'get')
2808 def test_get_triggered_alarms_on_resource_invalid_req_response(self
, m_get
):
2809 """Test get triggered alarms on resource method for invalid request"""
2812 ro_resource_uuid
= 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
2813 vrops_resource_id
= 'ac87622f-b761-40a0-b151-00872a2a456e'
2814 m_get
.return_value
.status_code
= 204
2815 expected_return
= None
2817 # call get_vrops_resourceid_from_ro_uuid method under test
2818 actual_return
= self
.mon_plugin
.get_triggered_alarms_on_resource(ro_resource_uuid
, \
2821 # verify that mocked method is called
2822 m_get
.assert_called()
2824 # verify return value with expected value
2825 self
.assertEqual(expected_return
, actual_return
)
2828 @mock.patch
.object(monPlugin
.requests
, 'get')
2829 def test_get_triggered_alarms_on_resource_no_alarms_present(self
, m_get
):
2830 """Test get triggered alarms on resource method for no alarms present"""
2833 ro_resource_uuid
= 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
2834 vrops_resource_id
= 'ac87622f-b761-40a0-b151-00872a2a456e'
2835 m_get
.return_value
.status_code
= 200
2836 expected_return
= []
2837 m_get
.return_value
.content
= '{"alerts": []}'
2839 # call get_vrops_resourceid_from_ro_uuid method under test
2840 actual_return
= self
.mon_plugin
.get_triggered_alarms_on_resource(ro_resource_uuid
, \
2843 # verify that mocked method is called
2844 m_get
.assert_called()
2846 # verify return value with expected value
2847 self
.assertEqual(expected_return
, actual_return
)
2850 def test_convert_date_time_valid_date_time(self
):
2851 """Test convert date time method valid input"""
2854 date_time
= 1515746045278
2855 expected_return
= '2018-01-12T08:34:05'
2857 # call convert_date_time method under test
2858 actual_return
= self
.mon_plugin
.convert_date_time(date_time
)
2860 # verify return value with expected value
2861 self
.assertEqual(expected_return
, actual_return
)
2863 def test_convert_date_time_invalid_date_time(self
):
2864 """Test convert date time method invalid input"""
2868 expected_return
= '0000-00-00T00:00:00'
2870 # call convert_date_time method under test
2871 actual_return
= self
.mon_plugin
.convert_date_time(date_time
)
2873 # verify return value with expected value
2874 self
.assertEqual(expected_return
, actual_return
)
2877 @mock.patch
.object(monPlugin
.requests
, 'get')
2878 def test_get_vm_resource_id_rest_valid_req_response(self
, m_get
):
2879 """Test get vms resource id valid request"""
2882 vm_moref_id
= 'vm-6626'
2883 m_get
.return_value
.status_code
= 200
2884 expected_return
= "ac87622f-b761-40a0-b151-00872a2a456e"
2885 m_get
.return_value
.content
= \
2889 "creationTime": 1497770174130,\
2891 "name": "OCInst2.ubuntu(4337d51f-1e65-4ab0-9c08-4897778d4fda)",\
2892 "adapterKindKey": "VMWARE",\
2893 "resourceKindKey": "VirtualMachine",\
2894 "resourceIdentifiers": [\
2896 "identifierType": {\
2897 "name": "VMEntityObjectID",\
2898 "dataType": "STRING",\
2899 "isPartOfUniqueness": true\
2905 "identifier": "ac87622f-b761-40a0-b151-00872a2a456e"\
2910 # call get_vm_resource_id method under test
2911 actual_return
= self
.mon_plugin
.get_vm_resource_id(vm_moref_id
)
2913 # verify that mocked method is called
2914 m_get
.assert_called()
2916 # verify return value with expected value
2917 self
.assertEqual(expected_return
, actual_return
)
2920 @mock.patch
.object(monPlugin
.requests
, 'get')
2921 def test_get_vm_resource_id_rest_invalid_req_response(self
, m_get
):
2922 """Test get vms resource id invalid request"""
2925 vm_moref_id
= 'vm-6626'
2926 m_get
.return_value
.status_code
= 406
2927 expected_return
= None
2928 m_get
.return_value
.content
= '406 Not Acceptable'
2930 # call get_vm_resource_id method under test
2931 actual_return
= self
.mon_plugin
.get_vm_resource_id(vm_moref_id
)
2933 # verify that mocked method is called
2934 m_get
.assert_called()
2936 # verify return value with expected value
2937 self
.assertEqual(expected_return
, actual_return
)
2940 @mock.patch
.object(monPlugin
.requests
, 'get')
2941 def test_get_vm_resource_id_rest_invalid_response(self
, m_get
):
2942 """Test get vms resource id invalid response"""
2945 vm_moref_id
= 'vm-6626'
2946 m_get
.return_value
.status_code
= 200
2947 expected_return
= None
2948 m_get
.return_value
.content
= \
2952 "creationTime": 1497770174130,\
2954 "name": "OCInst2.ubuntu(4337d51f-1e65-4ab0-9c08-4897778d4fda)",\
2955 "adapterKindKey": "VMWARE",\
2956 "resourceKindKey": "VirtualMachine",\
2957 "resourceIdentifiers": [\
2959 "identifierType": {\
2960 "name": "VMEntityObjectID",\
2961 "dataType": "STRING",\
2962 "isPartOfUniqueness": true\
2968 "identifier": "ac87622f-b761-40a0-b151-00872a2a456e"\
2972 # call get_vm_resource_id method under test
2973 actual_return
= self
.mon_plugin
.get_vm_resource_id(vm_moref_id
)
2975 # verify that mocked method is called
2976 #m_get.assert_called
2978 # verify return value with expected value
2979 self
.assertEqual(expected_return
, actual_return
)
2982 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vapp_details_rest')
2983 def test_get_vm_moref_id_valid_id_found (self
, m_get_vapp_details_rest
):
2984 """Test get vm moref id valid scenario"""
2987 vapp_uuid
= 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
2988 m_get_vapp_details_rest
.return_value
= {'vm_vcenter_info': {'vm_moref_id': 'vm-6626'}}
2989 expected_return
= 'vm-6626'
2991 # call get_vm_resource_id method under test
2992 actual_return
= self
.mon_plugin
.get_vm_moref_id(vapp_uuid
)
2994 # verify that mocked method is called
2995 m_get_vapp_details_rest
.assert_called_with(vapp_uuid
)
2997 # verify return value with expected value
2998 self
.assertEqual(expected_return
, actual_return
)
3001 @mock.patch
.object(monPlugin
.MonPlugin
, 'get_vapp_details_rest')
3002 def test_get_vm_moref_id_valid_id_not_found(self
, m_get_vapp_details_rest
):
3003 """Test get vm moref id invalid scenario"""
3006 vapp_uuid
= 'e14b203c-6bf2-4e2f-a91c-8c19d240eda'#invalid uuid
3007 m_get_vapp_details_rest
.return_value
= {}
3008 expected_return
= None
3010 # call get_vm_resource_id method under test
3011 actual_return
= self
.mon_plugin
.get_vm_moref_id(vapp_uuid
)
3013 # verify that mocked method is called
3014 m_get_vapp_details_rest
.assert_called_with(vapp_uuid
)
3016 # verify return value with expected value
3017 self
.assertEqual(expected_return
, actual_return
)
3020 @mock.patch
.object(monPlugin
.requests
, 'get')
3021 @mock.patch
.object(monPlugin
.MonPlugin
, 'connect_as_admin')
3022 def test_get_vapp_details_rest_valid_req_response(self
, m_connect_as_admin
, m_get
):
3023 """Test get vapp details rest method for valid request response"""
3026 vapp_uuid
= 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
3027 m_connect_as_admin
.return_value
= self
.vca
3028 self
.vca
._session
= self
.session
3029 self
.vca
._session
.headers
['x-vcloud-authorization'] = '2ec69b2cc6264ad0a47aaf4e3e280d16'
3030 m_get
.return_value
.status_code
= 200
3031 expected_return
= {'vm_vcenter_info': {'vm_moref_id': 'vm-6626'}}
3032 m_get
.return_value
.content
= '<?xml version="1.0" encoding="UTF-8"?>\
3033 <VApp xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:vmext="http://www.vmware.com/vcloud/extension/v1.5" >\
3035 <Vm needsCustomization="false" type="application/vnd.vmware.vcloud.vm+xml">\
3036 <VCloudExtension required="false">\
3038 <vmext:VmVimObjectRef>\
3039 <vmext:VimServerRef type="application/vnd.vmware.admin.vmwvirtualcenter+xml"/>\
3040 <vmext:MoRef>vm-6626</vmext:MoRef>\
3041 <vmext:VimObjectType>VIRTUAL_MACHINE</vmext:VimObjectType>\
3042 </vmext:VmVimObjectRef>\
3049 # call get_vapp_details_rest method under test
3050 actual_return
= self
.mon_plugin
.get_vapp_details_rest(vapp_uuid
)
3052 # verify that mocked method is called
3053 m_connect_as_admin
.assert_called_with()
3054 m_get
.assert_called()
3056 # verify return value with expected value
3057 self
.assertEqual(expected_return
, actual_return
)
3060 @mock.patch
.object(monPlugin
.requests
, 'get')
3061 @mock.patch
.object(monPlugin
.MonPlugin
, 'connect_as_admin')
3062 def test_get_vapp_details_rest_invalid_req_response(self
, m_connect_as_admin
, m_get
):
3063 """Test get vapp details rest method for invalid request response"""
3066 vapp_uuid
= 'Invalid-e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
3067 m_connect_as_admin
.return_value
= self
.vca
3068 self
.vca
._session
= self
.session
3069 self
.vca
._session
.headers
['x-vcloud-authorization'] = '2ec69b2cc6264ad0a47aaf4e3e280d16'
3070 m_get
.return_value
.status_code
= 400
3071 expected_return
= {}
3072 m_get
.return_value
.content
= 'Bad Request'
3074 # call get_vapp_details_rest method under test
3075 actual_return
= self
.mon_plugin
.get_vapp_details_rest(vapp_uuid
)
3077 # verify that mocked method is called
3078 m_connect_as_admin
.assert_called_with()
3080 # verify return value with expected value
3081 self
.assertEqual(expected_return
, actual_return
)
3084 @mock.patch
.object(monPlugin
.requests
, 'get')
3085 @mock.patch
.object(monPlugin
.MonPlugin
, 'connect_as_admin')
3086 def test_get_vapp_details_rest_failed_to_connect_vcd(self
, m_connect_as_admin
, m_get
):
3087 """Test get vapp details rest method for failed to connect to vcd"""
3090 vapp_uuid
= 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
3091 m_connect_as_admin
.return_value
= None
3092 expected_return
= {}
3094 # call get_vapp_details_rest method under test
3095 actual_return
= self
.mon_plugin
.get_vapp_details_rest(vapp_uuid
)
3097 # verify that mocked method is called
3098 m_connect_as_admin
.assert_called_with()
3099 m_get
.assert_not_called()
3101 # verify return value with expected value
3102 self
.assertEqual(expected_return
, actual_return
)
3105 @mock.patch
.object(monPlugin
.requests
, 'get')
3106 @mock.patch
.object(monPlugin
.MonPlugin
, 'connect_as_admin')
3107 def test_get_vapp_details_rest_invalid_response(self
, m_connect_as_admin
, m_get
):
3108 """Test get vapp details rest method for invalid response"""
3111 vapp_uuid
= 'e14b203c-6bf2-4e2f-a91c-8c19d240eda4'
3112 m_connect_as_admin
.return_value
= self
.vca
3113 self
.vca
._session
= self
.session
3114 self
.vca
._session
.headers
['x-vcloud-authorization'] = '2ec69b2cc6264ad0a47aaf4e3e280d16'
3115 m_get
.return_value
.status_code
= 200
3116 expected_return
= {}
3117 m_get
.return_value
.content
= '<?xml version="1.0" encoding="UTF-8"?>\
3118 <VApp xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:vmext="http://www.vmware.com/vcloud/extension/v1.5" >\
3120 <Vm needsCustomization="false" type="application/vnd.vmware.vcloud.vm+xml">\
3121 <VCloudExtension required="false">\
3123 <vmext:VmVimObjectRef>\
3124 <vmext:VimServerRef type="application/vnd.vmware.admin.vmwvirtualcenter+xml"/>\
3125 <vmext:MoRef>vm-6626</vmext:MoRef>\
3126 <vmext:VimObjectType>VIRTUAL_MACHINE</vmext:VimObjectType>\
3133 # call get_vapp_details_rest method under test
3134 actual_return
= self
.mon_plugin
.get_vapp_details_rest(vapp_uuid
)
3136 # verify that mocked method is called
3137 m_connect_as_admin
.assert_called_with()
3138 m_get
.assert_called()
3140 # verify return value with expected value
3141 self
.assertEqual(expected_return
, actual_return
)
3144 @mock.patch
.object(monPlugin
.Client
, 'set_credentials')
3145 @mock.patch
.object(monPlugin
, 'Client')
3146 def test_connect_as_admin(self
, m_client
, m_set_credentials
):
3147 """Test connect as admin to vCD method"""
3149 #mock the inputs and mocked returns
3150 expected_return
= m_client
.return_value
= self
.vca
3151 m_set_credentials
.retrun_value
= True
3153 # call connect_as_admin method under test
3154 actual_return
= self
.mon_plugin
.connect_as_admin()
3156 # verify that mocked method is called
3157 m_client
.assert_called_with(self
.m_vim_access_config
['vim_url'],
3158 verify_ssl_certs
=False)
3160 # verify return value with expected value
3161 self
.assertEqual(expected_return
, actual_return
)
3164 # For testing purpose
3165 #if __name__ == '__main__':